--- projects/cms/source/host/java/DecodeCPU_TXT.java 2001/01/22 04:31:18 1.9 +++ projects/cms/source/host/java/DecodeCPU_TXT.java 2002/05/18 18:15:57 1.12 @@ -1,12 +1,31 @@ +/* + * i-scream central monitoring system + * Copyright (C) 2000-2002 i-scream + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + import java.io.*; import java.util.*; class DecodeCPU_TXT { - XMLFormatter packet; + XMLFormatter packet; - public DecodeCPU_TXT(){ - HashMap data; + public DecodeCPU_TXT(){ + HashMap data; try { String[] cmd = {"statgrab.pl"}; Process proc = Runtime.getRuntime().exec(cmd); @@ -26,26 +45,26 @@ class DecodeCPU_TXT { catch (Exception e) {} String load1 = (String) data.get("packet.load.load1"); - String load5 = (String) data.get("packet.load.load5"); - String load15 = (String) data.get("packet.load.load15"); - - String totalProcesses = (String) data.get("packet.processes.total"); - String sleeping = (String) data.get("packet.processes.sleeping"); - String zombie = (String) data.get("packet.processes.zombie"); - String stopped = (String) data.get("packet.processes.stopped"); - String onCPU = (String) data.get("packet.processes.cpu"); - - String idle = (String) data.get("packet.cpu.idle"); - String user = (String) data.get("packet.cpu.user"); - String kernel = (String) data.get("packet.cpu.kernel"); - String iowait = (String) data.get("packet.cpu.iowait"); - String swap = (String) data.get("packet.cpu.swap"); - - String real = (String) data.get("packet.memory.real"); - String free = (String) data.get("packet.memory.free"); - String swapInUse = (String) data.get("packet.memory.swap_in_use"); - String swapFree = (String) data.get("packet.memory.swap_free"); + String load5 = (String) data.get("packet.load.load5"); + String load15 = (String) data.get("packet.load.load15"); + String totalProcesses = (String) data.get("packet.processes.total"); + String sleeping = (String) data.get("packet.processes.sleeping"); + String zombie = (String) data.get("packet.processes.zombie"); + String stopped = (String) data.get("packet.processes.stopped"); + String onCPU = (String) data.get("packet.processes.cpu"); + + String idle = (String) data.get("packet.cpu.idle"); + String user = (String) data.get("packet.cpu.user"); + String kernel = (String) data.get("packet.cpu.kernel"); + String iowait = (String) data.get("packet.cpu.iowait"); + String swap = (String) data.get("packet.cpu.swap"); + + String real = (String) data.get("packet.memory.real"); + String free = (String) data.get("packet.memory.free"); + String swapTotal = (String) data.get("packet.memory.swap_total"); + String swapFree = (String) data.get("packet.memory.swap_free"); + String osname = (String) data.get("packet.os.name"); String osrelease = (String) data.get("packet.os.release"); String osplatform = (String) data.get("packet.os.platform"); @@ -62,39 +81,56 @@ class DecodeCPU_TXT { packet.addElement("platform",osplatform); packet.addElement("sysname",ossysname); packet.addElement("version",osversion); - packet.closeNest(); - packet.addNest("load"); - packet.addElement("load1",load1); - packet.addElement("load5",load5); - packet.addElement("load15",load15); - packet.closeNest(); - packet.addNest("processes"); - packet.addElement("total",totalProcesses); - packet.addElement("sleeping",sleeping); - packet.addElement("zombie",zombie); - packet.addElement("stopped",stopped); - packet.closeNest(); - packet.addNest("cpu"); - packet.addElement("idle",idle); - packet.addElement("user",user); - packet.addElement("kernel",kernel); - packet.addElement("iowait",iowait); - packet.addElement("swap",swap); - packet.closeNest(); - packet.addNest("memory"); - packet.addElement("total",real); - packet.addElement("free",free); - packet.closeNest(); - packet.addNest("swap"); - packet.addElement("inuse",swapInUse); - packet.addElement("free",swapFree); - packet.closeNest(); + packet.closeNest(); + packet.addNest("load"); + packet.addElement("load1",load1); + packet.addElement("load5",load5); + packet.addElement("load15",load15); + packet.closeNest(); + packet.addNest("processes"); + packet.addElement("total",totalProcesses); + packet.addElement("sleeping",sleeping); + packet.addElement("zombie",zombie); + packet.addElement("stopped",stopped); + packet.addElement("cpu",onCPU); + packet.closeNest(); + packet.addNest("cpu"); + packet.addElement("idle",idle); + packet.addElement("user",user); + packet.addElement("kernel",kernel); + packet.addElement("iowait",iowait); + packet.addElement("swap",swap); + packet.closeNest(); + packet.addNest("memory"); + packet.addElement("total",real); + packet.addElement("free",free); + packet.closeNest(); + packet.addNest("swap"); + packet.addElement("total",swapTotal); + packet.addElement("free",swapFree); + packet.closeNest(); packet.addNest("users"); packet.addElement("count",usercount); - //packet.addElement("list",userlist); - packet.closeNest(); - - in.close(); + packet.addElement("list",userlist); + packet.closeNest(); + packet.addNest("disk"); + int i=0; + while(true) { + String check = (String) data.get("packet.disk.p"+i+".attributes.name"); + if(check == null) { + break; + } + packet.addNest("p"+i); + packet.addElement("name",check); + packet.addElement("kbytes",(String) data.get("packet.disk.p"+i+".attributes.kbytes")); + packet.addElement("used",(String) data.get("packet.disk.p"+i+".attributes.used")); + packet.addElement("avail",(String) data.get("packet.disk.p"+i+".attributes.avail")); + packet.addElement("mount",(String) data.get("packet.disk.p"+i+".attributes.mount")); + packet.closeNest(); + i++; + } + packet.closeNest(); + in.close(); } catch(Exception e) { @@ -102,12 +138,12 @@ class DecodeCPU_TXT { e.printStackTrace(); } - } + } - public String getItems(){ - // return the xml - return packet.returnXML(); - } - + public String getItems(){ + // return the xml + return packet.returnXML(); + } + } // class