1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* Copyright (C) 2000-2002 i-scream |
4 |
+ |
* |
5 |
+ |
* This program is free software; you can redistribute it and/or |
6 |
+ |
* modify it under the terms of the GNU General Public License |
7 |
+ |
* as published by the Free Software Foundation; either version 2 |
8 |
+ |
* of the License, or (at your option) any later version. |
9 |
+ |
* |
10 |
+ |
* This program is distributed in the hope that it will be useful, |
11 |
+ |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
+ |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
+ |
* GNU General Public License for more details. |
14 |
+ |
* |
15 |
+ |
* You should have received a copy of the GNU General Public License |
16 |
+ |
* along with this program; if not, write to the Free Software |
17 |
+ |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
+ |
*/ |
19 |
+ |
|
20 |
|
import java.io.*; |
21 |
|
import java.util.*; |
22 |
|
|
23 |
|
class DecodeCPU_TXT { |
24 |
|
|
25 |
< |
XMLFormatter packet; |
25 |
> |
XMLFormatter packet; |
26 |
|
|
27 |
< |
public DecodeCPU_TXT(){ |
28 |
< |
HashMap data; |
27 |
> |
public DecodeCPU_TXT(){ |
28 |
> |
HashMap data; |
29 |
|
try { |
30 |
|
String[] cmd = {"statgrab.pl"}; |
31 |
|
Process proc = Runtime.getRuntime().exec(cmd); |
45 |
|
catch (Exception e) {} |
46 |
|
|
47 |
|
String load1 = (String) data.get("packet.load.load1"); |
48 |
< |
String load5 = (String) data.get("packet.load.load5"); |
49 |
< |
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"); |
48 |
> |
String load5 = (String) data.get("packet.load.load5"); |
49 |
> |
String load15 = (String) data.get("packet.load.load15"); |
50 |
|
|
51 |
+ |
String totalProcesses = (String) data.get("packet.processes.total"); |
52 |
+ |
String sleeping = (String) data.get("packet.processes.sleeping"); |
53 |
+ |
String zombie = (String) data.get("packet.processes.zombie"); |
54 |
+ |
String stopped = (String) data.get("packet.processes.stopped"); |
55 |
+ |
String onCPU = (String) data.get("packet.processes.cpu"); |
56 |
+ |
|
57 |
+ |
String idle = (String) data.get("packet.cpu.idle"); |
58 |
+ |
String user = (String) data.get("packet.cpu.user"); |
59 |
+ |
String kernel = (String) data.get("packet.cpu.kernel"); |
60 |
+ |
String iowait = (String) data.get("packet.cpu.iowait"); |
61 |
+ |
String swap = (String) data.get("packet.cpu.swap"); |
62 |
+ |
|
63 |
+ |
String real = (String) data.get("packet.memory.real"); |
64 |
+ |
String free = (String) data.get("packet.memory.free"); |
65 |
+ |
String swapTotal = (String) data.get("packet.memory.swap_total"); |
66 |
+ |
String swapFree = (String) data.get("packet.memory.swap_free"); |
67 |
+ |
|
68 |
|
String osname = (String) data.get("packet.os.name"); |
69 |
|
String osrelease = (String) data.get("packet.os.release"); |
70 |
|
String osplatform = (String) data.get("packet.os.platform"); |
81 |
|
packet.addElement("platform",osplatform); |
82 |
|
packet.addElement("sysname",ossysname); |
83 |
|
packet.addElement("version",osversion); |
84 |
< |
packet.closeNest(); |
85 |
< |
packet.addNest("load"); |
86 |
< |
packet.addElement("load1",load1); |
87 |
< |
packet.addElement("load5",load5); |
88 |
< |
packet.addElement("load15",load15); |
89 |
< |
packet.closeNest(); |
90 |
< |
packet.addNest("processes"); |
91 |
< |
packet.addElement("total",totalProcesses); |
92 |
< |
packet.addElement("sleeping",sleeping); |
93 |
< |
packet.addElement("zombie",zombie); |
94 |
< |
packet.addElement("stopped",stopped); |
95 |
< |
packet.closeNest(); |
96 |
< |
packet.addNest("cpu"); |
97 |
< |
packet.addElement("idle",idle); |
98 |
< |
packet.addElement("user",user); |
99 |
< |
packet.addElement("kernel",kernel); |
100 |
< |
packet.addElement("iowait",iowait); |
101 |
< |
packet.addElement("swap",swap); |
102 |
< |
packet.closeNest(); |
103 |
< |
packet.addNest("memory"); |
104 |
< |
packet.addElement("total",real); |
105 |
< |
packet.addElement("free",free); |
106 |
< |
packet.closeNest(); |
107 |
< |
packet.addNest("swap"); |
108 |
< |
packet.addElement("inuse",swapInUse); |
109 |
< |
packet.addElement("free",swapFree); |
110 |
< |
packet.closeNest(); |
84 |
> |
packet.closeNest(); |
85 |
> |
packet.addNest("load"); |
86 |
> |
packet.addElement("load1",load1); |
87 |
> |
packet.addElement("load5",load5); |
88 |
> |
packet.addElement("load15",load15); |
89 |
> |
packet.closeNest(); |
90 |
> |
packet.addNest("processes"); |
91 |
> |
packet.addElement("total",totalProcesses); |
92 |
> |
packet.addElement("sleeping",sleeping); |
93 |
> |
packet.addElement("zombie",zombie); |
94 |
> |
packet.addElement("stopped",stopped); |
95 |
> |
packet.addElement("cpu",onCPU); |
96 |
> |
packet.closeNest(); |
97 |
> |
packet.addNest("cpu"); |
98 |
> |
packet.addElement("idle",idle); |
99 |
> |
packet.addElement("user",user); |
100 |
> |
packet.addElement("kernel",kernel); |
101 |
> |
packet.addElement("iowait",iowait); |
102 |
> |
packet.addElement("swap",swap); |
103 |
> |
packet.closeNest(); |
104 |
> |
packet.addNest("memory"); |
105 |
> |
packet.addElement("total",real); |
106 |
> |
packet.addElement("free",free); |
107 |
> |
packet.closeNest(); |
108 |
> |
packet.addNest("swap"); |
109 |
> |
packet.addElement("total",swapTotal); |
110 |
> |
packet.addElement("free",swapFree); |
111 |
> |
packet.closeNest(); |
112 |
|
packet.addNest("users"); |
113 |
|
packet.addElement("count",usercount); |
114 |
< |
//packet.addElement("list",userlist); |
115 |
< |
packet.closeNest(); |
116 |
< |
|
117 |
< |
in.close(); |
114 |
> |
packet.addElement("list",userlist); |
115 |
> |
packet.closeNest(); |
116 |
> |
packet.addNest("disk"); |
117 |
> |
int i=0; |
118 |
> |
while(true) { |
119 |
> |
String check = (String) data.get("packet.disk.p"+i+".attributes.name"); |
120 |
> |
if(check == null) { |
121 |
> |
break; |
122 |
> |
} |
123 |
> |
packet.addNest("p"+i); |
124 |
> |
packet.addElement("name",check); |
125 |
> |
packet.addElement("kbytes",(String) data.get("packet.disk.p"+i+".attributes.kbytes")); |
126 |
> |
packet.addElement("used",(String) data.get("packet.disk.p"+i+".attributes.used")); |
127 |
> |
packet.addElement("avail",(String) data.get("packet.disk.p"+i+".attributes.avail")); |
128 |
> |
packet.addElement("mount",(String) data.get("packet.disk.p"+i+".attributes.mount")); |
129 |
> |
packet.closeNest(); |
130 |
> |
i++; |
131 |
> |
} |
132 |
> |
packet.closeNest(); |
133 |
> |
in.close(); |
134 |
|
|
135 |
|
} |
136 |
|
catch(Exception e) { |
138 |
|
e.printStackTrace(); |
139 |
|
} |
140 |
|
|
141 |
< |
} |
141 |
> |
} |
142 |
|
|
143 |
< |
public String getItems(){ |
144 |
< |
// return the xml |
145 |
< |
return packet.returnXML(); |
146 |
< |
} |
147 |
< |
|
143 |
> |
public String getItems(){ |
144 |
> |
// return the xml |
145 |
> |
return packet.returnXML(); |
146 |
> |
} |
147 |
> |
|
148 |
|
|
149 |
|
} // class |