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.22
Committed: Thu Mar 22 17:57:05 2001 UTC (23 years, 2 months ago) by ajm
Branch: MAIN
Changes since 1.21: +22 -20 lines
Log Message:
Modified to use the new style queuing in the local client

File Contents

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