3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
|
import uk.ac.ukc.iscream.util.*; |
6 |
< |
import uk.ac.ukc.iscream.componentmanager.ConfigurationProxy; |
6 |
> |
import uk.ac.ukc.iscream.componentmanager.*; |
7 |
|
|
8 |
|
/** |
9 |
|
* The Register class holds theshold values, |
46 |
|
_monitorName = monitorName; |
47 |
|
_lastAlertLevels = new int[numAttributes]; |
48 |
|
_lastThresholdLevels = new int[numAttributes]; |
49 |
+ |
_initialAlertTime = new long[numAttributes]; |
50 |
|
_lastAlertTimeout = new long[numAttributes]; |
51 |
|
_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 |
+ |
_initialAlertTime[x] = 0; |
56 |
|
_lastThresholdLevels[x] = 0; |
57 |
|
_lastAlertTimeout[x] = 0; |
58 |
|
for(int y = 0; y < Alert.alertLevels.length; y++) { |
106 |
|
* Sets the last alert level for the |
107 |
|
* given attribute. |
108 |
|
* |
109 |
+ |
* Note that if this is setting to an OK |
110 |
+ |
* level alert, it resets _maxLevelCount. |
111 |
+ |
* |
112 |
+ |
* 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 |
|
* @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 |
+ |
if (level == Alert.alertOK) { |
122 |
+ |
_maxLevelCount = 0; |
123 |
+ |
_initialAlertTime[attributeNum] = 0; |
124 |
+ |
} |
125 |
+ |
if (level == Alert.alertOK + 1) { |
126 |
+ |
_initialAlertTime[attributeNum] = System.currentTimeMillis(); |
127 |
+ |
} |
128 |
|
} |
129 |
|
|
130 |
|
/** |
162 |
|
* @param level the alert level |
163 |
|
*/ |
164 |
|
public double getThreshold(int level) { |
165 |
+ |
// -1.0 means we don't use an alert level |
166 |
|
double threshold = -1.0; |
167 |
< |
String thresholdString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".threshold." + Alert.thresholdLevels[level]); |
168 |
< |
if(thresholdString != null) { |
169 |
< |
try { |
170 |
< |
threshold = Double.parseDouble(thresholdString); |
171 |
< |
} catch (NumberFormatException e) { |
172 |
< |
// -1.0 means we don't use an alert level |
173 |
< |
threshold = -1.0; |
157 |
< |
} |
167 |
> |
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 |
|
} |
175 |
|
return threshold; |
176 |
|
} |
187 |
|
* progress faster should a higher threshold value be passed |
188 |
|
* |
189 |
|
* If there is no alert timeout for a |
190 |
< |
* given level, this returns -1.0 |
190 |
> |
* given level, this returns 0 |
191 |
|
* |
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 |
+ |
// 0 means we don't use this value |
197 |
|
long timeout = 0; |
198 |
< |
String timeoutString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".alertTimeout." + Alert.alertLevels[level]); |
199 |
< |
if(timeoutString != null) { |
200 |
< |
try { |
201 |
< |
int threshold = getLastThresholdLevel(attributeNum); |
202 |
< |
if (threshold > 0) { |
186 |
< |
timeout = (Long.parseLong(timeoutString) / threshold) * 1000; |
187 |
< |
} |
188 |
< |
} catch (NumberFormatException e) { |
189 |
< |
// -1.0 means we don't use this value |
190 |
< |
timeout = 0; |
198 |
> |
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 |
|
} |
204 |
+ |
} catch (PropertyNotFoundException e) { |
205 |
+ |
timeout = 0; |
206 |
+ |
} catch (NumberFormatException e) { |
207 |
+ |
timeout = 0; |
208 |
|
} |
209 |
|
return timeout; |
210 |
|
} |
214 |
|
* the maximum alert level has been reached, simply returns |
215 |
|
* that. |
216 |
|
* |
217 |
+ |
* 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 |
|
* @param attributeNum the attribute to get next alert for |
222 |
|
*/ |
223 |
|
public int getNextAlertLevel(int attributeNum) { |
224 |
< |
if((getLastAlertLevel(attributeNum) + 1) > (Alert.alertLevels.length - 1)) { |
224 |
> |
if((getLastAlertLevel(attributeNum) + 1) > (Alert.alertLevels.length - 2)) { |
225 |
|
return getLastAlertLevel(attributeNum); |
226 |
|
} |
227 |
|
return getLastAlertLevel(attributeNum) + 1; |
250 |
|
} |
251 |
|
|
252 |
|
/** |
253 |
+ |
* 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 |
|
* Advances the alert level to the next one up. |
264 |
|
* |
265 |
+ |
* 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 |
|
* @param attributeNum the attribute to advance the alert for |
282 |
|
*/ |
283 |
|
public void escalateAlert(int attributeNum) { |
284 |
< |
setLastAlertLevel(attributeNum, getNextAlertLevel(attributeNum)); |
284 |
> |
// don't escalate if we're already on the last alert |
285 |
> |
if(getLastAlertLevel(attributeNum) != Alert.alertLevels.length -1) { |
286 |
> |
setLastAlertLevel(attributeNum, getNextAlertLevel(attributeNum)); |
287 |
> |
} |
288 |
> |
try { |
289 |
> |
// note if we fail to get this value, we won't process the res of this |
290 |
> |
int reachFINALcount = Integer.parseInt(_cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".reachFINALcount")); |
291 |
> |
if (getLastAlertLevel(attributeNum) == Alert.alertLevels.length - 2) { |
292 |
> |
_maxLevelCount++; |
293 |
> |
if(_maxLevelCount >= reachFINALcount) { |
294 |
> |
setLastAlertLevel(attributeNum, Alert.alertFINAL); |
295 |
> |
} |
296 |
> |
} |
297 |
> |
} catch (PropertyNotFoundException e) { |
298 |
> |
// we NEVER reach FINAL in this case |
299 |
> |
} catch (NumberFormatException e) { |
300 |
> |
// we NEVER reach FINAL in this case |
301 |
> |
} |
302 |
|
} |
303 |
|
|
304 |
|
//---ATTRIBUTES--- |
340 |
|
* was last sent for each attribute. |
341 |
|
*/ |
342 |
|
private long[][] _times; |
343 |
+ |
|
344 |
+ |
/** |
345 |
+ |
* Initial times that an alert was first |
346 |
+ |
* raised. |
347 |
+ |
*/ |
348 |
+ |
private long[] _initialAlertTime; |
349 |
|
|
350 |
|
/** |
351 |
|
* A reference to the configuration proxy in use |
352 |
|
*/ |
353 |
|
private ConfigurationProxy _cp = ConfigurationProxy.getInstance(); |
354 |
+ |
|
355 |
+ |
/** |
356 |
+ |
* The number of times the maximum level alert |
357 |
+ |
* has occured IN A ROW, this is escalated by |
358 |
+ |
* the escalate(int) method, and reset by the |
359 |
+ |
* setLastAlertLevel(int, int) method |
360 |
+ |
*/ |
361 |
+ |
private int _maxLevelCount = 0; |
362 |
|
|
363 |
|
//---STATIC ATTRIBUTES--- |
364 |
|
|