26 |
|
line = in.readLine(); |
27 |
|
// it seems some versions of top prefix this line with something else... lets remove it :) |
28 |
|
line = line.substring(line.indexOf("load averages:")); |
29 |
< |
System.out.println("line1: "+line); |
29 |
> |
// System.out.println("line1: "+line); |
30 |
|
StringTokenizer tok = new StringTokenizer(line,":",false); |
31 |
|
tok.nextToken(); // load averages |
32 |
|
tok.nextToken(" ,"); // : |
33 |
|
String load1 = tok.nextToken(); // "0.30" |
34 |
< |
System.out.println("load1: "+load1); |
34 |
> |
// System.out.println("load1: "+load1); |
35 |
|
String load5 = tok.nextToken(); // "0.27" |
36 |
< |
System.out.println("load5: "+load5); |
36 |
> |
// System.out.println("load5: "+load5); |
37 |
|
String load15 = tok.nextToken(); // "0.29" |
38 |
< |
System.out.println("load15: "+load15); |
38 |
> |
// System.out.println("load15: "+load15); |
39 |
|
String sTime = tok.nextToken(); // "16:58:10" |
40 |
< |
System.out.println("sTime: "+sTime); |
40 |
> |
// System.out.println("sTime: "+sTime); |
41 |
|
|
42 |
|
// get the next line |
43 |
|
line = in.readLine(); // 632 processes: 591 sleeping, 10 zombie, 30 stopped, 1 on cpu |
44 |
< |
System.out.println("line2: "+line); |
44 |
> |
// System.out.println("line2: "+line); |
45 |
|
tok = new StringTokenizer(line," ",false); |
46 |
|
String totalProcesses = tok.nextToken(); // "632" |
47 |
< |
System.out.println("totalProcesses: "+totalProcesses); |
47 |
> |
// System.out.println("totalProcesses: "+totalProcesses); |
48 |
|
tok.nextToken(); // processes |
49 |
|
String sleeping = tok.nextToken(": ,"); // "591" |
50 |
< |
System.out.println("sleeping: "+sleeping); |
50 |
> |
// System.out.println("sleeping: "+sleeping); |
51 |
|
tok.nextToken(); // sleeping |
52 |
|
String zombie = tok.nextToken(); // "10" |
53 |
< |
System.out.println("zombie: "+zombie); |
53 |
> |
// System.out.println("zombie: "+zombie); |
54 |
|
tok.nextToken(); // zombie |
55 |
|
String stopped = tok.nextToken(); // "30" |
56 |
< |
System.out.println("stopped: "+stopped); |
56 |
> |
// System.out.println("stopped: "+stopped); |
57 |
|
tok.nextToken(); // stopped |
58 |
|
String onCPU = tok.nextToken(); // "1" |
59 |
< |
System.out.println("onCPU: "+onCPU); |
59 |
> |
// System.out.println("onCPU: "+onCPU); |
60 |
|
|
61 |
|
// get the next line |
62 |
|
line = in.readLine(); // CPU states: 71.1% idle, 1.8% user, 4.8% kernel, 22.2% iowait, 0.0% swap |
63 |
< |
System.out.println("line3: "+line); |
63 |
> |
// System.out.println("line3: "+line); |
64 |
|
tok = new StringTokenizer(line,":%,",false); |
65 |
|
tok.nextToken(); // CPU states |
66 |
|
String idle = tok.nextToken(); // "71.1" |
67 |
< |
System.out.println("idle: "+idle); |
67 |
> |
// System.out.println("idle: "+idle); |
68 |
|
tok.nextToken(); // idle |
69 |
|
String user = tok.nextToken(",%"); // " 1.8" |
70 |
< |
System.out.println("user: "+user); |
70 |
> |
// System.out.println("user: "+user); |
71 |
|
tok.nextToken(); // user |
72 |
|
String kernel = tok.nextToken(); // " 4.8" |
73 |
< |
System.out.println("kernel: "+kernel); |
73 |
> |
// System.out.println("kernel: "+kernel); |
74 |
|
tok.nextToken(); // kernel |
75 |
|
String iowait = tok.nextToken(); // " 22.2" |
76 |
< |
System.out.println("iowait: "+iowait); |
76 |
> |
// System.out.println("iowait: "+iowait); |
77 |
|
tok.nextToken(); // iowait |
78 |
|
String swap = tok.nextToken(); // " 0.0" |
79 |
< |
System.out.println("swap: "+swap); |
79 |
> |
// System.out.println("swap: "+swap); |
80 |
|
|
81 |
|
line = in.readLine(); // Memory: 4096M real, 2380M free, 1237M swap in use, 9774M swap free |
82 |
< |
System.out.println("line4: "+line); |
82 |
> |
// System.out.println("line4: "+line); |
83 |
|
tok = new StringTokenizer(line,": ,",false); |
84 |
|
tok.nextToken(); // Memory: |
85 |
|
String real = tok.nextToken(); // "4096M" |
86 |
< |
System.out.println("real: "+real); |
86 |
> |
// System.out.println("real: "+real); |
87 |
|
tok.nextToken(); // real |
88 |
|
String free = tok.nextToken(", "); // "2380M" |
89 |
< |
System.out.println("free: "+free); |
89 |
> |
// System.out.println("free: "+free); |
90 |
|
tok.nextToken(); // free |
91 |
|
String swapInUse = tok.nextToken(); // "1237M" |
92 |
< |
System.out.println("swapInUse: "+swapInUse); |
92 |
> |
// System.out.println("swapInUse: "+swapInUse); |
93 |
|
tok.nextToken(); // swap |
94 |
|
tok.nextToken(); // in |
95 |
|
tok.nextToken(); // use |
96 |
|
String swapFree = tok.nextToken(", "); // "9774M" |
97 |
< |
System.out.println("swapFree: "+swapFree); |
97 |
> |
// System.out.println("swapFree: "+swapFree); |
98 |
|
|
99 |
|
// done now make it into an xml packet ;) |
100 |
|
|
119 |
|
packet.addElement("swap",swap.trim()); |
120 |
|
packet.closeNest(); |
121 |
|
packet.addNest("memory"); |
122 |
< |
packet.addElement("real",real); |
123 |
< |
packet.addElement("free",free); |
124 |
< |
packet.addElement("swapinuse",swapInUse); |
125 |
< |
packet.addElement("swapfree",swapFree); |
122 |
> |
packet.addElement("total",real.substring(0, real.length()-1)); |
123 |
> |
packet.addElement("free",free.substring(0, free.length()-1)); |
124 |
> |
packet.closeNest(); |
125 |
> |
packet.addNest("swap"); |
126 |
> |
packet.addElement("inuse",swapInUse.substring(0, swapInUse.length()-1)); |
127 |
> |
packet.addElement("free",swapFree.substring(0, swapFree.length()-1)); |
128 |
|
packet.closeNest(); |
129 |
|
|
130 |
|
in.close(); |
143 |
|
} |
144 |
|
|
145 |
|
|
146 |
< |
} // class |
146 |
> |
} // class |