3 |
|
|
4 |
|
class DecodeCPU_TXT { |
5 |
|
|
6 |
< |
XMLFormatter packet; |
6 |
> |
XMLFormatter packet; |
7 |
|
|
8 |
< |
public DecodeCPU_TXT(){ |
9 |
< |
HashMap data; |
8 |
> |
public DecodeCPU_TXT(){ |
9 |
> |
HashMap data; |
10 |
|
try { |
11 |
|
String[] cmd = {"statgrab.pl"}; |
12 |
|
Process proc = Runtime.getRuntime().exec(cmd); |
26 |
|
catch (Exception e) {} |
27 |
|
|
28 |
|
String load1 = (String) data.get("packet.load.load1"); |
29 |
< |
String load5 = (String) data.get("packet.load.load5"); |
30 |
< |
String load15 = (String) data.get("packet.load.load15"); |
31 |
< |
|
32 |
< |
String totalProcesses = (String) data.get("packet.processes.total"); |
33 |
< |
String sleeping = (String) data.get("packet.processes.sleeping"); |
34 |
< |
String zombie = (String) data.get("packet.processes.zombie"); |
35 |
< |
String stopped = (String) data.get("packet.processes.stopped"); |
36 |
< |
String onCPU = (String) data.get("packet.processes.cpu"); |
37 |
< |
|
38 |
< |
String idle = (String) data.get("packet.cpu.idle"); |
39 |
< |
String user = (String) data.get("packet.cpu.user"); |
40 |
< |
String kernel = (String) data.get("packet.cpu.kernel"); |
41 |
< |
String iowait = (String) data.get("packet.cpu.iowait"); |
42 |
< |
String swap = (String) data.get("packet.cpu.swap"); |
43 |
< |
|
44 |
< |
String real = (String) data.get("packet.memory.real"); |
45 |
< |
String free = (String) data.get("packet.memory.free"); |
46 |
< |
String swapInUse = (String) data.get("packet.memory.swap_in_use"); |
47 |
< |
String swapFree = (String) data.get("packet.memory.swap_free"); |
29 |
> |
String load5 = (String) data.get("packet.load.load5"); |
30 |
> |
String load15 = (String) data.get("packet.load.load15"); |
31 |
|
|
32 |
+ |
String totalProcesses = (String) data.get("packet.processes.total"); |
33 |
+ |
String sleeping = (String) data.get("packet.processes.sleeping"); |
34 |
+ |
String zombie = (String) data.get("packet.processes.zombie"); |
35 |
+ |
String stopped = (String) data.get("packet.processes.stopped"); |
36 |
+ |
String onCPU = (String) data.get("packet.processes.cpu"); |
37 |
+ |
|
38 |
+ |
String idle = (String) data.get("packet.cpu.idle"); |
39 |
+ |
String user = (String) data.get("packet.cpu.user"); |
40 |
+ |
String kernel = (String) data.get("packet.cpu.kernel"); |
41 |
+ |
String iowait = (String) data.get("packet.cpu.iowait"); |
42 |
+ |
String swap = (String) data.get("packet.cpu.swap"); |
43 |
+ |
|
44 |
+ |
String real = (String) data.get("packet.memory.real"); |
45 |
+ |
String free = (String) data.get("packet.memory.free"); |
46 |
+ |
String swapTotal = (String) data.get("packet.memory.swap_total"); |
47 |
+ |
String swapFree = (String) data.get("packet.memory.swap_free"); |
48 |
+ |
|
49 |
|
String osname = (String) data.get("packet.os.name"); |
50 |
|
String osrelease = (String) data.get("packet.os.release"); |
51 |
|
String osplatform = (String) data.get("packet.os.platform"); |
62 |
|
packet.addElement("platform",osplatform); |
63 |
|
packet.addElement("sysname",ossysname); |
64 |
|
packet.addElement("version",osversion); |
65 |
< |
packet.closeNest(); |
66 |
< |
packet.addNest("load"); |
67 |
< |
packet.addElement("load1",load1); |
68 |
< |
packet.addElement("load5",load5); |
69 |
< |
packet.addElement("load15",load15); |
70 |
< |
packet.closeNest(); |
71 |
< |
packet.addNest("processes"); |
72 |
< |
packet.addElement("total",totalProcesses); |
73 |
< |
packet.addElement("sleeping",sleeping); |
74 |
< |
packet.addElement("zombie",zombie); |
75 |
< |
packet.addElement("stopped",stopped); |
76 |
< |
packet.closeNest(); |
77 |
< |
packet.addNest("cpu"); |
78 |
< |
packet.addElement("idle",idle); |
79 |
< |
packet.addElement("user",user); |
80 |
< |
packet.addElement("kernel",kernel); |
81 |
< |
packet.addElement("iowait",iowait); |
82 |
< |
packet.addElement("swap",swap); |
83 |
< |
packet.closeNest(); |
84 |
< |
packet.addNest("memory"); |
85 |
< |
packet.addElement("total",real); |
86 |
< |
packet.addElement("free",free); |
87 |
< |
packet.closeNest(); |
88 |
< |
packet.addNest("swap"); |
89 |
< |
packet.addElement("inuse",swapInUse); |
90 |
< |
packet.addElement("free",swapFree); |
91 |
< |
packet.closeNest(); |
65 |
> |
packet.closeNest(); |
66 |
> |
packet.addNest("load"); |
67 |
> |
packet.addElement("load1",load1); |
68 |
> |
packet.addElement("load5",load5); |
69 |
> |
packet.addElement("load15",load15); |
70 |
> |
packet.closeNest(); |
71 |
> |
packet.addNest("processes"); |
72 |
> |
packet.addElement("total",totalProcesses); |
73 |
> |
packet.addElement("sleeping",sleeping); |
74 |
> |
packet.addElement("zombie",zombie); |
75 |
> |
packet.addElement("stopped",stopped); |
76 |
> |
packet.closeNest(); |
77 |
> |
packet.addNest("cpu"); |
78 |
> |
packet.addElement("idle",idle); |
79 |
> |
packet.addElement("user",user); |
80 |
> |
packet.addElement("kernel",kernel); |
81 |
> |
packet.addElement("iowait",iowait); |
82 |
> |
packet.addElement("swap",swap); |
83 |
> |
packet.closeNest(); |
84 |
> |
packet.addNest("memory"); |
85 |
> |
packet.addElement("total",real); |
86 |
> |
packet.addElement("free",free); |
87 |
> |
packet.closeNest(); |
88 |
> |
packet.addNest("swap"); |
89 |
> |
packet.addElement("total",swapTotal); |
90 |
> |
packet.addElement("free",swapFree); |
91 |
> |
packet.closeNest(); |
92 |
|
packet.addNest("users"); |
93 |
|
packet.addElement("count",usercount); |
94 |
< |
//packet.addElement("list",userlist); |
95 |
< |
packet.closeNest(); |
96 |
< |
|
97 |
< |
in.close(); |
94 |
> |
packet.addElement("list",userlist); |
95 |
> |
packet.closeNest(); |
96 |
> |
packet.addNest("disk"); |
97 |
> |
int i=0; |
98 |
> |
while(true) { |
99 |
> |
String check = (String) data.get("packet.disk.p"+i+".attributes.name"); |
100 |
> |
if(check == null) { |
101 |
> |
break; |
102 |
> |
} |
103 |
> |
packet.addNest("p"+i); |
104 |
> |
packet.addElement("name",check); |
105 |
> |
packet.addElement("kbytes",(String) data.get("packet.disk.p"+i+".attributes.kbytes")); |
106 |
> |
packet.addElement("used",(String) data.get("packet.disk.p"+i+".attributes.used")); |
107 |
> |
packet.addElement("avail",(String) data.get("packet.disk.p"+i+".attributes.avail")); |
108 |
> |
packet.addElement("mount",(String) data.get("packet.disk.p"+i+".attributes.mount")); |
109 |
> |
packet.closeNest(); |
110 |
> |
i++; |
111 |
> |
} |
112 |
> |
packet.closeNest(); |
113 |
> |
in.close(); |
114 |
|
|
115 |
|
} |
116 |
|
catch(Exception e) { |
118 |
|
e.printStackTrace(); |
119 |
|
} |
120 |
|
|
121 |
< |
} |
121 |
> |
} |
122 |
|
|
123 |
< |
public String getItems(){ |
124 |
< |
// return the xml |
125 |
< |
return packet.returnXML(); |
126 |
< |
} |
127 |
< |
|
123 |
> |
public String getItems(){ |
124 |
> |
// return the xml |
125 |
> |
return packet.returnXML(); |
126 |
> |
} |
127 |
> |
|
128 |
|
|
129 |
|
} // class |