8 |
|
|
9 |
|
/** |
10 |
|
* Gathers system information then outputs it as XML |
11 |
< |
* Collects data based on properties gained from the configurator |
12 |
< |
* then packages these up using XMLFormatter and outputs them if |
13 |
< |
* the timeout has passed. |
11 |
> |
* 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 |
|
* |
15 |
|
* @author $Author$ |
16 |
|
* @version $Id$ |
24 |
|
//---CONSTRUCTORS--- |
25 |
|
|
26 |
|
/** |
27 |
< |
* Public constructor for the class. Takes in a Config object to gain its |
28 |
< |
* properties from. |
27 |
> |
* Public constructor for the class. Takes in a Config |
28 |
> |
* object to gain its properties from. |
29 |
|
* |
30 |
|
*/ |
31 |
|
public SystemMonitor( Config config ){ |
34 |
|
|
35 |
|
lastCheck = System.currentTimeMillis(); |
36 |
|
sequence = 1; |
37 |
– |
|
38 |
– |
|
39 |
– |
// why oh why wont ultra edit let me put Long in the next line? oh its trying to |
40 |
– |
// correct keywords =| |
41 |
– |
try { |
42 |
– |
udpcheckInterval = Long.parseLong(config.getProperty("UDPUpdateTime")) * 1000; |
43 |
– |
} |
44 |
– |
catch ( NumberFormatException e ){ |
45 |
– |
System.out.println("The value for UDPUpdateTime is invalid, using a default"); |
46 |
– |
// 5 mins |
47 |
– |
udpcheckInterval = 5000 * 60; |
48 |
– |
} |
49 |
– |
// make the check interval into seconds |
37 |
|
|
38 |
|
} |
39 |
|
|
50 |
|
String ip = new String(); |
51 |
|
try { |
52 |
|
host = InetAddress.getLocalHost().getHostName(); |
53 |
< |
ip = InetAddress.getLocalHost().getHostAddress(); |
53 |
> |
ip = InetAddress.getLocalHost().getHostAddress(); |
54 |
|
} catch(UnknownHostException e) { |
55 |
|
System.out.println(e); |
56 |
|
} |
57 |
< |
String date = Long.toString(System.currentTimeMillis()); |
58 |
< |
XMLFormatter xml = new XMLFormatter("packet", "machine_name=\""+host+"\" ip=\""+ip+"\" date=\""+date+"\" seq_no=\""+sequence+"\""); |
57 |
> |
String date = Long.toString(System.currentTimeMillis()); |
58 |
> |
XMLFormatter xml = new XMLFormatter("packet", "machine_name=\""+host+"\" ip=\""+ip+"\" date=\""+date+"\" seq_no=\""+sequence+"\" type=\"data\""); |
59 |
|
|
60 |
< |
// get and decode the data |
61 |
< |
DecodeCPU_TXT details = new DecodeCPU_TXT(); |
60 |
> |
// get and decode the data |
61 |
> |
DecodeCPU_TXT details = new DecodeCPU_TXT(); |
62 |
|
|
63 |
|
// add the decoded info |
64 |
|
xml.addString(details.getItems()); |
65 |
|
|
79 |
– |
|
80 |
– |
// MUST FIX THIS..!!!! |
81 |
– |
try { |
82 |
– |
long updateIn = ( lastCheck + udpcheckInterval )-System.currentTimeMillis(); |
83 |
– |
if ( updateIn > 0 ){ |
84 |
– |
Thread.sleep(updateIn); |
85 |
– |
} |
86 |
– |
else |
87 |
– |
{ |
88 |
– |
Thread.sleep(defaultUpdateTime); |
89 |
– |
} |
90 |
– |
} |
91 |
– |
catch( InterruptedException e ){ |
92 |
– |
System.out.println("Sleep interrupted"); |
93 |
– |
} |
94 |
– |
|
66 |
|
// increment sequence. |
67 |
|
sequence++; |
68 |
< |
lastCheck = System.currentTimeMillis(); |
68 |
> |
// lastCheck = System.currentTimeMillis(); |
69 |
|
|
70 |
|
// finally return a string |
71 |
|
return xml.returnXML(); |
79 |
|
|
80 |
|
private long lastCheck; |
81 |
|
private int sequence; |
111 |
– |
private long udpcheckInterval; |
112 |
– |
private final long defaultUpdateTime = 60000; |
82 |
|
|
83 |
|
//---STATIC ATTRIBUTES--- |
84 |
|
|
85 |
< |
} // class |
85 |
> |
} // class |