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.14 by ajm, Mon Mar 5 12:45:51 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 35 | Line 35 | public class CPU__Monitor implements PluginMonitor {
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(source, _name, _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);
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 <                int result = checkAttributeThreshold(packet.getParam(_attributes[attributeNum]), reg);
48 <                
49 <                // decide what threshold level we're on, if we've changed, record that
50 <                if (result != reg.getLastThresholdLevel(attributeNum)) {
51 <                    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 <                            int lastAlert = reg.getLastAlertLevel(attributeNum);
58 <                            reg.escalateAlert(attributeNum);
59 <                            reg.setTimeLastSent(attributeNum, System.currentTimeMillis());
60 <                            reg.setLastAlertTimeout(attributeNum, reg.getAlertTimeout(reg.getLastAlertLevel(attributeNum), attributeNum));
61 <                            fireAlert(reg, lastAlert, packet, attributeNum);
62 <                        }
63 <                    // if we don't have a timeout configured...we got STRAIGHT to the next level
64 <                    } else {
65 <                        int lastAlert = reg.getLastAlertLevel(attributeNum);
66 <                        reg.escalateAlert(attributeNum);
67 <                        reg.setTimeLastSent(attributeNum, System.currentTimeMillis());
68 <                        reg.setLastAlertTimeout(attributeNum, reg.getAlertTimeout(reg.getLastAlertLevel(attributeNum), attributeNum));
69 <                        fireAlert(reg, lastAlert, packet, attributeNum);
70 <                    }
71 <                        
72 <                // we must be on ok, check the timeout value for this
73 <                } else {
74 <                    // if we were on an OK alert before, then we don't do anything
75 <                    // but if we weren't we only set OK, once the timout of the last
76 <                    // alert has occourd
77 <                    if (reg.getLastAlertLevel(attributeNum) != Alert.alertOK) {
78 <                        long timeout = reg.getLastAlertTimeout(attributeNum);
79 <                        if ((timeout > 0) && (reg.getTimeLastSent(attributeNum) > 0)) {
80 <                            if ((System.currentTimeMillis() - reg.getTimeLastSent(attributeNum)) > timeout) {
81 <                                int lastAlert = reg.getLastAlertLevel(attributeNum);
82 <                                reg.setLastAlertLevel(attributeNum, Alert.alertOK);
83 <                                reg.setTimeLastSent(attributeNum, System.currentTimeMillis());
84 <                                reg.setLastAlertTimeout(attributeNum, timeout);
85 <                                fireAlert(reg, lastAlert, packet, attributeNum);
86 <                            }
87 <                        }
88 <                    }
89 <                }
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      }
# Line 95 | 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 130 | Line 92 | public class CPU__Monitor implements PluginMonitor {
92                  }
93              }
94          }
95 <        return 0;
95 >        return Alert.thresholdNORMAL;
96      }
97  
98 <    private void fireAlert(Register reg, int lastAlert, XMLPacket packet, int attributeNum) {
99 <        int alertLevel = reg.getLastAlertLevel(attributeNum);
100 <        int thresholdLevel = reg.getLastThresholdLevel(attributeNum);
101 <        String source = packet.getParam("packet.attributes.machine_name");
140 <        String currentValue = packet.getParam(_attributes[attributeNum]);
141 <        String attributeName = _attributeNames[attributeNum];
142 <        String thresholdValue = Double.toString(reg.getThreshold(thresholdLevel));
143 <        String time = Long.toString(reg.getAlertTimeout(reg.getLastAlertLevel(attributeNum), attributeNum) / 1000);
144 <        if (thresholdLevel == Alert.thresholdNORMAL) {
145 <            thresholdValue = "-";
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          }
147        if (alertLevel == Alert.alertOK) {
148            time = "0";
149        }
150        Alert alert = new Alert(alertLevel, lastAlert, thresholdLevel, source, thresholdValue, currentValue, attributeName, time);
151        _alerterQueue.add(alert);
152        _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");
103      }
104  
105   //---ACCESSOR/MUTATOR METHODS---
# Line 166 | Line 116 | public class CPU__Monitor implements PluginMonitor {
116       * be changed to null for utility classes.
117       */
118      private String _name = "CPU";
169
170    /**
171     * This holds a reference to the
172     * system logger that is being used.
173     */
174    private Logger _logger = ReferenceManager.getInstance().getLogger();
175    
176    private Queue _alerterQueue = ClientMain._alerterQueue;
119      
120      /**
121       * A reference to the configuration proxy in use

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines