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.19 by tdb, Wed Mar 14 23:25:29 2001 UTC vs.
Revision 1.23 by tdb, Fri Mar 23 02:32:48 2001 UTC

# Line 23 | Line 23 | public class CPU__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 CPU.";
30      
31   //---STATIC METHODS---
# Line 30 | Line 33 | public class CPU__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) {
44 <        if (packet.getParam("packet.attributes.type").equals("data")) {
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);
41 <            }
44 >        String source = packet.getParam("packet.attributes.machine_name");
45 >        if (!_hosts.containsKey(source)) {
46 >            HashMap attributeRegisters = new HashMap();
47 >            initAttributeRegsiters(source, attributeRegisters);
48 >            _hosts.put(source, attributeRegisters);
49 >        }
50  
51 <            HashMap attributeRegisters = (HashMap) _hosts.get(source);
52 <            for(int attributeNum = 0; attributeNum < _attributes.length; attributeNum++) {
53 <                Register reg = (Register) attributeRegisters.get(_attributes[attributeNum]);
54 <                // find out the threshold level we're at
55 <                String attribute = _attributes[attributeNum];
56 <                String attributeName = _attributeNames[attributeNum];
57 <                String currentValue = packet.getParam(attribute);
58 <                int newThreshold = checkAttributeThreshold(currentValue, reg);
59 <                processAlert(newThreshold, attributeName, reg, source, currentValue);
52 <            }
51 >        HashMap attributeRegisters = (HashMap) _hosts.get(source);
52 >        for(int attributeNum = 0; attributeNum < _attributes.length; attributeNum++) {
53 >            Register reg = (Register) attributeRegisters.get(_attributes[attributeNum]);
54 >            // find out the threshold level we're at
55 >            String attribute = _attributes[attributeNum];
56 >            String attributeName = _attributeNames[attributeNum];
57 >            String currentValue = packet.getParam(attribute);
58 >            int newThreshold = checkAttributeThreshold(currentValue, reg);
59 >            processAlert(newThreshold, attributeName, reg, source, currentValue);
60          }
61      }
62  
# Line 77 | Line 84 | public class CPU__Monitor extends MonitorSkeleton {
84      }
85  
86   //---PRIVATE METHODS---
87 <
87 >    
88 >    /**
89 >     * Checks a piece of current data, and returns the
90 >     * threshold it breaches, if any.
91 >     *
92 >     * @param attributeString a String representing the current data value
93 >     * @param reg the Register for the host
94 >     * @return the threshold level breached, if any
95 >     */
96      private int checkAttributeThreshold(String attributeString, Register reg) {
97          for(int thresholdLevel = Alert.thresholdLevels.length - 1; thresholdLevel >= 0; thresholdLevel--) {
98              if (reg.getThreshold(thresholdLevel) != -1.0) {
# Line 94 | Line 109 | public class CPU__Monitor extends MonitorSkeleton {
109          }
110          return Alert.thresholdNORMAL;
111      }
112 <
112 >    
113 >    /**
114 >     * Initialises a HashMap of Registers with the current list
115 >     * of attributes. This is only used if we are looking at more
116 >     * than one distinct attribute.
117 >     *
118 >     * @param source the host we are looking at
119 >     * @param attributeRegisters a HashMap to put the new Registers in
120 >     */
121      private void initAttributeRegsiters(String source, HashMap attributeRegisters) {
122          for(int attributeNum = 0; attributeNum < _attributes.length; attributeNum++) {
123 <            attributeRegisters.put(_attributes[attributeNum], new Register(source, _name));
123 >            String attributeName = _attributes[attributeNum].substring(_attributes[attributeNum].lastIndexOf(".") + 1);
124 >            attributeRegisters.put(_attributes[attributeNum], new Register(source, _name, attributeName));
125          }
126      }
127  
128   //---ACCESSOR/MUTATOR METHODS---
129 +    
130 +    /**
131 +     * Returns a reference to a specific Queue for this
132 +     * monitor. This Queue returns only the data packets
133 +     * (based on type) that we want too look at.
134 +     *
135 +     * @return a reference to a Queue
136 +     */
137 +    protected Queue getQueue() {
138 +        return MonitorManager.getInstance().getDataQueue();
139 +    }
140  
141   //---ATTRIBUTES---
142  
# Line 117 | Line 152 | public class CPU__Monitor extends MonitorSkeleton {
152      private String _name = "CPU";
153      
154      /**
155 <     * A reference to the configuration proxy in use
155 >     * A HashMap of Registers (or groups of Registers), one
156 >     * for each host we're monitoring.
157       */
122    private ConfigurationProxy _cp = ConfigurationProxy.getInstance();
123
158      private HashMap _hosts = new HashMap();
159 <
159 >    
160 >    /**
161 >     * An array of attributes which we will be checking.
162 >     */
163      private String[] _attributes = { "packet.cpu.user", "packet.cpu.kernel", "packet.cpu.iowait", "packet.cpu.swap" };
164 +    
165 +    /**
166 +     * An array of "nice names" for the attributes in _attributes.
167 +     */
168      private String[] _attributeNames = {"User CPU", "Kernel CPU", "I/O Wait CPU", "Swap CPU"};
169  
170   //---STATIC ATTRIBUTES---

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines