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.9 by ajm, Fri Mar 2 03:57:06 2001 UTC vs.
Revision 1.17 by ajm, Tue Mar 6 23:44:08 2001 UTC

# 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 >                _hosts.put(source, new Register(source, _name, _attributes.length));
39              }
40              
41              Register reg = (Register) _hosts.get(source);
42 <            for(int x = 0; x < _attributes.length; x++) {
43 <                int result = checkAttribute(packet, _attributes[x]);
44 <                if (result != reg.getRegister(x)) {
45 <                    reg.setRegister(x, result);
46 <                    fireAlert(result, source, packet.getParam(_attributes[x]), _attributeNames[x]);
47 <                }
48 <            }          
42 >            for(int attributeNum = 0; attributeNum < _attributes.length; attributeNum++) {
43 >                // find out the threshold level we're at
44 >                String attribute = _attributes[attributeNum];
45 >                String attributeName = _attributeNames[attributeNum];
46 >                String currentValue = packet.getParam(attribute);
47 >                int newThreshold = checkAttributeThreshold(currentValue, reg);
48 >                processAlert(newThreshold, attributeNum, attributeName, reg, source, currentValue);
49 >            }
50          }
51      }
52  
# Line 85 | Line 67 | public class CPU__Monitor implements PluginMonitor {
67      }
68  
69      /**
70 <     * return the String representation of what the filter does
70 >     * return the String representation of what the monitor does
71       */
72      public String getDescription(){
73          return DESC;
# Line 93 | Line 75 | public class CPU__Monitor implements PluginMonitor {
75  
76   //---PRIVATE METHODS---
77  
78 <    private int checkAttribute(XMLPacket packet, String packetAttribute) {
79 <        for(int x= _levels.length; x > 0; x--) {
80 <            if (_levels[x] != -1) {
81 <                if(packet.getParam(packetAttribute) != null) {
82 <                    double attribute = Double.parseDouble(packet.getParam(packetAttribute));
83 <                    if (_levels[x] < attribute) return x;
78 >    private int checkAttributeThreshold(String attributeString, Register reg) {
79 >        for(int thresholdLevel = Alert.thresholdLevels.length - 1; thresholdLevel >= 0; thresholdLevel--) {
80 >            if (reg.getThreshold(thresholdLevel) != -1.0) {
81 >                if(attributeString != null) {
82 >                    try {
83 >                        double attribute = Double.parseDouble(attributeString);
84 >                        if (reg.getThreshold(thresholdLevel) < attribute) return thresholdLevel;
85 >                    } catch (NumberFormatException e) {
86 >                        // we got some duff data in the packet, but we shouldn't have
87 >                        _logger.write(toString(), Logger.DEBUG, "possible errenous packet data, should be double value - " + attributeString);
88 >                    }
89                  }
90              }
91          }
92 <        return 0;
92 >        return Alert.thresholdNORMAL;
93      }
94  
108    private void fireAlert(int alertLevel, String source, String currentValue, String attributeName) {
109        String thresholdValue = Double.toString(_levels[alertLevel]);
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:" + attributeName + " at:" +  currentValue + " exceeding threshold:" + _levels[alertLevel]);
113    }
114
95   //---ACCESSOR/MUTATOR METHODS---
96  
97   //---ATTRIBUTES---
# Line 125 | Line 105 | public class CPU__Monitor implements PluginMonitor {
105       * can be placed here.  This name could also
106       * be changed to null for utility classes.
107       */
108 <    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();
108 >    private String _name = "CPU";
109      
136    private double[] _levels;
137
138    private Queue _alerterQueue;
139    
110      /**
111 <     * A reference to the reference manager in use
111 >     * A reference to the configuration proxy in use
112       */
113 <    private ReferenceManager _refman = ReferenceManager.getInstance();
113 >    private ConfigurationProxy _cp = ConfigurationProxy.getInstance();
114  
115      private HashMap _hosts = new HashMap();
116  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines