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.4 by ab11, Thu Nov 30 17:33:36 2000 UTC vs.
Revision 1.9 by ab11, Mon Mar 19 17:30:17 2001 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
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$
# Line 22 | Line 24 | class SystemMonitor {
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 ){
# Line 31 | Line 33 | class SystemMonitor {
33          // like things to monitor
34          
35          lastCheck = System.currentTimeMillis();
36 <        sequence = 0;
35 <
36 <
37 <        // why oh why wont ultra edit let me put Long in the next line? oh its trying to
38 <        // correct keywords =|
39 <        try {
40 <                udpcheckInterval = Long.parseLong(config.getProperty("UDPUpdateTime")) * 1000;
41 <        }
42 <        catch ( NumberFormatException e ){
43 <                System.out.println("The value for UDPUpdateTime is invalid, using a default");
44 <                // 5 mins
45 <                udpcheckInterval = 5000 * 60;
46 <        }
47 <        // make the check interval into seconds
36 >        sequence = 1;
37          
38      }
39  
# Line 57 | Line 46 | class SystemMonitor {
46      */
47      public String getInfo(){
48          // called to retrieve the stored averages and output them as a XML string
49 <        XMLFormatter xml = new XMLFormatter("packet");
50 <        
62 <        Random rand = new Random();
63 <        
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 <        }
79 <        // MUST FIX THIS..!!!!
49 >        String host = new String();
50 >        String ip = new String();
51          try {
52 <                long updateIn = ( lastCheck + udpcheckInterval )-System.currentTimeMillis();
53 <                if ( updateIn > 0 ){
54 <                        Thread.sleep(updateIn);
55 <                }
85 <                else
86 <                {
87 <                        Thread.sleep(defaultUpdateTime);
88 <                }
52 >            host = InetAddress.getLocalHost().getHostName();
53 >            ip = InetAddress.getLocalHost().getHostAddress();
54 >        } catch(UnknownHostException e) {
55 >            System.out.println(e);
56          }
57 <        catch( InterruptedException e ){
58 <                System.out.println("Sleep interrupted");
59 <        }
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();
62 >
63 >        // add the decoded info
64 >        xml.addString(details.getItems());
65          
66          // increment sequence.
67          sequence++;
68 <        lastCheck = System.currentTimeMillis();
68 >        // lastCheck = System.currentTimeMillis();
69                  
70          // finally return a string
71          return xml.returnXML();
# Line 107 | Line 79 | class SystemMonitor {
79  
80      private long lastCheck;
81      private int sequence;
110    private long udpcheckInterval;
111    private final long defaultUpdateTime = 60000;
82  
83   //---STATIC ATTRIBUTES---
84  
85 < } // class
85 > } // class

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines