ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/client/monitors/CPU__Monitor.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/client/monitors/CPU__Monitor.java (file contents):
Revision 1.7 by ajm, Fri Mar 2 01:31:01 2001 UTC vs.
Revision 1.9 by ajm, Fri Mar 2 03:57:06 2001 UTC

# Line 2 | Line 2
2   package uk.ac.ukc.iscream.client.monitors;
3  
4   //---IMPORTS---
5 + import java.util.HashMap;
6   import uk.ac.ukc.iscream.client.*;
7   import uk.ac.ukc.iscream.core.*;
8   import uk.ac.ukc.iscream.util.*;
# Line 46 | Line 47 | public class CPU__Monitor implements PluginMonitor {
47              
48          }
49      }
50 +
51   //---PUBLIC METHODS---
52  
53      public void analysePacket(XMLPacket packet) {
54          if (packet.getParam("packet.attributes.type").equals("data")) {
55 <            String source = packet.getParam("packet.attributes.hostname");
56 <            for(int x=0; x < _levels.length; x++) {
57 <                if (_levels[x] != -1) {
56 <                    double idle = Double.parseDouble(packet.getParam("packet.cpu.idle"));
57 <                    if (_levels[x] < idle) fireAlert(x, source, idle, "idle");
58 <                    double user = Double.parseDouble(packet.getParam("packet.cpu.user"));
59 <                    if (_levels[x] < user) fireAlert(x, source, user, "user");
60 <                    double kernel = Double.parseDouble(packet.getParam("packet.cpu.kernel"));
61 <                    if (_levels[x] < kernel) fireAlert(x, source, kernel, "kernel");
62 <                    double iowait = Double.parseDouble(packet.getParam("packet.cpu.iowait"));
63 <                    if (_levels[x] < iowait) fireAlert(x, source, iowait, "iowait");
64 <                    double swap = Double.parseDouble(packet.getParam("packet.cpu.swap"));
65 <                    if (_levels[x] < swap) fireAlert(x, source, swap, "swap");
66 <                }
55 >            String source = packet.getParam("packet.attributes.machine_name");
56 >            if (!_hosts.containsKey(source)) {
57 >                _hosts.put(source, new Register(_attributes.length));
58              }
59 +            
60 +            Register reg = (Register) _hosts.get(source);
61 +            for(int x = 0; x < _attributes.length; x++) {
62 +                int result = checkAttribute(packet, _attributes[x]);
63 +                if (result != reg.getRegister(x)) {
64 +                    reg.setRegister(x, result);
65 +                    fireAlert(result, source, packet.getParam(_attributes[x]), _attributeNames[x]);
66 +                }
67 +            }          
68          }
69      }
70  
# Line 93 | Line 93 | public class CPU__Monitor implements PluginMonitor {
93  
94   //---PRIVATE METHODS---
95  
96 <    private void fireAlert(int alertLevel, String source, double currentValue, String type) {
97 <        String value = Double.toString(currentValue);
96 >    private int checkAttribute(XMLPacket packet, String packetAttribute) {
97 >        for(int x= _levels.length; x > 0; x--) {
98 >            if (_levels[x] != -1) {
99 >                if(packet.getParam(packetAttribute) != null) {
100 >                    double attribute = Double.parseDouble(packet.getParam(packetAttribute));
101 >                    if (_levels[x] < attribute) return x;
102 >                }
103 >            }
104 >        }
105 >        return 0;
106 >    }
107 >
108 >    private void fireAlert(int alertLevel, String source, String currentValue, String attributeName) {
109          String thresholdValue = Double.toString(_levels[alertLevel]);
110 <        String attributeName = "CPU " + type;
100 <        Alert alert = new Alert(alertLevel, source, thresholdValue, value, attributeName);
110 >        Alert alert = new Alert(alertLevel, source, thresholdValue, currentValue, attributeName);
111          _alerterQueue.add(alert);
112 <        _logger.write(toString(), Logger.DEBUG, "Fired alert for source:" + source + " at alert level:" + alertLevel + " on:" + type + " at:" +  currentValue + " exceeding threshold:" + _levels[alertLevel]);
112 >        _logger.write(toString(), Logger.DEBUG, "Fired alert for source:" + source + " at alert level:" + alertLevel + " on:" + attributeName + " at:" +  currentValue + " exceeding threshold:" + _levels[alertLevel]);
113      }
114  
115   //---ACCESSOR/MUTATOR METHODS---
# Line 131 | Line 141 | public class CPU__Monitor implements PluginMonitor {
141       * A reference to the reference manager in use
142       */
143      private ReferenceManager _refman = ReferenceManager.getInstance();
144 +
145 +    private HashMap _hosts = new HashMap();
146 +
147 +    private String[] _attributes = { "packet.cpu.user", "packet.cpu.kernel", "packet.cpu.iowait", "packet.cpu.swap" };
148 +    private String[] _attributeNames = {"User CPU", "Kernel CPU", "I/O Wait CPU", "Swap CPU"};
149  
150   //---STATIC ATTRIBUTES---
151  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines