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
Revision: 1.4
Committed: Tue May 29 17:02:34 2001 UTC (22 years, 11 months ago) by tdb
Branch: MAIN
Branch point for: SERVER_PIRCBOT
Changes since 1.3: +9 -9 lines
Log Message:
Major change in the java package naming. This has been held off for some time
now, but it really needed doing. The future packaging of all i-scream products
will be;

uk.org.iscream.<product>.<subpart>.*

In the case of the central monitoring system server this will be;

uk.org.iscream.cms.server.*

The whole server has been changed to follow this structure, and tested to a
smallish extent. Further changes in other parts of the CMS will follow.

File Contents

# Content
1 //---PACKAGE DECLARATION---
2 package uk.org.iscream.cms.server.client.monitors;
3
4 //---IMPORTS---
5 import java.util.HashMap;
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
13 *
14 * @author $Author: tdb1 $
15 * @version $Id: Load__Monitor.java,v 1.3 2001/03/23 02:32:49 tdb1 Exp $
16 */
17 public class Load__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.3 $";
25
26 /**
27 * A description of this monitor
28 */
29 public final String DESC = "Monitors Load.";
30
31 //---STATIC METHODS---
32
33 //---CONSTRUCTORS---
34
35 //---PUBLIC METHODS---
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
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.cms.server.util.NameFormat class
72 * to format the toString()
73 *
74 * @return the name of this class and its CVS revision
75 */
76 public String toString() {
77 return FormatName.getName(
78 _name,
79 getClass().getName(),
80 REVISION);
81 }
82
83 /**
84 * return the String representation of what the monitor does
85 */
86 public String getDescription(){
87 return DESC;
88 }
89
90 //---PRIVATE METHODS---
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) {
103 if(attributeString != null) {
104 try {
105 double attribute = Double.parseDouble(attributeString);
106 if (reg.getThreshold(thresholdLevel) < attribute) return thresholdLevel;
107 } catch (NumberFormatException e) {
108 // we got some duff data in the packet, but we shouldn't have
109 _logger.write(toString(), Logger.DEBUG, "possible errenous packet data, should be double value - " + attributeString);
110 }
111 }
112 }
113 }
114 return Alert.thresholdNORMAL;
115 }
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);
128 attributeRegisters.put(_attributes[attributeNum], new Register(source, _name, attributeName));
129 }
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 /**
149 * This is the friendly identifier of the
150 * component this class is running in.
151 * eg, a Filter may be called "filter1",
152 * If this class does not have an owning
153 * component, a name from the configuration
154 * can be placed here. This name could also
155 * be changed to null for utility classes.
156 */
157 private String _name = "Load";
158
159 /**
160 * A HashMap of Registers (or groups of Registers), one
161 * for each host we're monitoring.
162 */
163 private HashMap _hosts = new HashMap();
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---
176
177 }