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.2
Committed: Thu Mar 22 01:55:18 2001 UTC (23 years, 2 months ago) by ajm
Branch: MAIN
Changes since 1.1: +6 -6 lines
Log Message:
should work now ;p

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     * @author $Author: ajm4 $
20 ajm 1.2 * @version $Id: Queue__Monitor.java,v 1.1 2001/03/22 01:51:51 ajm4 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.2 public final String REVISION = "$Revision: 1.1 $";
30 ajm 1.1
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("data")) {
41     String source = packet.getParam("packet.attributes.machine_name");
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 ajm 1.2 String queueSize = packet.getParam(dataKey);
60 ajm 1.1
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 ajm 1.2 Register reg = (Register) queueRegisters.get(dataKey);
71 ajm 1.1
72     // get the packet data
73 ajm 1.2 double qMax, qSize;
74 ajm 1.1 try {
75    
76 ajm 1.2 if(maxQueueSize==null || queueSize==null) {
77 ajm 1.1 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    
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     String attributeName = "Size of queue " + type + " in " + queueName;
123    
124     processAlert(newThreshold, attributeName, reg, source, strCheckValue);
125    
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    
169     //---ATTRIBUTES---
170    
171     /**
172     * This is the friendly identifier of the
173     * component this class is running in.
174     * eg, a Filter may be called "filter1",
175     * If this class does not have an owning
176     * component, a name from the configuration
177     * can be placed here. This name could also
178     * be changed to null for utility classes.
179     */
180     private String _name = "Queue";
181    
182     /**
183     * A reference to the configuration proxy in use
184     */
185     private ConfigurationProxy _cp = ConfigurationProxy.getInstance();
186    
187     private HashMap _hosts = new HashMap();
188    
189     //---STATIC ATTRIBUTES---
190    
191     }