--- projects/cms/source/host/java/SystemMonitor.java 2000/11/27 20:36:30 1.2 +++ projects/cms/source/host/java/SystemMonitor.java 2001/03/19 17:30:17 1.9 @@ -2,14 +2,18 @@ //---IMPORTS--- +import java.io.*; +import java.net.*; +import java.util.*; + /** * Gathers system information then outputs it as XML - * Collects data based on properties gained from the configurator - * then packages these up using XMLFormatter and outputs them if - * the timeout has passed. + * Collects data based on properties gained from the + * configurator then packages these up using XMLFormatter + * and outputs them if the timeout has passed. * * @author $Author: ab11 $ - * @version $Id: SystemMonitor.java,v 1.2 2000/11/27 20:36:30 ab11 Exp $ + * @version $Id: SystemMonitor.java,v 1.9 2001/03/19 17:30:17 ab11 Exp $ */ class SystemMonitor { @@ -20,8 +24,8 @@ class SystemMonitor { //---CONSTRUCTORS--- /** - * Public constructor for the class. Takes in a Config object to gain its - * properties from. + * Public constructor for the class. Takes in a Config + * object to gain its properties from. * */ public SystemMonitor( Config config ){ @@ -29,12 +33,7 @@ class SystemMonitor { // like things to monitor lastCheck = System.currentTimeMillis(); - sequence = 0; - - - // why oh why wont ultra edit let me put Long in the next line? oh its trying to - // correct keywords =| - checkInterval = Long.parseLong(config.getProperty("UDPINTEVAL")); + sequence = 1; } @@ -47,29 +46,26 @@ class SystemMonitor { */ public String getInfo(){ // called to retrieve the stored averages and output them as a XML string - XMLFormatter xml = new XMLFormatter("packet"); - - // 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(); - xml.addNest("core"); - xml.addElement("cpu","100"); - xml.addElement("memory","200"); - xml.closeNest(); - xml.addNest("additional"); - xml.addElement("users","20"); - xml.closeNest(); - - // MUST FIX THIS..!!!! - while ( System.currentTimeMillis() < ( lastCheck + checkInterval ) ){ - // errm do nothing.. block or something. + String host = new String(); + String ip = new String(); + try { + host = InetAddress.getLocalHost().getHostName(); + ip = InetAddress.getLocalHost().getHostAddress(); + } catch(UnknownHostException e) { + System.out.println(e); } + 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()); // increment sequence. sequence++; + // lastCheck = System.currentTimeMillis(); // finally return a string return xml.returnXML(); @@ -83,8 +79,7 @@ class SystemMonitor { private long lastCheck; private int sequence; - private long checkInterval; //---STATIC ATTRIBUTES--- -} // class \ No newline at end of file +} // class