15 |
|
* @author $Author$ |
16 |
|
* @version $Id$ |
17 |
|
*/ |
18 |
< |
public class Heartbeat__Monitor extends Thread implements PluginMonitor { |
18 |
> |
public class Heartbeat__Monitor implements PluginMonitor, Runnable { |
19 |
|
|
20 |
|
//---FINAL ATTRIBUTES--- |
21 |
|
|
26 |
|
|
27 |
|
public final String DESC = "Monitors Heartbeats."; |
28 |
|
|
29 |
+ |
public final int DEFAULT_CHECK_PERIOD = 60; |
30 |
+ |
|
31 |
|
//---STATIC METHODS--- |
32 |
|
|
33 |
|
//---CONSTRUCTORS--- |
34 |
|
|
35 |
+ |
public Heartbeat__Monitor() { |
36 |
+ |
new Thread(this).start(); |
37 |
+ |
} |
38 |
+ |
|
39 |
|
//---PUBLIC METHODS--- |
40 |
|
|
41 |
|
public void run() { |
42 |
|
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
43 |
|
while(true) { |
44 |
< |
// this cycle period could be done better, maybe ? |
45 |
< |
int checkPeriod = Integer.parseInt(cp.getProperty(_name, "Monitor.Heartbeat.checkPeriod")); |
44 |
> |
// this cycle period of this monitor's checks |
45 |
> |
int checkPeriod = 0; |
46 |
> |
try { |
47 |
> |
checkPeriod = Integer.parseInt(cp.getProperty(_name, "Monitor.Heartbeat.checkPeriod")); |
48 |
> |
} catch (PropertyNotFoundException e) { |
49 |
> |
checkPeriod = DEFAULT_CHECK_PERIOD; |
50 |
> |
_logger.write(toString(), Logger.WARNING, "Monitor.Heartbeat.checkPeriod value unavailable using default of " + checkPeriod + " seconds"); |
51 |
> |
} catch (NumberFormatException e) { |
52 |
> |
checkPeriod = DEFAULT_CHECK_PERIOD; |
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 = _hostsHB.keySet().iterator(); |
73 |
|
Register reg = (Register) _hostsReg.get(source); |
74 |
|
|
75 |
|
// get host's HB interval (seconds) |
76 |
< |
int hostHBinterval = Integer.parseInt(cp.getProperty("Host."+source, "TCPUpdateTime")); |
76 |
> |
// this should always exist, thus we set to 0 |
77 |
> |
int hostHBinterval = 0; |
78 |
> |
try { |
79 |
> |
hostHBinterval = Integer.parseInt(cp.getProperty("Host."+source, "Host.TCPUpdateTime")); |
80 |
> |
} catch (PropertyNotFoundException e) { |
81 |
> |
hostHBinterval = 0; |
82 |
> |
_logger.write(toString(), Logger.WARNING, "TCPUpdateTime value unavailable using default of " + hostHBinterval + " seconds"); |
83 |
> |
} catch (NumberFormatException e) { |
84 |
> |
hostHBinterval = 0; |
85 |
> |
_logger.write(toString(), Logger.WARNING, "Erronous TCPUpdateTime value in configuration using default of " + hostHBinterval + " seconds"); |
86 |
> |
} |
87 |
> |
|
88 |
|
// get host's last HB time (seconds) |
89 |
< |
int lastHeartbeat = ((HeartbeatHolder) _hostsHB.get(source)).getLastHeartbeat(); |
89 |
> |
long lastHeartbeat = ((HeartbeatHolder) _hostsHB.get(source)).getLastHeartbeat(); |
90 |
|
// time since last heartbeat (seconds) |
91 |
< |
int timeSinceLastHB = ((int) (System.currentTimeMillis()/1000)) - lastHeartbeat; |
91 |
> |
long timeSinceLastHB = (System.currentTimeMillis()/1000) - lastHeartbeat; |
92 |
|
|
93 |
|
// find out the threshold level we're at |
94 |
|
int result = checkAttributeThreshold(timeSinceLastHB, reg); |
150 |
|
_hostsReg.put(source, new Register(source, _name, 1)); |
151 |
|
_hostsHB.put(source, new HeartbeatHolder()); |
152 |
|
} |
153 |
< |
HeartbeatHolder lastHeartbeat = (HeartbeatHolder) _hostsReg.get(source); |
154 |
< |
lastHeartbeat.setLastHeartbeat((int)System.currentTimeMillis()/1000); |
153 |
> |
HeartbeatHolder lastHeartbeat = (HeartbeatHolder) _hostsHB.get(source); |
154 |
> |
lastHeartbeat.setLastHeartbeat(System.currentTimeMillis()/1000); |
155 |
|
} |
156 |
|
} |
157 |
|
|
180 |
|
|
181 |
|
//---PRIVATE METHODS--- |
182 |
|
|
183 |
< |
private int checkAttributeThreshold(int timeSinceLastHB, Register reg) { |
183 |
> |
private int checkAttributeThreshold(long timeSinceLastHB, Register reg) { |
184 |
|
for(int thresholdLevel = Alert.thresholdLevels.length - 1; thresholdLevel >= 0; thresholdLevel--) { |
185 |
|
if (reg.getThreshold(thresholdLevel) != -1.0) { |
186 |
< |
if (reg.getThreshold(thresholdLevel) < timeSinceLastHB) { |
186 |
> |
if (((long) reg.getThreshold(thresholdLevel)) < timeSinceLastHB) { |
187 |
|
return thresholdLevel; |
188 |
|
} |
189 |
|
} |
191 |
|
return 0; |
192 |
|
} |
193 |
|
|
194 |
< |
private void fireAlert(String source, int timeSinceLastHB, Register reg, int lastAlert) { |
194 |
> |
private void fireAlert(String source, long timeSinceLastHB, Register reg, int lastAlert) { |
195 |
|
int alertLevel = reg.getLastAlertLevel(0); |
196 |
|
int thresholdLevel = reg.getLastThresholdLevel(0); |
197 |
|
String currentValue = String.valueOf(timeSinceLastHB); |
246 |
|
|
247 |
|
private class HeartbeatHolder { |
248 |
|
|
249 |
< |
public void setLastHeartbeat(int lastHeartbeat) { |
249 |
> |
public void setLastHeartbeat(long lastHeartbeat) { |
250 |
|
_lastHeartbeat = lastHeartbeat; |
251 |
|
} |
252 |
|
|
253 |
< |
public int getLastHeartbeat() { |
253 |
> |
public long getLastHeartbeat() { |
254 |
|
return _lastHeartbeat; |
255 |
|
} |
256 |
|
|
257 |
< |
private int _lastHeartbeat; |
257 |
> |
private long _lastHeartbeat; |
258 |
|
} |
259 |
|
|
260 |
|
} |