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/Queue__Monitor.java
Revision: 1.3
Committed: Thu Mar 22 17:32:34 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.2: +4 -6 lines
Log Message:
Some major bugs in here meaning it would never actually look at queueStat the
queueStat packets!

File Contents

# Content
1 //---PACKAGE DECLARATION---
2 package uk.org.iscream.client.monitors;
3
4 //---IMPORTS---
5 import java.util.HashMap;
6 import java.util.ArrayList;
7 import java.util.Set;
8 import java.util.Iterator;
9 import java.text.NumberFormat;
10 import uk.org.iscream.client.*;
11 import uk.org.iscream.core.*;
12 import uk.org.iscream.util.*;
13 import uk.org.iscream.componentmanager.*;
14
15 /**
16 * This Monitor watches the internal server queues.
17 * YES! this system is SO great it monitors itself!
18 *
19 * @author $Author: ajm4 $
20 * @version $Id: Queue__Monitor.java,v 1.2 2001/03/22 01:55:18 ajm4 Exp $
21 */
22 public class Queue__Monitor extends MonitorSkeleton {
23
24 //---FINAL ATTRIBUTES---
25
26 /**
27 * The current CVS revision of this class
28 */
29 public final String REVISION = "$Revision: 1.2 $";
30
31 public final String DESC = "Who watches the watchmen?";
32
33 //---STATIC METHODS---
34
35 //---CONSTRUCTORS---
36
37 //---PUBLIC METHODS---
38
39 public void analysePacket(XMLPacket packet) {
40 if (packet.getParam("packet.attributes.type").equals("queueStat")) {
41 String source = packet.getParam("packet.attributes.hashCode");
42 if (!_hosts.containsKey(source)) {
43 _hosts.put(source, new HashMap());
44 }
45
46 HashMap queueRegisters = (HashMap) _hosts.get(source);
47
48 // get info about the source queue class instance
49 String queueName = packet.getParam("packet.attributes.name");
50 String maxQueueSize = packet.getParam("packet.queue.attributes.maxSize");
51 // unfortunatly we need to check the whole packet
52 // to find the queues, and then get the data attributes
53 Set packetSet = packet.getSet();
54 Iterator i = packetSet.iterator();
55
56 while (i.hasNext()) {
57 String dataKey = (String) i.next();
58 if(dataKey.startsWith("packet.queue.attributes.queue")) {
59 String queueSize = packet.getParam(dataKey);
60
61 // *** now process this queue ***
62
63 // check if we've seen this queue before on a previous run
64 // if not, we need to create a register for it
65 if(!queueRegisters.containsKey(dataKey)) {
66 queueRegisters.put(dataKey, new Register(source, _name));
67 }
68
69 // get the register for this disk
70 Register reg = (Register) queueRegisters.get(dataKey);
71
72 // get the packet data
73 double qMax, qSize;
74 try {
75
76 if(maxQueueSize==null || queueSize==null) {
77 throw new NumberFormatException("Queue data invalid");
78 }
79 qMax = Double.parseDouble(maxQueueSize);
80 qSize = Double.parseDouble(queueSize);
81 } catch (NumberFormatException e) {
82 _logger.write(this.toString(), Logger.WARNING, "Received packet from "+source+" with bad queue information: "+e);
83 // don't try to continue and process, try next queue
84 break;
85 }
86
87 boolean useValue = false;
88 try {
89 String option = _cp.getProperty("Host." + source, "Monitor." + _name + ".thresholdMeasure");
90 if (option.equals("VALUE")) {
91 useValue = true;
92 }
93 } catch (PropertyNotFoundException e) {
94 // we default to percentage
95 }
96
97 // this bit determines if the disk check is a % check
98 // or a kb check
99 double checkValue;
100 String type;
101 if(useValue) {
102 // kb disk in use
103 checkValue = qSize;
104 type = "count";
105 } else {
106 // % disk in use
107 checkValue = (qSize / qMax) * 100;
108 type = "%";
109 }
110
111 int newThreshold = checkAttributeThreshold(checkValue, reg);
112
113 // format the checkValue to a String
114 NumberFormat nf = NumberFormat.getInstance();
115 nf.setMaximumFractionDigits(2);
116 nf.setMinimumFractionDigits(2);
117 String strCheckValue = nf.format(checkValue);
118
119 // say which disk had the problem
120 String attributeName = "Size of queue " + type + " in " + queueName;
121
122 processAlert(newThreshold, attributeName, reg, source, strCheckValue);
123
124 }
125 }
126 }
127 }
128
129 /**
130 * Overrides the {@link java.lang.Object#toString() Object.toString()}
131 * method to provide clean logging (every class should have this).
132 *
133 * This uses the uk.org.iscream.util.NameFormat class
134 * to format the toString()
135 *
136 * @return the name of this class and its CVS revision
137 */
138 public String toString() {
139 return FormatName.getName(
140 _name,
141 getClass().getName(),
142 REVISION);
143 }
144
145 /**
146 * return the String representation of what the monitor does
147 */
148 public String getDescription(){
149 return DESC;
150 }
151
152 //---PRIVATE METHODS---
153
154 private int checkAttributeThreshold(double qSize, Register reg) {
155 for(int thresholdLevel = Alert.thresholdLevels.length - 1; thresholdLevel >= 0; thresholdLevel--) {
156 if (reg.getThreshold(thresholdLevel) != -1.0) {
157 if(((double) reg.getThreshold(thresholdLevel)) < qSize) {
158 return thresholdLevel;
159 }
160 }
161 }
162 return Alert.thresholdNORMAL;
163 }
164
165 //---ACCESSOR/MUTATOR METHODS---
166
167 //---ATTRIBUTES---
168
169 /**
170 * This is the friendly identifier of the
171 * component this class is running in.
172 * eg, a Filter may be called "filter1",
173 * If this class does not have an owning
174 * component, a name from the configuration
175 * can be placed here. This name could also
176 * be changed to null for utility classes.
177 */
178 private String _name = "Queue";
179
180 /**
181 * A reference to the configuration proxy in use
182 */
183 private ConfigurationProxy _cp = ConfigurationProxy.getInstance();
184
185 private HashMap _hosts = new HashMap();
186
187 //---STATIC ATTRIBUTES---
188
189 }