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.14
Committed: Sat May 18 18:16:00 2002 UTC (22 years ago) by tdb
Branch: MAIN
Changes since 1.13: +22 -3 lines
Log Message:
i-scream is now licensed under the GPL. I've added the GPL headers to every
source file, and put a full copy of the license in the appropriate places.
I think I've covered everything. This is going to be a mad commit ;)

File Contents

# Content
1 /*
2 * i-scream central monitoring system
3 * Copyright (C) 2000-2002 i-scream
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 //---PACKAGE DECLARATION---
21 package uk.org.iscream.cms.server.client.monitors;
22
23 //---IMPORTS---
24 import java.util.HashMap;
25 import java.util.ArrayList;
26 import java.util.Set;
27 import java.util.Iterator;
28 import java.text.NumberFormat;
29 import uk.org.iscream.cms.server.client.*;
30 import uk.org.iscream.cms.server.core.*;
31 import uk.org.iscream.cms.server.util.*;
32 import uk.org.iscream.cms.server.componentmanager.*;
33
34 /**
35 * This Monitor watches the internal server queues.
36 * YES! this system is SO great it monitors itself!
37 *
38 * @author $Author: tdb $
39 * @version $Id: Queue__Monitor.java,v 1.13 2001/05/29 17:02:34 tdb Exp $
40 */
41 public class Queue__Monitor extends MonitorSkeleton {
42
43 //---FINAL ATTRIBUTES---
44
45 /**
46 * The current CVS revision of this class
47 */
48 public final String REVISION = "$Revision: 1.13 $";
49
50 /**
51 * A description of this monitor
52 */
53 public final String DESC = "Who watches the watchmen?";
54
55 private final String SOURCE = "i-scream-server";
56
57 //---STATIC METHODS---
58
59 //---CONSTRUCTORS---
60
61 //---PUBLIC METHODS---
62
63 /**
64 * Analyse a packet of data, and generate an alert if
65 * necessary.
66 *
67 * @param packet the XMLPacket to analyse
68 */
69 public void analysePacket(XMLPacket packet) {
70 if (packet.getParam("packet.attributes.type").equals("queueStat")) {
71 String source = packet.getParam("packet.attributes.hashCode");
72 if (!_hosts.containsKey(source)) {
73 _hosts.put(source, new HashMap());
74 }
75
76 HashMap queueRegisters = (HashMap) _hosts.get(source);
77
78 // get info about the source queue class instance
79 String queueName = packet.getParam("packet.attributes.name");
80 String maxQueueSize = packet.getParam("packet.queue.attributes.maxSize");
81 // unfortunatly we need to check the whole packet
82 // to find the queues, and then get the data attributes
83 Set packetSet = packet.getSet();
84 Iterator i = packetSet.iterator();
85
86 while (i.hasNext()) {
87 String dataKey = (String) i.next();
88 if(dataKey.startsWith("packet.queue.attributes.queue")) {
89 String queueSize = packet.getParam(dataKey);
90
91 // silently ignore these
92 // they're generated by the queueMonitor for deleted queues
93 if(queueSize.equals("[deleted]")) {
94 break;
95 }
96
97 // *** now process this queue ***
98
99 // check if we've seen this queue before on a previous run
100 // if not, we need to create a register for it
101 if(!queueRegisters.containsKey(dataKey)) {
102 queueRegisters.put(dataKey, new Register(_name, _name));
103 }
104
105 // get the register for this disk
106 Register reg = (Register) queueRegisters.get(dataKey);
107
108 // get the packet data
109 double qMax, qSize;
110 try {
111
112 if(maxQueueSize==null || queueSize==null) {
113 throw new NumberFormatException("Queue data invalid");
114 }
115 qMax = Double.parseDouble(maxQueueSize);
116 qSize = Double.parseDouble(queueSize);
117 } catch (NumberFormatException e) {
118 _logger.write(this.toString(), Logger.WARNING, "Received packet from "+source+" with bad queue information: "+e);
119 // don't try to continue and process, try next queue
120 break;
121 }
122
123 boolean useValue = false;
124 try {
125 String option = _cp.getProperty(_name, "Monitor." + _name + ".thresholdMeasure");
126 if (option.equals("VALUE")) {
127 useValue = true;
128 }
129 } catch (PropertyNotFoundException e) {
130 // we default to percentage
131 }
132
133 // this bit determines if the queue check is a % check
134 // or a literal value check
135 double checkValue;
136 String type;
137 if(useValue) {
138 // queue count
139 checkValue = qSize;
140 type = "count";
141 } else {
142 // % of queue
143 checkValue = (qSize / qMax) * 100;
144 type = "%";
145 }
146
147 int newThreshold = checkAttributeThreshold(checkValue, reg);
148
149 // format the checkValue to a String
150 NumberFormat nf = NumberFormat.getInstance();
151 nf.setMaximumFractionDigits(2);
152 nf.setMinimumFractionDigits(2);
153 String strCheckValue = nf.format(checkValue);
154
155 // say which disk had the problem
156 String attributeName = "Size of queue " + type + " in " + queueName + " " + dataKey.substring(dataKey.lastIndexOf('.')+1);
157
158 processAlert(newThreshold, attributeName, reg, SOURCE, strCheckValue);
159
160 }
161 }
162 }
163 }
164
165 /**
166 * Overrides the {@link java.lang.Object#toString() Object.toString()}
167 * method to provide clean logging (every class should have this).
168 *
169 * This uses the uk.org.iscream.cms.server.util.NameFormat class
170 * to format the toString()
171 *
172 * @return the name of this class and its CVS revision
173 */
174 public String toString() {
175 return FormatName.getName(
176 _name,
177 getClass().getName(),
178 REVISION);
179 }
180
181 /**
182 * return the String representation of what the monitor does
183 */
184 public String getDescription(){
185 return DESC;
186 }
187
188 //---PRIVATE METHODS---
189
190 /**
191 * Checks a piece of current data, and returns the
192 * threshold it breaches, if any.
193 *
194 * @param qSize the size of a queue
195 * @param reg the Register for the host
196 * @return the threshold level breached, if any
197 */
198 private int checkAttributeThreshold(double qSize, Register reg) {
199 for(int thresholdLevel = Alert.thresholdLevels.length - 1; thresholdLevel >= 0; thresholdLevel--) {
200 if (reg.getThreshold(thresholdLevel) != -1.0) {
201 if(((double) reg.getThreshold(thresholdLevel)) < qSize) {
202 return thresholdLevel;
203 }
204 }
205 }
206 return Alert.thresholdNORMAL;
207 }
208
209 //---ACCESSOR/MUTATOR METHODS---
210
211 /**
212 * Returns a reference to a specific Queue for this
213 * monitor. This Queue returns only the data packets
214 * (based on type) that we want too look at.
215 *
216 * @return a reference to a Queue
217 */
218 protected Queue getQueue() {
219 return MonitorManager.getInstance().getOtherQueue();
220 }
221
222
223 //---ATTRIBUTES---
224
225 /**
226 * This is the friendly identifier of the
227 * component this class is running in.
228 * eg, a Filter may be called "filter1",
229 * If this class does not have an owning
230 * component, a name from the configuration
231 * can be placed here. This name could also
232 * be changed to null for utility classes.
233 */
234 private String _name = "Queue";
235
236 /**
237 * A reference to the configuration proxy in use
238 */
239 private ConfigurationProxy _cp = ConfigurationProxy.getInstance();
240
241 /**
242 * A HashMap of Registers (or groups of Registers), one
243 * for each host we're monitoring.
244 */
245 private HashMap _hosts = new HashMap();
246
247 //---STATIC ATTRIBUTES---
248
249 }