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/Load__Monitor.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/client/monitors/Load__Monitor.java (file contents):
Revision 1.1 by tdb, Thu Mar 22 00:52:48 2001 UTC vs.
Revision 1.4 by tdb, Tue May 29 17:02:34 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.org.iscream.client.monitors;
2 > package uk.org.iscream.cms.server.client.monitors;
3  
4   //---IMPORTS---
5   import java.util.HashMap;
6 < import uk.org.iscream.client.*;
7 < import uk.org.iscream.core.*;
8 < import uk.org.iscream.util.*;
9 < import uk.org.iscream.componentmanager.*;
6 > import uk.org.iscream.cms.server.client.*;
7 > import uk.org.iscream.cms.server.core.*;
8 > import uk.org.iscream.cms.server.util.*;
9 > import uk.org.iscream.cms.server.componentmanager.*;
10  
11   /**
12   * This Monitor watches the Load for all machines
# Line 23 | Line 23 | public class Load__Monitor extends MonitorSkeleton {
23       */
24      public final String REVISION = "$Revision$";
25      
26 +    /**
27 +     * A description of this monitor
28 +     */
29      public final String DESC = "Monitors Load.";
30      
31   //---STATIC METHODS---
# Line 30 | Line 33 | public class Load__Monitor extends MonitorSkeleton {
33   //---CONSTRUCTORS---
34  
35   //---PUBLIC METHODS---
36 <
36 >    
37 >    /**
38 >     * Analyse a packet of data, and generate an alert if
39 >     * necessary.
40 >     *
41 >     * @param packet the XMLPacket to analyse
42 >     */
43      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                HashMap attributeRegisters = new HashMap();
39                initAttributeRegsiters(source, attributeRegisters);
40                _hosts.put(source, attributeRegisters);
41            }
44  
45 <            HashMap attributeRegisters = (HashMap) _hosts.get(source);
46 <            for(int attributeNum = 0; attributeNum < _attributes.length; attributeNum++) {
47 <                Register reg = (Register) attributeRegisters.get(_attributes[attributeNum]);
48 <                // find out the threshold level we're at
49 <                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 <            }
45 >        String source = packet.getParam("packet.attributes.machine_name");
46 >        if (!_hosts.containsKey(source)) {
47 >            HashMap attributeRegisters = new HashMap();
48 >            initAttributeRegsiters(source, attributeRegisters);
49 >            _hosts.put(source, attributeRegisters);
50          }
51 +
52 +        HashMap attributeRegisters = (HashMap) _hosts.get(source);
53 +        for(int attributeNum = 0; attributeNum < _attributes.length; attributeNum++) {
54 +            Register reg = (Register) attributeRegisters.get(_attributes[attributeNum]);
55 +            // find out the threshold level we're at
56 +            String attribute = _attributes[attributeNum];
57 +            String attributeName = _attributeNames[attributeNum];
58 +            String currentValue = packet.getParam(attribute);
59 +            // find out our new threshold
60 +            int newThreshold = checkAttributeThreshold(currentValue, reg);
61 +            // process this data to generate an alert
62 +            processAlert(newThreshold, attributeName, reg, source, currentValue);
63 +        }
64 +
65      }
66  
67      /**
68       * Overrides the {@link java.lang.Object#toString() Object.toString()}
69       * method to provide clean logging (every class should have this).
70       *
71 <     * This uses the uk.org.iscream.util.NameFormat class
71 >     * This uses the uk.org.iscream.cms.server.util.NameFormat class
72       * to format the toString()
73       *
74       * @return the name of this class and its CVS revision
# Line 77 | Line 88 | public class Load__Monitor extends MonitorSkeleton {
88      }
89  
90   //---PRIVATE METHODS---
91 <
91 >    
92 >    /**
93 >     * Checks a piece of current data, and returns the
94 >     * threshold it breaches, if any.
95 >     *
96 >     * @param attributeString a String representing the current data value
97 >     * @param reg the Register for the host
98 >     * @return the threshold level breached, if any
99 >     */
100      private int checkAttributeThreshold(String attributeString, Register reg) {
101          for(int thresholdLevel = Alert.thresholdLevels.length - 1; thresholdLevel >= 0; thresholdLevel--) {
102              if (reg.getThreshold(thresholdLevel) != -1.0) {
# Line 94 | Line 113 | public class Load__Monitor extends MonitorSkeleton {
113          }
114          return Alert.thresholdNORMAL;
115      }
116 <
116 >    
117 >    /**
118 >     * Initialises a HashMap of Registers with the current list
119 >     * of attributes. This is only used if we are looking at more
120 >     * than one distinct attribute.
121 >     *
122 >     * @param source the host we are looking at
123 >     * @param attributeRegisters a HashMap to put the new Registers in
124 >     */
125      private void initAttributeRegsiters(String source, HashMap attributeRegisters) {
126          for(int attributeNum = 0; attributeNum < _attributes.length; attributeNum++) {
127              String attributeName = _attributes[attributeNum].substring(_attributes[attributeNum].lastIndexOf(".") + 1);
# Line 103 | Line 130 | public class Load__Monitor extends MonitorSkeleton {
130      }
131  
132   //---ACCESSOR/MUTATOR METHODS---
133 +    
134 +    /**
135 +     * Returns a reference to a specific Queue for this
136 +     * monitor. This Queue returns only the data packets
137 +     * (based on type) that we want too look at.
138 +     *
139 +     * @return a reference to a Queue
140 +     */
141 +    protected Queue getQueue() {
142 +        return MonitorManager.getInstance().getDataQueue();
143 +    }
144  
145 +
146   //---ATTRIBUTES---
147  
148      /**
# Line 118 | Line 157 | public class Load__Monitor extends MonitorSkeleton {
157      private String _name = "Load";
158      
159      /**
160 <     * A reference to the configuration proxy in use
160 >     * A HashMap of Registers (or groups of Registers), one
161 >     * for each host we're monitoring.
162       */
123    private ConfigurationProxy _cp = ConfigurationProxy.getInstance();
124
163      private HashMap _hosts = new HashMap();
164 <
164 >    
165 >    /**
166 >     * An array of attributes which we will be checking.
167 >     */
168      private String[] _attributes = { "packet.load.load1", "packet.load.load5", "packet.load.load15" };
169 +    
170 +    /**
171 +     * An array of "nice names" for the attributes in _attributes.
172 +     */
173      private String[] _attributeNames = {"1 min load avg.", "5 min load avg.", "15 min load avg."};
174  
175   //---STATIC ATTRIBUTES---

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines