ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/java/DecodeCPU_TXT.java
Revision: 1.12
Committed: Sat May 18 18:15:57 2002 UTC (22 years, 6 months ago) by tdb
Branch: MAIN
Changes since 1.11: +19 -0 lines
Log Message:
i-scream is now licensed under the GPL. I've added the GPL headers to every
source file, and put a full copy of the license in the appropriate places.
I think I've covered everything. This is going to be a mad commit ;)

File Contents

# Content
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;
26
27 public DecodeCPU_TXT(){
28 HashMap data;
29 try {
30 String[] cmd = {"statgrab.pl"};
31 Process proc = Runtime.getRuntime().exec(cmd);
32 BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
33
34 data = new HashMap();
35
36 // Messy, but it'll keep going until no more data :/
37 try {
38 String line = new String();
39 while(true) {
40 line = in.readLine();
41 int split = line.indexOf(' ');
42 data.put(line.substring(0, split), line.substring(split+1));
43 }
44 }
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");
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");
71 String ossysname = (String) data.get("packet.os.sysname");
72 String osversion = (String) data.get("packet.os.version");
73
74 String usercount = (String) data.get("packet.users.count");
75 String userlist = (String) data.get("packet.users.list");
76
77 packet = new XMLFormatter();
78 packet.addNest("os");
79 packet.addElement("name",osname);
80 packet.addElement("release",osrelease);
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.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 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) {
137 System.out.println("ERROR IN DECODE: "+e);
138 e.printStackTrace();
139 }
140
141 }
142
143 public String getItems(){
144 // return the xml
145 return packet.returnXML();
146 }
147
148
149 } // class