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.13
Committed: Thu Mar 15 03:25:41 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.12: +6 -4 lines
Log Message:
Now an OK alert will have an initialAlertTime that follows from the alert it is
giving on OK for.

File Contents

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