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/Register.java
Revision: 1.6
Committed: Tue Mar 6 02:33:55 2001 UTC (23 years, 3 months ago) by ajm
Branch: MAIN
Changes since 1.5: +29 -3 lines
Log Message:
Now passes the time since the first alert for a problem occoured.

Also has support for formatting and displaying this information as obtained from the config

File Contents

# User Rev Content
1 ajm 1.1 //---PACKAGE DECLARATION---
2     package uk.ac.ukc.iscream.client;
3    
4     //---IMPORTS---
5     import uk.ac.ukc.iscream.util.*;
6 tdb 1.4 import uk.ac.ukc.iscream.componentmanager.*;
7 ajm 1.1
8     /**
9 ajm 1.2 * The Register class holds theshold values,
10     * the last level of alert for each attribute for a monitor
11     * and the time of last alert sent for each alert level for
12     * each attribute in this register.
13 ajm 1.1 *
14 ajm 1.2 * This class is used by monitor classes so they can determine
15     * how often they should send alerts when breaching alert levels.
16     * It also stores (and keeps uptodate (via the configuration proxy)
17     * the threshold values for the monitor.
18     *
19 ajm 1.6 * @author $Author: ajm4 $
20     * @version $Id: Register.java,v 1.5 2001/03/06 01:40:24 ajm4 Exp $
21 ajm 1.1 */
22     public class Register {
23    
24     //---FINAL ATTRIBUTES---
25    
26     /**
27     * The current CVS revision of this class
28     */
29 ajm 1.6 public static final String REVISION = "$Revision: 1.5 $";
30 ajm 1.1
31     //---STATIC METHODS---
32    
33     //---CONSTRUCTORS---
34    
35     /**
36 ajm 1.2 * Construct a Register with the hostname and monitorName
37     * (for obtaining the threshold values), and the number of
38     * attributes we are keeping track of.
39 ajm 1.1 *
40 ajm 1.2 * @param hostname the hostname this register is for
41     * @param monitorName the monitor this register is for
42     * @param numAttributes the number of attributes to track
43 ajm 1.1 */
44 ajm 1.2 public Register(String hostname, String monitorName, int numAttributes) {
45     _hostname = hostname;
46     _monitorName = monitorName;
47     _lastAlertLevels = new int[numAttributes];
48     _lastThresholdLevels = new int[numAttributes];
49 ajm 1.6 _initialAlertTime = new long[numAttributes];
50 ajm 1.3 _lastAlertTimeout = new long[numAttributes];
51 ajm 1.2 _times = new long[numAttributes][Alert.alertLevels.length];
52     // initialise the arrays to 0
53     for (int x = 0; x < _lastAlertLevels.length; x++) {
54     _lastAlertLevels[x] = 0;
55 ajm 1.6 _initialAlertTime[x] = 0;
56 ajm 1.2 _lastThresholdLevels[x] = 0;
57 ajm 1.3 _lastAlertTimeout[x] = 0;
58 ajm 1.2 for(int y = 0; y < Alert.alertLevels.length; y++) {
59     _times[x][y] = 0;
60     }
61 ajm 1.1 }
62     }
63    
64     //---PUBLIC METHODS---
65    
66     //---PRIVATE METHODS---
67    
68     //---ACCESSOR/MUTATOR METHODS---
69    
70 ajm 1.2 /**
71     * Gets the last alert level for the
72     * given attribute.
73     *
74     * @param attributeNum the attribute to get
75     *
76     * @return the last alert level
77     */
78     public int getLastAlertLevel(int attributeNum) {
79     return _lastAlertLevels[attributeNum];
80     }
81    
82     /**
83     * Sets the last threshold level for the
84     * given attribute.
85     *
86     * @param attributeNum the attribute to set
87     * @param level the new last threshold level
88     */
89     public void setLastThresholdLevel(int attributeNum, int level) {
90     _lastThresholdLevels[attributeNum] = level;
91     }
92    
93     /**
94     * Gets the last threshold level for the
95     * given attribute.
96     *
97     * @param attributeNum the attribute to get
98     *
99     * @return the last threshold level
100     */
101     public int getLastThresholdLevel(int attributeNum) {
102     return _lastThresholdLevels[attributeNum];
103     }
104    
105     /**
106     * Sets the last alert level for the
107     * given attribute.
108     *
109 ajm 1.5 * Note that if this is setting to an OK
110     * level alert, it resets _maxLevelCount.
111     *
112 ajm 1.6 * This also sets the "initialAlertTime"
113     * if the next alert after OK is set.
114     * And resets it to 0 if it IS an OK.
115     *
116 ajm 1.2 * @param attributeNum the attribute to set
117     * @param level the new last alert level
118     */
119     public void setLastAlertLevel(int attributeNum, int level) {
120     _lastAlertLevels[attributeNum] = level;
121 ajm 1.5 if (level == Alert.alertOK) {
122     _maxLevelCount = 0;
123 ajm 1.6 _initialAlertTime[attributeNum] = 0;
124     }
125     if (level == Alert.alertOK + 1) {
126     _initialAlertTime[attributeNum] = System.currentTimeMillis();
127 ajm 1.5 }
128 ajm 1.2 }
129    
130     /**
131     * Gets the time an alert was sent for the
132     * given attribute at the given level.
133     *
134     * @param attributeNum the attribute to get
135     * @param level the alert level to get
136     *
137     * @return the time last sent
138     */
139     public long getTimeLastSent(int attributeNum) {
140     return _times[attributeNum][getLastAlertLevel(attributeNum)];
141     }
142    
143     /**
144     * Gets the time an alert was sent for the
145     * given attribute at the given level.
146     *
147     * @param attributeNum the attribute to get
148     * @param level the alert level to get
149     * @param value the new time
150     */
151     public void setTimeLastSent(int attributeNum, long value) {
152     _times[attributeNum][getLastAlertLevel(attributeNum)] = value;
153     }
154    
155     /**
156     * Gets the threshold value for the given
157     * level of alert.
158     *
159     * If there is no alert threshold for a
160     * given level, this returns -1.0
161     *
162     * @param level the alert level
163     */
164     public double getThreshold(int level) {
165 tdb 1.4 // -1.0 means we don't use an alert level
166 ajm 1.2 double threshold = -1.0;
167 tdb 1.4 try {
168     String thresholdString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".threshold." + Alert.thresholdLevels[level]);
169     threshold = Double.parseDouble(thresholdString);
170     } catch (PropertyNotFoundException e) {
171     threshold = -1.0;
172     } catch (NumberFormatException e) {
173     threshold = -1.0;
174 ajm 1.2 }
175     return threshold;
176     }
177    
178     /**
179     * Gets the alert timeout value for the given
180     * level of alert. This value is in millis,
181     * and is converted from the value in the config,
182     * which should be seconds.
183     *
184     * Note that this is dependant on the threshold value
185     * given, the timeout is obatined from the config, then
186     * divided by the threshold value, this allows alerts to
187     * progress faster should a higher threshold value be passed
188     *
189     * If there is no alert timeout for a
190 tdb 1.4 * given level, this returns 0
191 ajm 1.2 *
192     * @param level the alert level
193     * @param thresholdLevel the threshold leve we are on
194     */
195     public long getAlertTimeout(int level, int attributeNum) {
196 tdb 1.4 // 0 means we don't use this value
197 ajm 1.2 long timeout = 0;
198 tdb 1.4 try {
199     String timeoutString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".alertTimeout." + Alert.alertLevels[level]);
200     int threshold = getLastThresholdLevel(attributeNum);
201     if (threshold > 0) {
202     timeout = (Long.parseLong(timeoutString) / threshold) * 1000;
203 ajm 1.2 }
204 tdb 1.4 } catch (PropertyNotFoundException e) {
205     timeout = 0;
206     } catch (NumberFormatException e) {
207     timeout = 0;
208 ajm 1.2 }
209     return timeout;
210 ajm 1.1 }
211    
212 ajm 1.2 /**
213     * Either advances to the next alert level, or if
214     * the maximum alert level has been reached, simply returns
215     * that.
216     *
217 ajm 1.5 * Note this method will NEVER reach the last alert level
218     * in the list, this is assumed to be FINAL, and special
219     * logic is in place to handle that.
220     *
221 ajm 1.2 * @param attributeNum the attribute to get next alert for
222     */
223     public int getNextAlertLevel(int attributeNum) {
224 ajm 1.5 if((getLastAlertLevel(attributeNum) + 1) > (Alert.alertLevels.length - 2)) {
225 ajm 1.2 return getLastAlertLevel(attributeNum);
226     }
227     return getLastAlertLevel(attributeNum) + 1;
228     }
229    
230     /**
231 ajm 1.3 * Gets the timeout value of the last alert
232     * sent
233     *
234     * @param attrubuteNum the attribute to get the last timeout for
235     * @return the last timeout value
236     */
237     public long getLastAlertTimeout(int attributeNum) {
238     return _lastAlertTimeout[attributeNum];
239     }
240    
241     /**
242     * Sets the timeout value of the last alert
243     * sent
244     *
245     * @param attrubuteNum the attribute to get the last timeout for
246     * @param timeout the new value
247     */
248     public void setLastAlertTimeout(int attributeNum, long timeout) {
249     _lastAlertTimeout[attributeNum] = timeout;
250     }
251    
252     /**
253 ajm 1.6 * Returns the time that the first alert was sent
254     * for an attribute that has passed a threshold value
255     *
256     * @param attrubuteNum the attribute to get the first alert time for
257     */
258     public long getInitialAlertTime(int attributeNum) {
259     return _initialAlertTime[attributeNum];
260     }
261    
262     /**
263 ajm 1.2 * Advances the alert level to the next one up.
264     *
265 ajm 1.5 * This keeps track of the number of the number
266     * of times the highest NON-FINAL alert level
267     * has been reached. Note this isn't a specific
268     * level, just the highest, so you could configure
269     * more levels and not affect this.
270     *
271     * If the count exceeds the number of times
272     * set in the configuration, it escalates to
273     * a FINAL alert if we're using FINAL's.
274     *
275     * It determines if to use FINAL's from the config
276     * entry reachFINALcount, when the count exceeds
277     * this value, it escalates to a FINAL. If that attribute
278     * is mis-read or is not configured. It will NEVER reach
279     * a FINAL.
280     *
281 ajm 1.2 * @param attributeNum the attribute to advance the alert for
282     */
283     public void escalateAlert(int attributeNum) {
284     setLastAlertLevel(attributeNum, getNextAlertLevel(attributeNum));
285 ajm 1.5 try {
286     // note if we fail to get this value, we won't process the res of this
287     int reachFINALcount = Integer.parseInt(_cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".reachFINALcount"));
288     if ((getLastAlertLevel(attributeNum) == Alert.alertLevels.length - 2) && (_maxLevelCount < reachFINALcount) ) {
289     _maxLevelCount++;
290     } else {
291     setLastAlertLevel(attributeNum, Alert.alertFINAL);
292     }
293     } catch (PropertyNotFoundException e) {
294     // we NEVER reach FINAL in this case
295     } catch (NumberFormatException e) {
296     // we NEVER reach FINAL in this case
297     }
298 ajm 1.1 }
299    
300     //---ATTRIBUTES---
301    
302 ajm 1.2 /**
303     * The host this register is for
304     */
305     private String _hostname;
306    
307     /**
308     * The monitor this register is for
309     */
310     private String _monitorName;
311    
312     /**
313     * An array of last alert levels for
314     * each attribute this register is looking
315     * after.
316     */
317     private int[] _lastAlertLevels;
318    
319     /**
320     * An array of last threshold levels for
321     * each attribute this register is looking
322     * after.
323     */
324     private int[] _lastThresholdLevels;
325 ajm 1.3
326     /**
327     * An array of last alert timeout levels for
328     * each attribute this register is looking
329     * after.
330     */
331     private long[] _lastAlertTimeout;
332 ajm 1.2
333     /**
334     * An array of arrays containing
335     * time an alert of each level
336     * was last sent for each attribute.
337     */
338     private long[][] _times;
339 ajm 1.6
340     /**
341     * Initial times that an alert was first
342     * raised.
343     */
344     private long[] _initialAlertTime;
345 ajm 1.2
346     /**
347     * A reference to the configuration proxy in use
348     */
349     private ConfigurationProxy _cp = ConfigurationProxy.getInstance();
350 ajm 1.5
351     /**
352     * The number of times the maximum level alert
353     * has occured IN A ROW, this is escalated by
354     * the escalate(int) method, and reset by the
355     * setLastAlertLevel(int, int) method
356     */
357     private int _maxLevelCount = 0;
358 ajm 1.1
359     //---STATIC ATTRIBUTES---
360    
361     }