| 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; |
| 7 |
< |
|
| 8 |
< |
public static final String VERSION = "statgrab.pl $Revision$"; |
| 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); |
| 44 |
|
} |
| 45 |
|
catch (Exception e) {} |
| 46 |
|
|
| 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 |
– |
|
| 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"); |
| 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"); |
| 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.addNest("load"); |
| 85 |
< |
packet.addElement("load1",load1); |
| 86 |
< |
packet.addElement("load5",load5); |
| 87 |
< |
packet.addElement("load15",load15); |
| 88 |
< |
packet.closeNest(); |
| 89 |
< |
packet.addNest("processes"); |
| 90 |
< |
packet.addElement("total",totalProcesses); |
| 91 |
< |
packet.addElement("sleeping",sleeping); |
| 92 |
< |
packet.addElement("zombie",zombie); |
| 93 |
< |
packet.addElement("stopped",stopped); |
| 94 |
< |
packet.closeNest(); |
| 95 |
< |
packet.addNest("cpu"); |
| 96 |
< |
packet.addElement("idle",idle); |
| 97 |
< |
packet.addElement("user",user); |
| 98 |
< |
packet.addElement("kernel",kernel); |
| 99 |
< |
packet.addElement("iowait",iowait); |
| 100 |
< |
packet.addElement("swap",swap); |
| 101 |
< |
packet.closeNest(); |
| 102 |
< |
packet.addNest("memory"); |
| 103 |
< |
packet.addElement("total",real); |
| 104 |
< |
packet.addElement("free",free); |
| 105 |
< |
packet.closeNest(); |
| 106 |
< |
packet.addNest("swap"); |
| 107 |
< |
packet.addElement("inuse",swapInUse); |
| 108 |
< |
packet.addElement("free",swapFree); |
| 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(); |
| 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 |