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.13 by ajm, Sun Mar 4 05:23:41 2001 UTC

# 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 >                int result = checkAttributeThreshold(packet.getParam(_attributes[attributeNum]), reg);
45 >                
46 >                // decide what threshold level we're on, if we've changed, record that
47 >                if (result != reg.getLastThresholdLevel(attributeNum)) {
48 >                    reg.setLastThresholdLevel(attributeNum, result);
49 >                }
50 >                // as long as this isn't a normal level
51 >                if(reg.getLastThresholdLevel(attributeNum) != Alert.thresholdNORMAL) {
52 >                    // if the time since the last alert is more than the time for
53 >                    // its timeout, fire an alert, escalate the alert
54 >                    long timeout = reg.getLastAlertTimeout(attributeNum);
55 >                    if ((timeout > 0) && (reg.getTimeLastSent(attributeNum) > 0)) {
56 >                        if((System.currentTimeMillis() - reg.getTimeLastSent(attributeNum)) > timeout) {
57 >                            reg.escalateAlert(attributeNum);
58 >                            reg.setTimeLastSent(attributeNum, System.currentTimeMillis());
59 >                            reg.setLastAlertTimeout(attributeNum, reg.getAlertTimeout(reg.getLastAlertLevel(attributeNum), attributeNum));
60 >                            fireAlert(reg, packet, attributeNum);
61 >                        }
62 >                    // if we don't have a timeout configured...we got STRAIGHT to the next level
63 >                    } else {
64 >                        reg.escalateAlert(attributeNum);
65 >                        reg.setTimeLastSent(attributeNum, System.currentTimeMillis());
66 >                        reg.setLastAlertTimeout(attributeNum, reg.getAlertTimeout(reg.getLastAlertLevel(attributeNum), attributeNum));
67 >                        fireAlert(reg, packet, attributeNum);
68 >                    }
69 >                        
70 >                // we must be on ok, check the timeout value for this
71 >                } else {
72 >                    // if we were on an OK alert before, then we don't do anything
73 >                    // but if we weren't we only set OK, once the timout of the last
74 >                    // alert has occourd
75 >                    if (reg.getLastAlertLevel(attributeNum) != Alert.alertOK) {
76 >                        long timeout = reg.getLastAlertTimeout(attributeNum);
77 >                        if ((timeout > 0) && (reg.getTimeLastSent(attributeNum) > 0)) {
78 >                            if ((System.currentTimeMillis() - reg.getTimeLastSent(attributeNum)) > timeout) {
79 >                                reg.setLastAlertLevel(attributeNum, Alert.alertOK);
80 >                                reg.setTimeLastSent(attributeNum, System.currentTimeMillis());
81 >                                reg.setLastAlertTimeout(attributeNum, timeout);
82 >                                fireAlert(reg, packet, attributeNum);
83 >                            }
84 >                        }
85 >                    }
86 >                }
87 >            }
88          }
89      }
90  
# Line 85 | Line 105 | public class CPU__Monitor implements PluginMonitor {
105      }
106  
107      /**
108 <     * return the String representation of what the filter does
108 >     * return the String representation of what the monitor does
109       */
110      public String getDescription(){
111          return DESC;
# Line 93 | Line 113 | public class CPU__Monitor implements PluginMonitor {
113  
114   //---PRIVATE METHODS---
115  
116 <    private int checkAttribute(XMLPacket packet, String packetAttribute) {
117 <        for(int x= _levels.length; x > 0; x--) {
118 <            if (_levels[x] != -1) {
119 <                if(packet.getParam(packetAttribute) != null) {
120 <                    double attribute = Double.parseDouble(packet.getParam(packetAttribute));
121 <                    if (_levels[x] < attribute) return x;
116 >    private int checkAttributeThreshold(String attributeString, Register reg) {
117 >        for(int thresholdLevel = Alert.thresholdLevels.length - 1; thresholdLevel >= 0; thresholdLevel--) {
118 >            if (reg.getThreshold(thresholdLevel) != -1.0) {
119 >                if(attributeString != null) {
120 >                    try {
121 >                        double attribute = Double.parseDouble(attributeString);
122 >                        if (reg.getThreshold(thresholdLevel) < attribute) return thresholdLevel;
123 >                    } catch (NumberFormatException e) {
124 >                        // we got some duff data in the packet, but we shouldn't have
125 >                        _logger.write(toString(), Logger.DEBUG, "possible errenous packet data, should be double value - " + attributeString);
126 >                    }
127                  }
128              }
129          }
130          return 0;
131      }
132  
133 <    private void fireAlert(int alertLevel, String source, String currentValue, String attributeName) {
134 <        String thresholdValue = Double.toString(_levels[alertLevel]);
135 <        Alert alert = new Alert(alertLevel, source, thresholdValue, currentValue, attributeName);
133 >    private void fireAlert(Register reg, XMLPacket packet, int attributeNum) {
134 >        int alertLevel = reg.getLastAlertLevel(attributeNum);
135 >        int thresholdLevel = reg.getLastThresholdLevel(attributeNum);
136 >        String source = packet.getParam("packet.attributes.machine_name");
137 >        String currentValue = packet.getParam(_attributes[attributeNum]);
138 >        String attributeName = _attributeNames[attributeNum];
139 >        String thresholdValue = Double.toString(reg.getThreshold(thresholdLevel));
140 >        String time = Long.toString(reg.getAlertTimeout(reg.getLastAlertLevel(attributeNum), attributeNum) / 1000);
141 >        if (thresholdLevel == Alert.thresholdNORMAL) {
142 >            thresholdValue = "-";
143 >        }
144 >        if (alertLevel == Alert.alertOK) {
145 >            time = "0";
146 >        }
147 >        Alert alert = new Alert(alertLevel, thresholdLevel, source, thresholdValue, currentValue, attributeName, time);
148          _alerterQueue.add(alert);
149 <        _logger.write(toString(), Logger.DEBUG, "Fired alert for source:" + source + " at alert level:" + alertLevel + " on:" + attributeName + " at:" +  currentValue + " exceeding threshold:" + _levels[alertLevel]);
149 >        _logger.write(toString(), Logger.DEBUG, "Fired alert for source:" + source + " at alert level:" + Alert.alertLevels[alertLevel] + " on:" + attributeName + " for threshold level:" + Alert.thresholdLevels[thresholdLevel] + " at:" +  currentValue + " exceeding threshold of:" +thresholdValue + " next alert sent in:" + time + "secs");
150      }
151  
152   //---ACCESSOR/MUTATOR METHODS---
# Line 125 | Line 162 | public class CPU__Monitor implements PluginMonitor {
162       * can be placed here.  This name could also
163       * be changed to null for utility classes.
164       */
165 <    private String _name = ClientMain.NAME;
165 >    private String _name = "CPU";
166  
167      /**
168       * This holds a reference to the
# Line 133 | Line 170 | public class CPU__Monitor implements PluginMonitor {
170       */
171      private Logger _logger = ReferenceManager.getInstance().getLogger();
172      
173 <    private double[] _levels;
137 <
138 <    private Queue _alerterQueue;
173 >    private Queue _alerterQueue = ClientMain._alerterQueue;
174      
175      /**
176 <     * A reference to the reference manager in use
176 >     * A reference to the configuration proxy in use
177       */
178 <    private ReferenceManager _refman = ReferenceManager.getInstance();
178 >    private ConfigurationProxy _cp = ConfigurationProxy.getInstance();
179  
180      private HashMap _hosts = new HashMap();
181  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines