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