--- projects/cms/source/host/java/SystemMonitor.java 2000/12/07 18:25:37 1.5 +++ projects/cms/source/host/java/SystemMonitor.java 2001/01/19 00:13:49 1.8 @@ -2,8 +2,9 @@ //---IMPORTS--- -import java.util.Random; import java.io.*; +import java.net.*; +import java.util.*; /** * Gathers system information then outputs it as XML @@ -11,8 +12,8 @@ import java.io.*; * then packages these up using XMLFormatter and outputs them if * the timeout has passed. * - * @author $Author: ab11 $ - * @version $Id: SystemMonitor.java,v 1.5 2000/12/07 18:25:37 ab11 Exp $ + * @author $Author: tdb $ + * @version $Id: SystemMonitor.java,v 1.8 2001/01/19 00:13:49 tdb Exp $ */ class SystemMonitor { @@ -32,11 +33,13 @@ class SystemMonitor { // like things to monitor lastCheck = System.currentTimeMillis(); - sequence = 0; + sequence = 1; // why oh why wont ultra edit let me put Long in the next line? oh its trying to // correct keywords =| + /* + try { udpcheckInterval = Long.parseLong(config.getProperty("UDPUpdateTime")) * 1000; } @@ -45,6 +48,8 @@ class SystemMonitor { // 5 mins udpcheckInterval = 5000 * 60; } + */ + // make the check interval into seconds } @@ -58,41 +63,25 @@ class SystemMonitor { */ public String getInfo(){ // called to retrieve the stored averages and output them as a XML string - XMLFormatter xml = new XMLFormatter("packet"); - - // the process to run + String host = new String(); + String ip = new String(); try { - Process proc = Runtime.getRuntime().exec("/usr/local/sbin/top -s1 -d2 0 > top.txt"); - // this process will take atleast 2 seconds to complete - try { - proc.waitFor(); - } - catch ( InterruptedException e ){ - - } - + host = InetAddress.getLocalHost().getHostName(); + ip = InetAddress.getLocalHost().getHostAddress(); + } catch(UnknownHostException e) { + System.out.println(e); } - catch ( IOException e ){ - - } - - - - // now do some text processing. - DecodeCPU_TXT details = new DecodeCPU_TXT("top.txt"); - - - Random rand = new Random(); - - // just send some dummy info for now. - xml.addNest("packet_info"); - String currentTime = Long.toString(System.currentTimeMillis()); - xml.addElement("date_time", currentTime ); - xml.addElement("sequence", Integer.toString(sequence)); - xml.closeNest(); + String date = Long.toString(System.currentTimeMillis()); + XMLFormatter xml = new XMLFormatter("packet", "machine_name=\""+host+"\" ip=\""+ip+"\" date=\""+date+"\" seq_no=\""+sequence+"\" type=\"data\""); + + // get and decode the data + DecodeCPU_TXT details = new DecodeCPU_TXT(); + + // add the decoded info xml.addString(details.getItems()); + /* // MUST FIX THIS..!!!! try { long updateIn = ( lastCheck + udpcheckInterval )-System.currentTimeMillis(); @@ -107,10 +96,11 @@ class SystemMonitor { catch( InterruptedException e ){ System.out.println("Sleep interrupted"); } + */ // increment sequence. sequence++; - lastCheck = System.currentTimeMillis(); + // lastCheck = System.currentTimeMillis(); // finally return a string return xml.returnXML(); @@ -124,8 +114,6 @@ class SystemMonitor { private long lastCheck; private int sequence; - private long udpcheckInterval; - private final long defaultUpdateTime = 60000; //---STATIC ATTRIBUTES---