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.10 by ajm, Fri Mar 2 03:59:25 2001 UTC vs.
Revision 1.21 by tdb, Thu Mar 22 00:52:48 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.ac.ukc.iscream.client.monitors;
2 > package uk.org.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.*;
9 < import uk.ac.ukc.iscream.componentmanager.*;
6 > import uk.org.iscream.client.*;
7 > import uk.org.iscream.core.*;
8 > import uk.org.iscream.util.*;
9 > import uk.org.iscream.componentmanager.*;
10  
11   /**
12   * This Monitor watches the CPU load for all machines
# Line 14 | Line 14 | import uk.ac.ukc.iscream.componentmanager.*;
14   * @author  $Author$
15   * @version $Id$
16   */
17 < public class CPU__Monitor implements PluginMonitor {
17 > public class CPU__Monitor extends MonitorSkeleton {
18  
19   //---FINAL ATTRIBUTES---
20  
# Line 29 | Line 29 | public class CPU__Monitor implements PluginMonitor {
29  
30   //---CONSTRUCTORS---
31  
32    public CPU__Monitor() {
33        _alerterQueue = ClientMain._alerterQueue;
34        // get the configuration for this plug-in
35        Configuration config = _refman.getCM().getConfiguration(_name);
36        _levels = new double[(Alert.alerts).length];
37        for (int x = 0; x < Alert.alerts.length; x++) {
38            try {
39                _levels[x] = Double.parseDouble(config.getProperty("Monitor.CPU.level." + x));
40            } catch (NumberFormatException e) {
41                _logger.write(toString(), Logger.ERROR, "Invalid configured value for alert level " + x + " - ignoring level.");
42                _levels[x] = -1;
43            } catch (org.omg.CORBA.MARSHAL e2) {
44                _logger.write(toString(), Logger.WARNING, "Alert level " + x + " unused.");
45                _levels[x] = -1;
46            }
47            
48        }
49    }
50
32   //---PUBLIC METHODS---
33  
34      public void analysePacket(XMLPacket packet) {
35          if (packet.getParam("packet.attributes.type").equals("data")) {
36              String source = packet.getParam("packet.attributes.machine_name");
37              if (!_hosts.containsKey(source)) {
38 <                _hosts.put(source, new Register(_attributes.length));
38 >                HashMap attributeRegisters = new HashMap();
39 >                initAttributeRegsiters(source, attributeRegisters);
40 >                _hosts.put(source, attributeRegisters);
41              }
42 <            
43 <            Register reg = (Register) _hosts.get(source);
44 <            for(int x = 0; x < _attributes.length; x++) {
45 <                int result = checkAttribute(packet, _attributes[x]);
46 <                if (result != reg.getRegister(x)) {
47 <                    reg.setRegister(x, result);
48 <                    fireAlert(result, source, packet.getParam(_attributes[x]), _attributeNames[x]);
49 <                }
50 <            }          
42 >
43 >            HashMap attributeRegisters = (HashMap) _hosts.get(source);
44 >            for(int attributeNum = 0; attributeNum < _attributes.length; attributeNum++) {
45 >                Register reg = (Register) attributeRegisters.get(_attributes[attributeNum]);
46 >                // find out the threshold level we're at
47 >                String attribute = _attributes[attributeNum];
48 >                String attributeName = _attributeNames[attributeNum];
49 >                String currentValue = packet.getParam(attribute);
50 >                int newThreshold = checkAttributeThreshold(currentValue, reg);
51 >                processAlert(newThreshold, attributeName, reg, source, currentValue);
52 >            }
53          }
54      }
55  
# Line 72 | Line 57 | public class CPU__Monitor implements PluginMonitor {
57       * Overrides the {@link java.lang.Object#toString() Object.toString()}
58       * method to provide clean logging (every class should have this).
59       *
60 <     * This uses the uk.ac.ukc.iscream.util.NameFormat class
60 >     * This uses the uk.org.iscream.util.NameFormat class
61       * to format the toString()
62       *
63       * @return the name of this class and its CVS revision
# Line 85 | Line 70 | public class CPU__Monitor implements PluginMonitor {
70      }
71  
72      /**
73 <     * return the String representation of what the filter does
73 >     * return the String representation of what the monitor does
74       */
75      public String getDescription(){
76          return DESC;
# Line 93 | Line 78 | public class CPU__Monitor implements PluginMonitor {
78  
79   //---PRIVATE METHODS---
80  
81 <    private int checkAttribute(XMLPacket packet, String packetAttribute) {
82 <        for(int x = _levels.length - 1; x >= 0; x--) {
83 <            if (_levels[x] != -1) {
84 <                if(packet.getParam(packetAttribute) != null) {
85 <                    double attribute = Double.parseDouble(packet.getParam(packetAttribute));
86 <                    if (_levels[x] < attribute) return x;
81 >    private int checkAttributeThreshold(String attributeString, Register reg) {
82 >        for(int thresholdLevel = Alert.thresholdLevels.length - 1; thresholdLevel >= 0; thresholdLevel--) {
83 >            if (reg.getThreshold(thresholdLevel) != -1.0) {
84 >                if(attributeString != null) {
85 >                    try {
86 >                        double attribute = Double.parseDouble(attributeString);
87 >                        if (reg.getThreshold(thresholdLevel) < attribute) return thresholdLevel;
88 >                    } catch (NumberFormatException e) {
89 >                        // we got some duff data in the packet, but we shouldn't have
90 >                        _logger.write(toString(), Logger.DEBUG, "possible errenous packet data, should be double value - " + attributeString);
91 >                    }
92                  }
93              }
94          }
95 <        return 0;
95 >        return Alert.thresholdNORMAL;
96      }
97  
98 <    private void fireAlert(int alertLevel, String source, String currentValue, String attributeName) {
99 <        String thresholdValue = Double.toString(_levels[alertLevel]);
100 <        Alert alert = new Alert(alertLevel, source, thresholdValue, currentValue, attributeName);
101 <        _alerterQueue.add(alert);
102 <        _logger.write(toString(), Logger.DEBUG, "Fired alert for source:" + source + " at alert level:" + alertLevel + " on:" + attributeName + " at:" +  currentValue + " exceeding threshold:" + _levels[alertLevel]);
98 >    private void initAttributeRegsiters(String source, HashMap attributeRegisters) {
99 >        for(int attributeNum = 0; attributeNum < _attributes.length; attributeNum++) {
100 >            String attributeName = _attributes[attributeNum].substring(_attributes[attributeNum].lastIndexOf(".") + 1);
101 >            attributeRegisters.put(_attributes[attributeNum], new Register(source, _name, attributeName));
102 >        }
103      }
104  
105   //---ACCESSOR/MUTATOR METHODS---
# Line 125 | Line 115 | public class CPU__Monitor implements PluginMonitor {
115       * can be placed here.  This name could also
116       * be changed to null for utility classes.
117       */
118 <    private String _name = ClientMain.NAME;
129 <
130 <    /**
131 <     * This holds a reference to the
132 <     * system logger that is being used.
133 <     */
134 <    private Logger _logger = ReferenceManager.getInstance().getLogger();
118 >    private String _name = "CPU";
119      
136    private double[] _levels;
137
138    private Queue _alerterQueue;
139    
120      /**
121 <     * A reference to the reference manager in use
121 >     * A reference to the configuration proxy in use
122       */
123 <    private ReferenceManager _refman = ReferenceManager.getInstance();
123 >    private ConfigurationProxy _cp = ConfigurationProxy.getInstance();
124  
125      private HashMap _hosts = new HashMap();
126  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines