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
Revision: 1.18
Committed: Fri Mar 9 03:30:55 2001 UTC (23 years, 2 months ago) by ajm
Branch: MAIN
Changes since 1.17: +16 -7 lines
Log Message:
TOTALLY re-wrote the Register class and made appropriate changes thoughout.  It
is now much more obvious what is going on in many places.

The problem was probably caused by doing CPU as a first monitor and hard coding
the number of attributes a Register stores.  Now if a monitor wants to store
multiple attributes, it has to do that itself.  This makes alot of things
much more readable and inteligable as a result.

File Contents

# User Rev Content
1 tdb 1.1 //---PACKAGE DECLARATION---
2     package uk.ac.ukc.iscream.client.monitors;
3    
4     //---IMPORTS---
5 ajm 1.9 import java.util.HashMap;
6 tdb 1.1 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.*;
10    
11     /**
12     * This Monitor watches the CPU load for all machines
13     *
14 ajm 1.18 * @author $Author: ajm4 $
15     * @version $Id: CPU__Monitor.java,v 1.17 2001/03/06 23:44:08 ajm4 Exp $
16 tdb 1.1 */
17 tdb 1.16 public class CPU__Monitor extends MonitorSkeleton {
18 tdb 1.1
19     //---FINAL ATTRIBUTES---
20    
21     /**
22     * The current CVS revision of this class
23     */
24 ajm 1.18 public final String REVISION = "$Revision: 1.17 $";
25 tdb 1.1
26     public final String DESC = "Monitors CPU.";
27    
28     //---STATIC METHODS---
29    
30     //---CONSTRUCTORS---
31    
32     //---PUBLIC METHODS---
33    
34     public void analysePacket(XMLPacket packet) {
35 ajm 1.7 if (packet.getParam("packet.attributes.type").equals("data")) {
36 tdb 1.8 String source = packet.getParam("packet.attributes.machine_name");
37 ajm 1.9 if (!_hosts.containsKey(source)) {
38 ajm 1.18 HashMap attributeRegisters = new HashMap();
39     initAttributeRegsiters(source, attributeRegisters);
40     _hosts.put(source, attributeRegisters);
41 ajm 1.2 }
42 ajm 1.18
43     HashMap attributeRegisters = (HashMap) _hosts.get(source);
44 ajm 1.11 for(int attributeNum = 0; attributeNum < _attributes.length; attributeNum++) {
45 ajm 1.18 Register reg = (Register) attributeRegisters.get(_attributes[attributeNum]);
46 ajm 1.11 // find out the threshold level we're at
47 ajm 1.17 String attribute = _attributes[attributeNum];
48     String attributeName = _attributeNames[attributeNum];
49     String currentValue = packet.getParam(attribute);
50 tdb 1.16 int newThreshold = checkAttributeThreshold(currentValue, reg);
51 ajm 1.18 processAlert(newThreshold, attributeName, reg, source, currentValue);
52 ajm 1.11 }
53 ajm 1.2 }
54 tdb 1.1 }
55    
56     /**
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
61     * to format the toString()
62     *
63     * @return the name of this class and its CVS revision
64     */
65     public String toString() {
66     return FormatName.getName(
67     _name,
68     getClass().getName(),
69     REVISION);
70     }
71    
72     /**
73 ajm 1.11 * return the String representation of what the monitor does
74 tdb 1.1 */
75     public String getDescription(){
76     return DESC;
77     }
78    
79     //---PRIVATE METHODS---
80    
81 ajm 1.11 private int checkAttributeThreshold(String attributeString, Register reg) {
82     for(int thresholdLevel = Alert.thresholdLevels.length - 1; thresholdLevel >= 0; thresholdLevel--) {
83     if (reg.getThreshold(thresholdLevel) != -1.0) {
84     if(attributeString != null) {
85     try {
86     double attribute = Double.parseDouble(attributeString);
87     if (reg.getThreshold(thresholdLevel) < attribute) return thresholdLevel;
88     } catch (NumberFormatException e) {
89     // we got some duff data in the packet, but we shouldn't have
90     _logger.write(toString(), Logger.DEBUG, "possible errenous packet data, should be double value - " + attributeString);
91     }
92 ajm 1.9 }
93     }
94     }
95 tdb 1.16 return Alert.thresholdNORMAL;
96 ajm 1.18 }
97    
98     private void initAttributeRegsiters(String source, HashMap attributeRegisters) {
99     for(int attributeNum = 0; attributeNum < _attributes.length; attributeNum++) {
100     attributeRegisters.put(_attributes[attributeNum], new Register(source, _name));
101     }
102 ajm 1.2 }
103    
104 tdb 1.1 //---ACCESSOR/MUTATOR METHODS---
105    
106     //---ATTRIBUTES---
107    
108     /**
109     * This is the friendly identifier of the
110     * component this class is running in.
111     * eg, a Filter may be called "filter1",
112     * If this class does not have an owning
113     * component, a name from the configuration
114     * can be placed here. This name could also
115     * be changed to null for utility classes.
116     */
117 ajm 1.11 private String _name = "CPU";
118 ajm 1.2
119     /**
120 ajm 1.11 * A reference to the configuration proxy in use
121 ajm 1.2 */
122 ajm 1.11 private ConfigurationProxy _cp = ConfigurationProxy.getInstance();
123 ajm 1.9
124     private HashMap _hosts = new HashMap();
125    
126     private String[] _attributes = { "packet.cpu.user", "packet.cpu.kernel", "packet.cpu.iowait", "packet.cpu.swap" };
127     private String[] _attributeNames = {"User CPU", "Kernel CPU", "I/O Wait CPU", "Swap CPU"};
128 tdb 1.1
129     //---STATIC ATTRIBUTES---
130    
131     }