--- projects/cms/source/host/java/SystemMonitor.java 2000/11/30 04:11:00 1.3 +++ projects/cms/source/host/java/SystemMonitor.java 2000/12/08 15:45:28 1.7 @@ -2,7 +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,7 +13,7 @@ import java.util.Random; * the timeout has passed. * * @author $Author: ab11 $ - * @version $Id: SystemMonitor.java,v 1.3 2000/11/30 04:11:00 ab11 Exp $ + * @version $Id: SystemMonitor.java,v 1.7 2000/12/08 15:45:28 ab11 Exp $ */ class SystemMonitor { @@ -31,12 +33,23 @@ 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 =| - checkInterval = Long.parseLong(config.getProperty("UDPUpdateTime")) * 1000; + /* + + try { + udpcheckInterval = Long.parseLong(config.getProperty("UDPUpdateTime")) * 1000; + } + catch ( NumberFormatException e ){ + System.out.println("The value for UDPUpdateTime is invalid, using a default"); + // 5 mins + udpcheckInterval = 5000 * 60; + } + */ + // make the check interval into seconds } @@ -50,36 +63,44 @@ class SystemMonitor { */ public String getInfo(){ // called to retrieve the stored averages and output them as a XML string - XMLFormatter xml = new XMLFormatter("packet"); + 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+"\""); + + // get and decode the data + DecodeCPU_TXT details = new DecodeCPU_TXT(); + + // add the decoded info + xml.addString(details.getItems()); - 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(); - xml.addNest("core"); - xml.addElement("cpu",""+rand.nextInt(100)); - xml.addElement("memory",""+rand.nextInt(100)); - xml.closeNest(); - if ( rand.nextBoolean() ){ - xml.addNest("additional"); - xml.addElement("users",""+rand.nextInt(30)); - xml.closeNest(); - } + /* // MUST FIX THIS..!!!! try { - Thread.sleep(( lastCheck + checkInterval )-System.currentTimeMillis()); + long updateIn = ( lastCheck + udpcheckInterval )-System.currentTimeMillis(); + if ( updateIn > 0 ){ + Thread.sleep(updateIn); + } + else + { + Thread.sleep(defaultUpdateTime); + } } catch( InterruptedException e ){ System.out.println("Sleep interrupted"); } + */ // increment sequence. sequence++; - lastCheck = System.currentTimeMillis(); + // lastCheck = System.currentTimeMillis(); // finally return a string return xml.returnXML(); @@ -93,7 +114,6 @@ class SystemMonitor { private long lastCheck; private int sequence; - private long checkInterval; //---STATIC ATTRIBUTES---