1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
package uk.ac.ukc.iscream.client.monitors; |
2 |
> |
package uk.org.iscream.client.monitors; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
|
import java.util.HashMap; |
6 |
|
import java.util.Iterator; |
7 |
< |
import uk.ac.ukc.iscream.client.*; |
8 |
< |
import uk.ac.ukc.iscream.core.*; |
9 |
< |
import uk.ac.ukc.iscream.util.*; |
10 |
< |
import uk.ac.ukc.iscream.componentmanager.*; |
7 |
> |
import uk.org.iscream.client.*; |
8 |
> |
import uk.org.iscream.core.*; |
9 |
> |
import uk.org.iscream.util.*; |
10 |
> |
import uk.org.iscream.componentmanager.*; |
11 |
|
|
12 |
|
/** |
13 |
|
* This Monitor watches heartbeats |
53 |
|
_logger.write(toString(), Logger.WARNING, "Erronous Monitor.Heartbeat.checkPeriod value in configuration using default of " + checkPeriod + " seconds"); |
54 |
|
} |
55 |
|
|
56 |
< |
// perform the checks (use HB hash, although they *should* be the same) |
57 |
< |
Iterator i = _hosts.keySet().iterator(); |
58 |
< |
while(i.hasNext()) { |
59 |
< |
// get host |
60 |
< |
String source = (String) i.next(); |
61 |
< |
// check it |
62 |
< |
boolean remove = analyseHB(source); |
63 |
< |
if(remove) { |
64 |
< |
i.remove(); |
56 |
> |
synchronized(this) { |
57 |
> |
// perform the checks (use HB hash, although they *should* be the same) |
58 |
> |
Iterator i = _hosts.keySet().iterator(); |
59 |
> |
while(i.hasNext()) { |
60 |
> |
// get host |
61 |
> |
String source = (String) i.next(); |
62 |
> |
// check it |
63 |
> |
boolean remove = analyseHB(source); |
64 |
> |
if(remove) { |
65 |
> |
i.remove(); |
66 |
> |
} |
67 |
|
} |
68 |
|
} |
69 |
|
|
76 |
|
if (packet.getParam("packet.attributes.type").equals("heartbeat")) { |
77 |
|
String source = packet.getParam("packet.attributes.machine_name"); |
78 |
|
if (!_hosts.containsKey(source)) { |
79 |
< |
HashMap registerHash = new HashMap(); |
80 |
< |
registerHash.put(source, new Register(source, _name, 1)); |
81 |
< |
_hosts.put(source, new HeartbeatHolder(registerHash)); |
79 |
> |
synchronized(this) { |
80 |
> |
HashMap registerHash = new HashMap(); |
81 |
> |
registerHash.put(source, new Register(source, _name)); |
82 |
> |
_hosts.put(source, new HeartbeatHolder(registerHash)); |
83 |
> |
} |
84 |
|
} |
85 |
|
HeartbeatHolder lastHeartbeat = (HeartbeatHolder) _hosts.get(source); |
86 |
|
lastHeartbeat.setLastHeartbeat(System.currentTimeMillis()/1000); |
91 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
92 |
|
* method to provide clean logging (every class should have this). |
93 |
|
* |
94 |
< |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
94 |
> |
* This uses the uk.org.iscream.util.NameFormat class |
95 |
|
* to format the toString() |
96 |
|
* |
97 |
|
* @return the name of this class and its CVS revision |
134 |
|
long lastHeartbeat = hbHolder.getLastHeartbeat(); |
135 |
|
// time since last heartbeat (seconds) |
136 |
|
long timeSinceLastHB = (System.currentTimeMillis()/1000) - lastHeartbeat; |
137 |
+ |
// time since (or until if negative) the expected heartbeat |
138 |
+ |
long timeSinceExpectedHB = timeSinceLastHB - (long) hostHBinterval; |
139 |
|
|
140 |
+ |
// best do a check in case the expected heartbeat is in the future |
141 |
+ |
if(timeSinceExpectedHB < 0) { |
142 |
+ |
timeSinceExpectedHB = 0; |
143 |
+ |
} |
144 |
+ |
|
145 |
|
// find out the threshold level we're at |
146 |
< |
int newThreshold = checkAttributeThreshold(timeSinceLastHB, reg); |
146 |
> |
int newThreshold = checkAttributeThreshold(timeSinceExpectedHB, reg); |
147 |
|
|
148 |
|
// process the alert |
149 |
< |
processAlert(newThreshold, 0, "Heartbeat", reg, source, String.valueOf(timeSinceLastHB)); |
149 |
> |
processAlert(newThreshold, "Heartbeat", reg, source, String.valueOf(timeSinceExpectedHB)); |
150 |
|
|
151 |
< |
if(reg.getLastAlertLevel(0) == Alert.alertFINAL) { |
151 |
> |
if(reg.getLastAlertLevel() == Alert.alertFINAL) { |
152 |
|
return true; |
153 |
|
} |
154 |
|
return false; |