--- projects/cms/source/host/java/SystemMonitor.java 2000/11/30 04:11:00 1.3 +++ projects/cms/source/host/java/SystemMonitor.java 2002/05/21 16:47:12 1.11 @@ -1,17 +1,39 @@ +/* + * i-scream central monitoring system + * http://www.i-scream.org.uk + * 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. + */ + //---PACKAGE DECLARATION--- //---IMPORTS--- -import java.util.Random; +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.3 2000/11/30 04:11:00 ab11 Exp $ + * @author $Author: tdb $ + * @version $Id: SystemMonitor.java,v 1.11 2002/05/21 16:47:12 tdb Exp $ */ class SystemMonitor { @@ -22,8 +44,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 ){ @@ -31,13 +53,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("UDPUpdateTime")) * 1000; - // make the check interval into seconds + sequence = 1; } @@ -50,36 +66,26 @@ class SystemMonitor { */ public String getInfo(){ // called to retrieve the stored averages and output them as a XML string - XMLFormatter xml = new XMLFormatter("packet"); - - 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..!!!! + String host = new String(); + String ip = new String(); try { - Thread.sleep(( lastCheck + checkInterval )-System.currentTimeMillis()); + host = InetAddress.getLocalHost().getHostName(); + ip = InetAddress.getLocalHost().getHostAddress(); + } catch(UnknownHostException e) { + System.out.println(e); } - catch( InterruptedException e ){ - System.out.println("Sleep interrupted"); - } + 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(); + // lastCheck = System.currentTimeMillis(); // finally return a string return xml.returnXML(); @@ -93,8 +99,7 @@ class SystemMonitor { private long lastCheck; private int sequence; - private long checkInterval; //---STATIC ATTRIBUTES--- -} // class \ No newline at end of file +} // class