2 |
|
|
3 |
|
//---IMPORTS--- |
4 |
|
|
5 |
< |
import java.util.Random; |
5 |
> |
import java.io.*; |
6 |
> |
import java.net.*; |
7 |
> |
import java.util.*; |
8 |
|
|
9 |
|
/** |
10 |
|
* Gathers system information then outputs it as XML |
33 |
|
// like things to monitor |
34 |
|
|
35 |
|
lastCheck = System.currentTimeMillis(); |
36 |
< |
sequence = 0; |
36 |
> |
sequence = 1; |
37 |
|
|
38 |
|
|
39 |
|
// why oh why wont ultra edit let me put Long in the next line? oh its trying to |
59 |
|
*/ |
60 |
|
public String getInfo(){ |
61 |
|
// called to retrieve the stored averages and output them as a XML string |
62 |
< |
XMLFormatter xml = new XMLFormatter("packet"); |
62 |
> |
String host = new String(); |
63 |
> |
String ip = new String(); |
64 |
> |
try { |
65 |
> |
host = InetAddress.getLocalHost().getHostName(); |
66 |
> |
ip = InetAddress.getLocalHost().getHostAddress(); |
67 |
> |
} catch(UnknownHostException e) { |
68 |
> |
System.out.println(e); |
69 |
> |
} |
70 |
> |
String date = Long.toString(System.currentTimeMillis()); |
71 |
> |
XMLFormatter xml = new XMLFormatter("packet", "machine_name=\""+host+"\" ip=\""+ip+"\" date=\""+date+"\" seq_no=\""+sequence+"\""); |
72 |
> |
|
73 |
> |
// get and decode the data |
74 |
> |
DecodeCPU_TXT details = new DecodeCPU_TXT(); |
75 |
> |
|
76 |
> |
// add the decoded info |
77 |
> |
xml.addString(details.getItems()); |
78 |
|
|
62 |
– |
Random rand = new Random(); |
79 |
|
|
64 |
– |
// just send some dummy info for now. |
65 |
– |
xml.addNest("packet_info"); |
66 |
– |
String currentTime = Long.toString(System.currentTimeMillis()); |
67 |
– |
xml.addElement("date_time", currentTime ); |
68 |
– |
xml.addElement("sequence", Integer.toString(sequence)); |
69 |
– |
xml.closeNest(); |
70 |
– |
xml.addNest("core"); |
71 |
– |
xml.addElement("cpu",""+rand.nextInt(100)); |
72 |
– |
xml.addElement("memory",""+rand.nextInt(100)); |
73 |
– |
xml.closeNest(); |
74 |
– |
if ( rand.nextBoolean() ){ |
75 |
– |
xml.addNest("additional"); |
76 |
– |
xml.addElement("users",""+rand.nextInt(30)); |
77 |
– |
xml.closeNest(); |
78 |
– |
} |
80 |
|
// MUST FIX THIS..!!!! |
81 |
|
try { |
82 |
|
long updateIn = ( lastCheck + udpcheckInterval )-System.currentTimeMillis(); |