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.1 by tdb, Tue Feb 27 01:03:28 2001 UTC vs.
Revision 1.5 by ajm, Fri Mar 2 01:05:53 2001 UTC

# Line 28 | Line 28 | public class CPU__Monitor implements Monitor {
28  
29   //---CONSTRUCTORS---
30  
31 +    public CPU__Monitor() {
32 +        _alerterQueue = ClientMain._alerterQueue;
33 +        // get the configuration for this plug-in
34 +        Configuration config = _refman.getCM().getConfiguration(_name);
35 +        _levels = new double[(Alert.alerts).length];
36 +        for (int x = 0; x < Alert.alerts.length; x++) {
37 +            try {
38 +                _levels[x] = Double.parseDouble(config.getProperty("Monitor.CPU.level." + x));
39 +            } catch (NumberFormatException e) {
40 +                _logger.write(toString(), Logger.ERROR, "Invalid configured value for alert level " + x + " - ignoring level.");
41 +                _levels[x] = -1;
42 +            } catch (org.omg.CORBA.MARSHAL e2) {
43 +                _logger.write(toString(), Logger.WARNING, "Alert level " + x + " unused.");
44 +                _levels[x] = -1;
45 +            }
46 +            
47 +        }
48 +    }
49   //---PUBLIC METHODS---
50  
51      public void analysePacket(XMLPacket packet) {
52 <        // yeah, now what ?
52 >        String source = packet.getParam("packet.attributes.hostname");
53 >        for(int x=0; x < _levels.length; x++) {
54 >            if (_levels[x] != -1) {
55 >                double idle = Double.parseDouble(packet.getParam("packet.cpu.idle"));
56 >                if (_levels[x] < idle) fireAlert(x, source, idle, "idle");
57 >                double user = Double.parseDouble(packet.getParam("packet.cpu.user"));
58 >                if (_levels[x] < user) fireAlert(x, source, user, "user");
59 >                double kernel = Double.parseDouble(packet.getParam("packet.cpu.kernel"));
60 >                if (_levels[x] < kernel) fireAlert(x, source, kernel, "kernel");
61 >                double iowait = Double.parseDouble(packet.getParam("packet.cpu.iowait"));
62 >                if (_levels[x] < iowait) fireAlert(x, source, iowait, "iowait");
63 >                double swap = Double.parseDouble(packet.getParam("packet.cpu.swap"));
64 >                if (_levels[x] < swap) fireAlert(x, source, swap, "swap");
65 >            }
66 >        }
67      }
68  
69      /**
# Line 59 | Line 91 | public class CPU__Monitor implements Monitor {
91  
92   //---PRIVATE METHODS---
93  
94 +    private void fireAlert(int alertLevel, String source, double currentValue, String type) {
95 +        String value = Double.toString(currentValue);
96 +        String thresholdValue = Double.toString(_levels[alertLevel]);
97 +        String attributeName = "CPU " + type;
98 +        Alert alert = new Alert(alertLevel, source, thresholdValue, value, attributeName);
99 +        _alerterQueue.add(alert);
100 +    }
101 +
102   //---ACCESSOR/MUTATOR METHODS---
103  
104   //---ATTRIBUTES---
# Line 79 | Line 119 | public class CPU__Monitor implements Monitor {
119       * system logger that is being used.
120       */
121      private Logger _logger = ReferenceManager.getInstance().getLogger();
122 +    
123 +    private double[] _levels;
124 +
125 +    private Queue _alerterQueue;
126 +    
127 +    /**
128 +     * A reference to the reference manager in use
129 +     */
130 +    private ReferenceManager _refman = ReferenceManager.getInstance();
131  
132   //---STATIC ATTRIBUTES---
133  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines