3 |
|
//---IMPORTS--- |
4 |
|
|
5 |
|
import java.util.Random; |
6 |
+ |
import java.io.*; |
7 |
|
|
8 |
|
/** |
9 |
|
* Gathers system information then outputs it as XML |
60 |
|
// called to retrieve the stored averages and output them as a XML string |
61 |
|
XMLFormatter xml = new XMLFormatter("packet"); |
62 |
|
|
63 |
+ |
// the process to run |
64 |
+ |
try { |
65 |
+ |
Process proc = Runtime.getRuntime().exec("/usr/local/sbin/top -s1 -d2 0 > top.txt"); |
66 |
+ |
// this process will take atleast 2 seconds to complete |
67 |
+ |
try { |
68 |
+ |
proc.waitFor(); |
69 |
+ |
} |
70 |
+ |
catch ( InterruptedException e ){ |
71 |
+ |
|
72 |
+ |
} |
73 |
+ |
|
74 |
+ |
} |
75 |
+ |
catch ( IOException e ){ |
76 |
+ |
|
77 |
+ |
} |
78 |
+ |
|
79 |
+ |
|
80 |
+ |
|
81 |
+ |
// now do some text processing. |
82 |
+ |
DecodeCPU_TXT details = new DecodeCPU_TXT("top.txt"); |
83 |
+ |
|
84 |
+ |
|
85 |
|
Random rand = new Random(); |
86 |
|
|
87 |
|
// just send some dummy info for now. |
90 |
|
xml.addElement("date_time", currentTime ); |
91 |
|
xml.addElement("sequence", Integer.toString(sequence)); |
92 |
|
xml.closeNest(); |
93 |
< |
xml.addNest("core"); |
94 |
< |
xml.addElement("cpu",""+rand.nextInt(100)); |
95 |
< |
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 |
< |
} |
93 |
> |
xml.addString(details.getItems()); |
94 |
> |
|
95 |
> |
|
96 |
|
// MUST FIX THIS..!!!! |
97 |
|
try { |
98 |
|
long updateIn = ( lastCheck + udpcheckInterval )-System.currentTimeMillis(); |