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.1 by ab11, Mon Nov 27 19:44:32 2000 UTC vs.
Revision 1.9 by ab11, Mon Mar 19 17:30:17 2001 UTC

# Line 1 | Line 1
1 + //---PACKAGE DECLARATION---
2 +
3 + //---IMPORTS---
4 +
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
12 + * configurator then packages these up using XMLFormatter
13 + * and outputs them if the timeout has passed.
14 + *
15 + * @author  $Author$
16 + * @version $Id$
17 + */
18   class SystemMonitor {
19  
20 <        public SystemMonitor( Config config ){
4 <                // create a new instace, get the info we need out of config
5 <                // like things to monitor
6 <                
7 <                lastCheck = System.currentTimeMillis();
8 <                sequence = 0;
20 > //---FINAL ATTRIBUTES---
21  
22 + //---STATIC METHODS---
23  
24 <                // why oh why wont ultra edit let me put Long in the next line? oh its trying to
12 <                // correct keywords =|
13 <                checkInterval = Long.parseLong(config.getProperty("UDPINTEVAL"));
14 <                
15 <        }
24 > //---CONSTRUCTORS---
25  
26 <        public String getInfo(){
27 <                // called to retrieve the stored averages and output them as a XML string
28 <                XMLFormatter xml = new XMLFormatter("packet");
29 <                
30 <                // just send some dummy info for now.
31 <                xml.addNest("packet_info");
32 <                    String currentTime = Long.toString(System.currentTimeMillis());
33 <                    xml.addElement("date_time", currentTime );
34 <                    xml.addElement("sequence", Integer.toString(sequence));
35 <                xml.closeNest();
36 <                xml.addNest("core");
37 <                    xml.addElement("cpu","100");
38 <                    xml.addElement("memory","200");
30 <                xml.closeNest();
31 <                xml.addNest("additional");
32 <                    xml.addElement("users","20");
33 <                xml.closeNest();
34 <                
35 <                // MUST FIX THIS..!!!!
36 <                while ( System.currentTimeMillis() < ( lastCheck + checkInterval ) ){
37 <                  // errm do nothing.. block or something.          
38 <                }
39 <                
40 <                // increment sequence.
41 <                sequence++;
42 <                                
43 <                // finally return a string
44 <                return xml.returnXML();
45 <        } // getinfo()
26 > /**
27 > * Public constructor for the class. Takes in a Config
28 > * object to gain its properties from.
29 > *
30 > */  
31 > public SystemMonitor( Config config ){
32 >        // create a new instace, get the info we need out of config
33 >        // like things to monitor
34 >        
35 >        lastCheck = System.currentTimeMillis();
36 >        sequence = 1;
37 >        
38 >    }
39  
40 <    // last time the system data was returned.
40 > //---PUBLIC METHODS---
41 >
42 >   /**
43 >    * Gathers system information and will black until the timeout has passed.
44 >    *
45 >    * @return the system information in an XML packet
46 >    */
47 >    public String getInfo(){
48 >        // called to retrieve the stored averages and output them as a XML string
49 >        String host = new String();
50 >        String ip = new String();
51 >        try {
52 >            host = InetAddress.getLocalHost().getHostName();
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+"\" 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();
69 >                
70 >        // finally return a string
71 >        return xml.returnXML();
72 >    } // getinfo()
73 >    
74 > //---PRIVATE METHODS---
75 >
76 > //---ACCESSOR/MUTATOR METHODS---
77 >
78 > //---ATTRIBUTES---
79 >
80      private long lastCheck;
81      private int sequence;
82 <    private long checkInterval;
82 >
83 > //---STATIC ATTRIBUTES---
84  
85 < } // class
85 > } // class

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines