1 |
ajm |
1.1 |
//---PACKAGE DECLARATION--- |
2 |
tdb |
1.12 |
package uk.org.iscream.client; |
3 |
ajm |
1.1 |
|
4 |
|
|
//---IMPORTS--- |
5 |
tdb |
1.12 |
import uk.org.iscream.util.*; |
6 |
|
|
import uk.org.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 |
ajm |
1.11 |
* and the time of last alert sent for each alert level. |
12 |
ajm |
1.1 |
* |
13 |
ajm |
1.2 |
* 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 |
tdb |
1.13 |
* @author $Author: tdb1 $ |
19 |
|
|
* @version $Id: Register.java,v 1.12 2001/03/14 23:25:29 tdb1 Exp $ |
20 |
ajm |
1.1 |
*/ |
21 |
|
|
public class Register { |
22 |
|
|
|
23 |
|
|
//---FINAL ATTRIBUTES--- |
24 |
|
|
|
25 |
|
|
/** |
26 |
|
|
* The current CVS revision of this class |
27 |
|
|
*/ |
28 |
tdb |
1.13 |
public static final String REVISION = "$Revision: 1.12 $"; |
29 |
ajm |
1.1 |
|
30 |
|
|
//---STATIC METHODS--- |
31 |
|
|
|
32 |
|
|
//---CONSTRUCTORS--- |
33 |
|
|
|
34 |
|
|
/** |
35 |
ajm |
1.2 |
* Construct a Register with the hostname and monitorName |
36 |
ajm |
1.11 |
* (for obtaining the threshold values). |
37 |
ajm |
1.1 |
* |
38 |
ajm |
1.2 |
* @param hostname the hostname this register is for |
39 |
|
|
* @param monitorName the monitor this register is for |
40 |
ajm |
1.11 |
|
41 |
ajm |
1.1 |
*/ |
42 |
ajm |
1.11 |
public Register(String hostname, String monitorName) { |
43 |
ajm |
1.2 |
_hostname = hostname; |
44 |
|
|
_monitorName = monitorName; |
45 |
ajm |
1.11 |
_lastAlertLevel = 0; |
46 |
|
|
_lastThresholdLevel = 0; |
47 |
|
|
_initialAlertTime= 0; |
48 |
|
|
_lastAlertTimeout = 0; |
49 |
|
|
_times = new long[Alert.alertLevels.length]; |
50 |
ajm |
1.2 |
// initialise the arrays to 0 |
51 |
ajm |
1.11 |
for(int x = 0; x < Alert.alertLevels.length; x++) { |
52 |
|
|
_times[x] = 0; |
53 |
ajm |
1.1 |
} |
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
//---PUBLIC METHODS--- |
57 |
|
|
|
58 |
|
|
//---PRIVATE METHODS--- |
59 |
|
|
|
60 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
61 |
|
|
|
62 |
ajm |
1.2 |
/** |
63 |
ajm |
1.11 |
* Gets the last alert level |
64 |
ajm |
1.2 |
* |
65 |
|
|
* @return the last alert level |
66 |
|
|
*/ |
67 |
ajm |
1.11 |
public int getLastAlertLevel() { |
68 |
|
|
return _lastAlertLevel; |
69 |
ajm |
1.2 |
} |
70 |
|
|
|
71 |
|
|
/** |
72 |
ajm |
1.11 |
* Sets the last threshold level |
73 |
ajm |
1.2 |
* |
74 |
|
|
* @param level the new last threshold level |
75 |
|
|
*/ |
76 |
ajm |
1.11 |
public void setLastThresholdLevel(int level) { |
77 |
|
|
_lastThresholdLevel = level; |
78 |
ajm |
1.2 |
} |
79 |
|
|
|
80 |
ajm |
1.11 |
/** |
81 |
|
|
* Gets the last threshold level |
82 |
ajm |
1.2 |
* |
83 |
|
|
* @return the last threshold level |
84 |
|
|
*/ |
85 |
ajm |
1.11 |
public int getLastThresholdLevel() { |
86 |
|
|
return _lastThresholdLevel; |
87 |
ajm |
1.2 |
} |
88 |
|
|
|
89 |
|
|
/** |
90 |
ajm |
1.11 |
* Sets the last alert level |
91 |
ajm |
1.2 |
* |
92 |
ajm |
1.5 |
* Note that if this is setting to an OK |
93 |
|
|
* level alert, it resets _maxLevelCount. |
94 |
|
|
* |
95 |
ajm |
1.6 |
* 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 |
ajm |
1.2 |
* @param level the new last alert level |
100 |
|
|
*/ |
101 |
ajm |
1.11 |
public void setLastAlertLevel(int level) { |
102 |
|
|
_lastAlertLevel = level; |
103 |
ajm |
1.5 |
if (level == Alert.alertOK) { |
104 |
|
|
_maxLevelCount = 0; |
105 |
tdb |
1.13 |
// 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 |
ajm |
1.6 |
} |
109 |
|
|
if (level == Alert.alertOK + 1) { |
110 |
ajm |
1.11 |
_initialAlertTime = System.currentTimeMillis(); |
111 |
ajm |
1.5 |
} |
112 |
ajm |
1.2 |
} |
113 |
|
|
|
114 |
|
|
/** |
115 |
ajm |
1.11 |
* Gets the time an alert was sent at the given level. |
116 |
ajm |
1.2 |
* |
117 |
|
|
* @param level the alert level to get |
118 |
|
|
* |
119 |
|
|
* @return the time last sent |
120 |
|
|
*/ |
121 |
ajm |
1.11 |
public long getTimeLastSent() { |
122 |
|
|
return _times[getLastAlertLevel()]; |
123 |
ajm |
1.2 |
} |
124 |
|
|
|
125 |
|
|
/** |
126 |
ajm |
1.11 |
* Gets the time an alert was sent at the given level. |
127 |
ajm |
1.2 |
* |
128 |
|
|
* @param level the alert level to get |
129 |
|
|
* @param value the new time |
130 |
|
|
*/ |
131 |
ajm |
1.11 |
public void setTimeLastSent(long value) { |
132 |
|
|
_times[getLastAlertLevel()] = value; |
133 |
ajm |
1.2 |
} |
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 |
tdb |
1.4 |
// -1.0 means we don't use an alert level |
146 |
ajm |
1.2 |
double threshold = -1.0; |
147 |
tdb |
1.4 |
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 |
ajm |
1.2 |
} |
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 |
tdb |
1.4 |
* given level, this returns 0 |
171 |
ajm |
1.2 |
* |
172 |
|
|
* @param level the alert level |
173 |
|
|
* @param thresholdLevel the threshold leve we are on |
174 |
|
|
*/ |
175 |
ajm |
1.11 |
public long getAlertTimeout(int level) { |
176 |
tdb |
1.4 |
// 0 means we don't use this value |
177 |
ajm |
1.2 |
long timeout = 0; |
178 |
tdb |
1.4 |
try { |
179 |
|
|
String timeoutString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".alertTimeout." + Alert.alertLevels[level]); |
180 |
ajm |
1.11 |
int threshold = getLastThresholdLevel(); |
181 |
tdb |
1.4 |
if (threshold > 0) { |
182 |
|
|
timeout = (Long.parseLong(timeoutString) / threshold) * 1000; |
183 |
ajm |
1.2 |
} |
184 |
tdb |
1.4 |
} catch (PropertyNotFoundException e) { |
185 |
|
|
timeout = 0; |
186 |
|
|
} catch (NumberFormatException e) { |
187 |
|
|
timeout = 0; |
188 |
ajm |
1.2 |
} |
189 |
|
|
return timeout; |
190 |
ajm |
1.1 |
} |
191 |
|
|
|
192 |
ajm |
1.2 |
/** |
193 |
|
|
* Either advances to the next alert level, or if |
194 |
|
|
* the maximum alert level has been reached, simply returns |
195 |
|
|
* that. |
196 |
|
|
* |
197 |
ajm |
1.5 |
* 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 |
ajm |
1.2 |
*/ |
202 |
ajm |
1.11 |
public int getNextAlertLevel() { |
203 |
|
|
if((getLastAlertLevel() + 1) > (Alert.alertLevels.length - 2)) { |
204 |
|
|
return getLastAlertLevel(); |
205 |
ajm |
1.2 |
} |
206 |
ajm |
1.11 |
return getLastAlertLevel() + 1; |
207 |
ajm |
1.2 |
} |
208 |
|
|
|
209 |
|
|
/** |
210 |
ajm |
1.3 |
* Gets the timeout value of the last alert |
211 |
|
|
* sent |
212 |
|
|
* |
213 |
|
|
* @return the last timeout value |
214 |
|
|
*/ |
215 |
ajm |
1.11 |
public long getLastAlertTimeout() { |
216 |
|
|
return _lastAlertTimeout; |
217 |
ajm |
1.3 |
} |
218 |
|
|
|
219 |
|
|
/** |
220 |
|
|
* Sets the timeout value of the last alert |
221 |
|
|
* sent |
222 |
|
|
* |
223 |
|
|
* @param timeout the new value |
224 |
|
|
*/ |
225 |
ajm |
1.11 |
public void setLastAlertTimeout(long timeout) { |
226 |
|
|
_lastAlertTimeout = timeout; |
227 |
ajm |
1.3 |
} |
228 |
|
|
|
229 |
|
|
/** |
230 |
ajm |
1.6 |
* Returns the time that the first alert was sent |
231 |
|
|
* for an attribute that has passed a threshold value |
232 |
|
|
* |
233 |
|
|
*/ |
234 |
ajm |
1.11 |
public long getInitialAlertTime() { |
235 |
|
|
return _initialAlertTime; |
236 |
ajm |
1.6 |
} |
237 |
|
|
|
238 |
|
|
/** |
239 |
ajm |
1.2 |
* Advances the alert level to the next one up. |
240 |
|
|
* |
241 |
ajm |
1.5 |
* 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 |
ajm |
1.2 |
*/ |
258 |
ajm |
1.11 |
public void escalateAlert() { |
259 |
tdb |
1.7 |
// don't escalate if we're already on the last alert |
260 |
ajm |
1.11 |
if(getLastAlertLevel() != Alert.alertLevels.length -1) { |
261 |
|
|
setLastAlertLevel(getNextAlertLevel()); |
262 |
tdb |
1.7 |
} |
263 |
ajm |
1.5 |
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 |
ajm |
1.11 |
if (getLastAlertLevel() == Alert.alertLevels.length - 2) { |
267 |
ajm |
1.5 |
_maxLevelCount++; |
268 |
tdb |
1.10 |
if(_maxLevelCount > reachFINALcount) { |
269 |
ajm |
1.11 |
setLastAlertLevel(Alert.alertFINAL); |
270 |
tdb |
1.8 |
} |
271 |
ajm |
1.5 |
} |
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 |
ajm |
1.1 |
} |
278 |
|
|
|
279 |
|
|
//---ATTRIBUTES--- |
280 |
|
|
|
281 |
ajm |
1.2 |
/** |
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 |
ajm |
1.11 |
private int _lastAlertLevel; |
297 |
ajm |
1.2 |
|
298 |
|
|
/** |
299 |
|
|
* An array of last threshold levels for |
300 |
|
|
* each attribute this register is looking |
301 |
|
|
* after. |
302 |
|
|
*/ |
303 |
ajm |
1.11 |
private int _lastThresholdLevel; |
304 |
ajm |
1.3 |
|
305 |
|
|
/** |
306 |
|
|
* An array of last alert timeout levels for |
307 |
|
|
* each attribute this register is looking |
308 |
|
|
* after. |
309 |
|
|
*/ |
310 |
ajm |
1.11 |
private long _lastAlertTimeout; |
311 |
ajm |
1.2 |
|
312 |
|
|
/** |
313 |
|
|
* An array of arrays containing |
314 |
|
|
* time an alert of each level |
315 |
|
|
* was last sent for each attribute. |
316 |
|
|
*/ |
317 |
ajm |
1.11 |
private long[] _times; |
318 |
ajm |
1.6 |
|
319 |
|
|
/** |
320 |
|
|
* Initial times that an alert was first |
321 |
|
|
* raised. |
322 |
|
|
*/ |
323 |
ajm |
1.11 |
private long _initialAlertTime; |
324 |
ajm |
1.2 |
|
325 |
|
|
/** |
326 |
|
|
* A reference to the configuration proxy in use |
327 |
|
|
*/ |
328 |
|
|
private ConfigurationProxy _cp = ConfigurationProxy.getInstance(); |
329 |
ajm |
1.5 |
|
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 |
ajm |
1.1 |
|
338 |
|
|
//---STATIC ATTRIBUTES--- |
339 |
|
|
|
340 |
|
|
} |