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

# User Rev Content
1 tdb 1.14 /*
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 ajm 1.1 //---PACKAGE DECLARATION---
21 tdb 1.13 package uk.org.iscream.cms.server.client.monitors;
22 ajm 1.1
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 tdb 1.13 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 ajm 1.1
34     /**
35     * This Monitor watches the internal server queues.
36     * YES! this system is SO great it monitors itself!
37     *
38 tdb 1.14 * @author $Author: tdb $
39     * @version $Id: Queue__Monitor.java,v 1.13 2001/05/29 17:02:34 tdb Exp $
40 ajm 1.1 */
41     public class Queue__Monitor extends MonitorSkeleton {
42    
43     //---FINAL ATTRIBUTES---
44    
45     /**
46     * The current CVS revision of this class
47     */
48 tdb 1.14 public final String REVISION = "$Revision: 1.13 $";
49 ajm 1.1
50 tdb 1.8 /**
51     * A description of this monitor
52     */
53 ajm 1.1 public final String DESC = "Who watches the watchmen?";
54    
55 tdb 1.6 private final String SOURCE = "i-scream-server";
56    
57 ajm 1.1 //---STATIC METHODS---
58    
59     //---CONSTRUCTORS---
60    
61     //---PUBLIC METHODS---
62 tdb 1.8
63     /**
64     * Analyse a packet of data, and generate an alert if
65     * necessary.
66     *
67     * @param packet the XMLPacket to analyse
68     */
69 ajm 1.1 public void analysePacket(XMLPacket packet) {
70 tdb 1.3 if (packet.getParam("packet.attributes.type").equals("queueStat")) {
71     String source = packet.getParam("packet.attributes.hashCode");
72 ajm 1.1 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 ajm 1.2 String queueSize = packet.getParam(dataKey);
90 tdb 1.12
91     // silently ignore these
92     // they're generated by the queueMonitor for deleted queues
93     if(queueSize.equals("[deleted]")) {
94     break;
95     }
96 ajm 1.1
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 tdb 1.10 queueRegisters.put(dataKey, new Register(_name, _name));
103 ajm 1.1 }
104    
105     // get the register for this disk
106 ajm 1.2 Register reg = (Register) queueRegisters.get(dataKey);
107 ajm 1.1
108     // get the packet data
109 ajm 1.2 double qMax, qSize;
110 ajm 1.1 try {
111    
112 ajm 1.2 if(maxQueueSize==null || queueSize==null) {
113 ajm 1.1 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 tdb 1.9 String option = _cp.getProperty(_name, "Monitor." + _name + ".thresholdMeasure");
126 ajm 1.1 if (option.equals("VALUE")) {
127     useValue = true;
128     }
129     } catch (PropertyNotFoundException e) {
130     // we default to percentage
131     }
132    
133 tdb 1.12 // this bit determines if the queue check is a % check
134     // or a literal value check
135 ajm 1.1 double checkValue;
136     String type;
137     if(useValue) {
138 ajm 1.7 // queue count
139 ajm 1.1 checkValue = qSize;
140     type = "count";
141     } else {
142 ajm 1.7 // % of queue
143 ajm 1.1 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 tdb 1.11 String attributeName = "Size of queue " + type + " in " + queueName + " " + dataKey.substring(dataKey.lastIndexOf('.')+1);
157 ajm 1.1
158 tdb 1.6 processAlert(newThreshold, attributeName, reg, SOURCE, strCheckValue);
159 ajm 1.1
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 tdb 1.13 * This uses the uk.org.iscream.cms.server.util.NameFormat class
170 ajm 1.1 * 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 tdb 1.8
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 ajm 1.1 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 tdb 1.8
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 ajm 1.4 protected Queue getQueue() {
219     return MonitorManager.getInstance().getOtherQueue();
220     }
221    
222 ajm 1.1
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 tdb 1.8
241     /**
242     * A HashMap of Registers (or groups of Registers), one
243     * for each host we're monitoring.
244     */
245 ajm 1.1 private HashMap _hosts = new HashMap();
246    
247     //---STATIC ATTRIBUTES---
248    
249     }