33 |
|
//---CONSTRUCTORS--- |
34 |
|
|
35 |
|
public Heartbeat__Monitor() { |
36 |
< |
new Thread(this).start(); |
36 |
> |
super(); |
37 |
|
new HeartbeatWorker().start(); |
38 |
|
} |
39 |
|
|
76 |
|
} |
77 |
|
|
78 |
|
//---PRIVATE METHODS--- |
79 |
– |
|
80 |
– |
private boolean analyseHB(String source) { |
81 |
– |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
82 |
– |
HeartbeatHolder hbHolder = (HeartbeatHolder) _hosts.get(source); |
83 |
– |
Register reg = (Register) ((HashMap) hbHolder.getRegisterHash()).get(source); |
84 |
– |
|
85 |
– |
// get host's HB interval (seconds) |
86 |
– |
// this should always exist, thus we set to 0 |
87 |
– |
int hostHBinterval = 0; |
88 |
– |
try { |
89 |
– |
hostHBinterval = Integer.parseInt(cp.getProperty("Host."+source, "Host.TCPUpdateTime")); |
90 |
– |
} catch (PropertyNotFoundException e) { |
91 |
– |
hostHBinterval = 0; |
92 |
– |
_logger.write(toString(), Logger.WARNING, "TCPUpdateTime value unavailable using default of " + hostHBinterval + " seconds"); |
93 |
– |
} catch (NumberFormatException e) { |
94 |
– |
hostHBinterval = 0; |
95 |
– |
_logger.write(toString(), Logger.WARNING, "Erronous TCPUpdateTime value in configuration using default of " + hostHBinterval + " seconds"); |
96 |
– |
} |
97 |
– |
|
98 |
– |
// get host's last HB time (seconds) |
99 |
– |
long lastHeartbeat = hbHolder.getLastHeartbeat(); |
100 |
– |
// time since last heartbeat (seconds) |
101 |
– |
long timeSinceLastHB = (System.currentTimeMillis()/1000) - lastHeartbeat; |
102 |
– |
// time since (or until if negative) the expected heartbeat |
103 |
– |
long timeSinceExpectedHB = timeSinceLastHB - (long) hostHBinterval; |
104 |
– |
|
105 |
– |
// best do a check in case the expected heartbeat is in the future |
106 |
– |
if(timeSinceExpectedHB < 0) { |
107 |
– |
timeSinceExpectedHB = 0; |
108 |
– |
} |
109 |
– |
|
110 |
– |
// find out the threshold level we're at |
111 |
– |
int newThreshold = checkAttributeThreshold(timeSinceExpectedHB, reg); |
112 |
– |
|
113 |
– |
// process the alert |
114 |
– |
processAlert(newThreshold, "Heartbeat", reg, source, String.valueOf(timeSinceExpectedHB)); |
115 |
– |
|
116 |
– |
if(reg.getLastAlertLevel() == Alert.alertFINAL) { |
117 |
– |
return true; |
118 |
– |
} |
119 |
– |
return false; |
120 |
– |
} |
79 |
|
|
80 |
|
private int checkAttributeThreshold(long timeSinceLastHB, Register reg) { |
81 |
|
for(int thresholdLevel = Alert.thresholdLevels.length - 1; thresholdLevel >= 0; thresholdLevel--) { |
177 |
|
try {Thread.sleep(checkPeriod * 1000);} catch (InterruptedException e) {} |
178 |
|
} |
179 |
|
} |
180 |
+ |
|
181 |
+ |
private boolean analyseHB(String source) { |
182 |
+ |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
183 |
+ |
HeartbeatHolder hbHolder = (HeartbeatHolder) _hosts.get(source); |
184 |
+ |
Register reg = (Register) ((HashMap) hbHolder.getRegisterHash()).get(source); |
185 |
+ |
|
186 |
+ |
// get host's HB interval (seconds) |
187 |
+ |
// this should always exist, thus we set to 0 |
188 |
+ |
int hostHBinterval = 0; |
189 |
+ |
try { |
190 |
+ |
hostHBinterval = Integer.parseInt(cp.getProperty("Host."+source, "Host.TCPUpdateTime")); |
191 |
+ |
} catch (PropertyNotFoundException e) { |
192 |
+ |
hostHBinterval = 0; |
193 |
+ |
_logger.write(this.toString(), Logger.WARNING, "TCPUpdateTime value unavailable using default of " + hostHBinterval + " seconds"); |
194 |
+ |
} catch (NumberFormatException e) { |
195 |
+ |
hostHBinterval = 0; |
196 |
+ |
_logger.write(this.toString(), Logger.WARNING, "Erronous TCPUpdateTime value in configuration using default of " + hostHBinterval + " seconds"); |
197 |
+ |
} |
198 |
+ |
|
199 |
+ |
// get host's last HB time (seconds) |
200 |
+ |
long lastHeartbeat = hbHolder.getLastHeartbeat(); |
201 |
+ |
// time since last heartbeat (seconds) |
202 |
+ |
long timeSinceLastHB = (System.currentTimeMillis()/1000) - lastHeartbeat; |
203 |
+ |
// time since (or until if negative) the expected heartbeat |
204 |
+ |
long timeSinceExpectedHB = timeSinceLastHB - (long) hostHBinterval; |
205 |
+ |
|
206 |
+ |
// best do a check in case the expected heartbeat is in the future |
207 |
+ |
if(timeSinceExpectedHB < 0) { |
208 |
+ |
timeSinceExpectedHB = 0; |
209 |
+ |
} |
210 |
+ |
|
211 |
+ |
// find out the threshold level we're at |
212 |
+ |
int newThreshold = checkAttributeThreshold(timeSinceExpectedHB, reg); |
213 |
+ |
|
214 |
+ |
// process the alert |
215 |
+ |
processAlert(newThreshold, "Heartbeat", reg, source, String.valueOf(timeSinceExpectedHB)); |
216 |
+ |
|
217 |
+ |
if(reg.getLastAlertLevel() == Alert.alertFINAL) { |
218 |
+ |
return true; |
219 |
+ |
} |
220 |
+ |
return false; |
221 |
+ |
} |
222 |
|
} |
223 |
– |
|
223 |
|
} |