| 1 |
ab11 |
1.2 |
//---PACKAGE DECLARATION--- |
| 2 |
|
|
|
| 3 |
|
|
//---IMPORTS--- |
| 4 |
|
|
|
| 5 |
ab11 |
1.5 |
import java.io.*; |
| 6 |
tdb |
1.6 |
import java.net.*; |
| 7 |
|
|
import java.util.*; |
| 8 |
ab11 |
1.3 |
|
| 9 |
ab11 |
1.2 |
/** |
| 10 |
|
|
* Gathers system information then outputs it as XML |
| 11 |
ab11 |
1.9 |
* Collects data based on properties gained from the |
| 12 |
|
|
* configurator then packages these up using XMLFormatter |
| 13 |
|
|
* and outputs them if the timeout has passed. |
| 14 |
ab11 |
1.2 |
* |
| 15 |
ab11 |
1.9 |
* @author $Author: tdb1 $ |
| 16 |
|
|
* @version $Id: SystemMonitor.java,v 1.8 2001/01/19 00:13:49 tdb1 Exp $ |
| 17 |
ab11 |
1.2 |
*/ |
| 18 |
ab11 |
1.1 |
class SystemMonitor { |
| 19 |
|
|
|
| 20 |
ab11 |
1.2 |
//---FINAL ATTRIBUTES--- |
| 21 |
|
|
|
| 22 |
|
|
//---STATIC METHODS--- |
| 23 |
|
|
|
| 24 |
|
|
//---CONSTRUCTORS--- |
| 25 |
|
|
|
| 26 |
|
|
/** |
| 27 |
ab11 |
1.9 |
* Public constructor for the class. Takes in a Config |
| 28 |
|
|
* object to gain its properties from. |
| 29 |
ab11 |
1.2 |
* |
| 30 |
|
|
*/ |
| 31 |
|
|
public SystemMonitor( Config config ){ |
| 32 |
|
|
// create a new instace, get the info we need out of config |
| 33 |
|
|
// like things to monitor |
| 34 |
|
|
|
| 35 |
|
|
lastCheck = System.currentTimeMillis(); |
| 36 |
tdb |
1.6 |
sequence = 1; |
| 37 |
ab11 |
1.2 |
|
| 38 |
|
|
} |
| 39 |
|
|
|
| 40 |
|
|
//---PUBLIC METHODS--- |
| 41 |
|
|
|
| 42 |
|
|
/** |
| 43 |
|
|
* Gathers system information and will black until the timeout has passed. |
| 44 |
|
|
* |
| 45 |
|
|
* @return the system information in an XML packet |
| 46 |
|
|
*/ |
| 47 |
|
|
public String getInfo(){ |
| 48 |
|
|
// called to retrieve the stored averages and output them as a XML string |
| 49 |
tdb |
1.6 |
String host = new String(); |
| 50 |
|
|
String ip = new String(); |
| 51 |
ab11 |
1.5 |
try { |
| 52 |
tdb |
1.6 |
host = InetAddress.getLocalHost().getHostName(); |
| 53 |
ab11 |
1.9 |
ip = InetAddress.getLocalHost().getHostAddress(); |
| 54 |
tdb |
1.6 |
} catch(UnknownHostException e) { |
| 55 |
|
|
System.out.println(e); |
| 56 |
ab11 |
1.5 |
} |
| 57 |
ab11 |
1.9 |
String date = Long.toString(System.currentTimeMillis()); |
| 58 |
tdb |
1.8 |
XMLFormatter xml = new XMLFormatter("packet", "machine_name=\""+host+"\" ip=\""+ip+"\" date=\""+date+"\" seq_no=\""+sequence+"\" type=\"data\""); |
| 59 |
tdb |
1.6 |
|
| 60 |
ab11 |
1.9 |
// get and decode the data |
| 61 |
|
|
DecodeCPU_TXT details = new DecodeCPU_TXT(); |
| 62 |
tdb |
1.6 |
|
| 63 |
|
|
// add the decoded info |
| 64 |
ab11 |
1.5 |
xml.addString(details.getItems()); |
| 65 |
|
|
|
| 66 |
ab11 |
1.2 |
// increment sequence. |
| 67 |
|
|
sequence++; |
| 68 |
ab11 |
1.7 |
// lastCheck = System.currentTimeMillis(); |
| 69 |
ab11 |
1.2 |
|
| 70 |
|
|
// finally return a string |
| 71 |
|
|
return xml.returnXML(); |
| 72 |
|
|
} // getinfo() |
| 73 |
|
|
|
| 74 |
|
|
//---PRIVATE METHODS--- |
| 75 |
|
|
|
| 76 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
| 77 |
|
|
|
| 78 |
|
|
//---ATTRIBUTES--- |
| 79 |
ab11 |
1.1 |
|
| 80 |
|
|
private long lastCheck; |
| 81 |
|
|
private int sequence; |
| 82 |
ab11 |
1.2 |
|
| 83 |
|
|
//---STATIC ATTRIBUTES--- |
| 84 |
ab11 |
1.1 |
|
| 85 |
ab11 |
1.9 |
} // class |