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.7
Committed: Thu Mar 22 22:34:18 2001 UTC (23 years, 6 months ago) by ajm
Branch: MAIN
Changes since 1.6: +5 -5 lines
Log Message:
Now sends a nicer alert identifier, passes the queue number that rasied the alert.

File Contents

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