ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/java/SystemMonitor.java
(Generate patch)

Comparing projects/cms/source/host/java/SystemMonitor.java (file contents):
Revision 1.3 by ab11, Thu Nov 30 04:11:00 2000 UTC vs.
Revision 1.6 by tdb, Thu Dec 7 23:21:13 2000 UTC

# Line 2 | Line 2
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
# Line 31 | Line 33 | class SystemMonitor {
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
40          // correct keywords =|
41 <        checkInterval = Long.parseLong(config.getProperty("UDPUpdateTime")) * 1000;
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
50          
51      }
# Line 50 | Line 59 | class SystemMonitor {
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          
55        Random rand = new Random();
79          
57        // just send some dummy info for now.
58        xml.addNest("packet_info");
59            String currentTime = Long.toString(System.currentTimeMillis());
60            xml.addElement("date_time", currentTime );
61            xml.addElement("sequence", Integer.toString(sequence));
62        xml.closeNest();
63        xml.addNest("core");
64            xml.addElement("cpu",""+rand.nextInt(100));
65            xml.addElement("memory",""+rand.nextInt(100));
66        xml.closeNest();
67        if ( rand.nextBoolean() ){
68                xml.addNest("additional");
69                    xml.addElement("users",""+rand.nextInt(30));
70                xml.closeNest();
71        }
80          // MUST FIX THIS..!!!!
81          try {
82 <                Thread.sleep(( lastCheck + checkInterval )-System.currentTimeMillis());
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");
# Line 93 | Line 108 | class SystemMonitor {
108  
109      private long lastCheck;
110      private int sequence;
111 <    private long checkInterval;
111 >    private long udpcheckInterval;
112 >    private final long defaultUpdateTime = 60000;
113  
114   //---STATIC ATTRIBUTES---
115  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines