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.2 by ab11, Mon Nov 27 20:36:30 2000 UTC vs.
Revision 1.5 by ab11, Thu Dec 7 18:25:37 2000 UTC

# Line 2 | Line 2
2  
3   //---IMPORTS---
4  
5 + import java.util.Random;
6 + import java.io.*;
7 +
8   /**
9   * Gathers system information then outputs it as XML
10   * Collects data based on properties gained from the configurator
# Line 34 | Line 37 | class SystemMonitor {
37  
38          // why oh why wont ultra edit let me put Long in the next line? oh its trying to
39          // correct keywords =|
40 <        checkInterval = Long.parseLong(config.getProperty("UDPINTEVAL"));
40 >        try {
41 >                udpcheckInterval = Long.parseLong(config.getProperty("UDPUpdateTime")) * 1000;
42 >        }
43 >        catch ( NumberFormatException e ){
44 >                System.out.println("The value for UDPUpdateTime is invalid, using a default");
45 >                // 5 mins
46 >                udpcheckInterval = 5000 * 60;
47 >        }
48 >        // make the check interval into seconds
49          
50      }
51  
# Line 49 | Line 60 | class SystemMonitor {
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.
88          xml.addNest("packet_info");
89              String currentTime = Long.toString(System.currentTimeMillis());
90              xml.addElement("date_time", currentTime );
91              xml.addElement("sequence", Integer.toString(sequence));
92          xml.closeNest();
93 <        xml.addNest("core");
59 <            xml.addElement("cpu","100");
60 <            xml.addElement("memory","200");
61 <        xml.closeNest();
62 <        xml.addNest("additional");
63 <            xml.addElement("users","20");
64 <        xml.closeNest();
93 >        xml.addString(details.getItems());
94          
95 +        
96          // MUST FIX THIS..!!!!
97 <        while ( System.currentTimeMillis() < ( lastCheck + checkInterval ) ){
98 <          // errm do nothing.. block or something.      
97 >        try {
98 >                long updateIn = ( lastCheck + udpcheckInterval )-System.currentTimeMillis();
99 >                if ( updateIn > 0 ){
100 >                        Thread.sleep(updateIn);
101 >                }
102 >                else
103 >                {
104 >                        Thread.sleep(defaultUpdateTime);
105 >                }
106          }
107 +        catch( InterruptedException e ){
108 +                System.out.println("Sleep interrupted");
109 +        }
110          
111          // increment sequence.
112          sequence++;
113 +        lastCheck = System.currentTimeMillis();
114                  
115          // finally return a string
116          return xml.returnXML();
# Line 83 | Line 124 | class SystemMonitor {
124  
125      private long lastCheck;
126      private int sequence;
127 <    private long checkInterval;
127 >    private long udpcheckInterval;
128 >    private final long defaultUpdateTime = 60000;
129  
130   //---STATIC ATTRIBUTES---
131  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines