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.16
Committed: Tue Mar 6 22:35:01 2001 UTC (23 years, 3 months ago) by tdb
Branch: MAIN
Changes since 1.15: +8 -77 lines
Log Message:
Changed the existing monitor's to use the skeleton class.

File Contents

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