1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* http://www.i-scream.org |
4 |
+ |
* Copyright (C) 2000-2002 i-scream |
5 |
+ |
* |
6 |
+ |
* This program is free software; you can redistribute it and/or |
7 |
+ |
* modify it under the terms of the GNU General Public License |
8 |
+ |
* as published by the Free Software Foundation; either version 2 |
9 |
+ |
* of the License, or (at your option) any later version. |
10 |
+ |
* |
11 |
+ |
* This program is distributed in the hope that it will be useful, |
12 |
+ |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
+ |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
+ |
* GNU General Public License for more details. |
15 |
+ |
* |
16 |
+ |
* You should have received a copy of the GNU General Public License |
17 |
+ |
* along with this program; if not, write to the Free Software |
18 |
+ |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
+ |
*/ |
20 |
+ |
|
21 |
|
//---PACKAGE DECLARATION--- |
22 |
< |
package uk.org.iscream.client.monitors; |
22 |
> |
package uk.org.iscream.cms.server.client.monitors; |
23 |
|
|
24 |
|
//---IMPORTS--- |
25 |
|
import java.util.HashMap; |
26 |
|
import java.util.Iterator; |
27 |
< |
import uk.org.iscream.client.*; |
28 |
< |
import uk.org.iscream.core.*; |
29 |
< |
import uk.org.iscream.util.*; |
30 |
< |
import uk.org.iscream.componentmanager.*; |
27 |
> |
import java.util.StringTokenizer; |
28 |
> |
import uk.org.iscream.cms.server.client.*; |
29 |
> |
import uk.org.iscream.cms.server.core.*; |
30 |
> |
import uk.org.iscream.cms.util.*; |
31 |
> |
import uk.org.iscream.cms.server.componentmanager.*; |
32 |
|
|
33 |
|
/** |
34 |
|
* This Monitor watches heartbeats. |
39 |
|
* for missing heartbeat's, and thus has an extra inner class |
40 |
|
* thread. |
41 |
|
* |
42 |
+ |
* This originally took "heartbeat" packets, but they've now |
43 |
+ |
* been deprecated. Instead we look at UDP packets, or, rather |
44 |
+ |
* the lack of them :-) |
45 |
+ |
* |
46 |
|
* @author $Author$ |
47 |
|
* @version $Id$ |
48 |
|
*/ |
76 |
|
*/ |
77 |
|
public Heartbeat__Monitor() { |
78 |
|
super(); |
79 |
+ |
createInitialHosts(); |
80 |
|
new HeartbeatWorker().start(); |
81 |
|
} |
82 |
|
|
90 |
|
*/ |
91 |
|
public void analysePacket(XMLPacket packet) { |
92 |
|
String source = packet.getParam("packet.attributes.machine_name"); |
93 |
+ |
if(!checkBooleanConfig("Host." + source, "Monitor." + _name + ".enable")) { |
94 |
+ |
return; |
95 |
+ |
} |
96 |
|
if (!_hosts.containsKey(source)) { |
97 |
|
synchronized(this) { |
98 |
|
_hosts.put(source, new HeartbeatHolder(new Register(source, _name))); |
106 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
107 |
|
* method to provide clean logging (every class should have this). |
108 |
|
* |
109 |
< |
* This uses the uk.org.iscream.util.NameFormat class |
109 |
> |
* This uses the uk.org.iscream.cms.util.NameFormat class |
110 |
|
* to format the toString() |
111 |
|
* |
112 |
|
* @return the name of this class and its CVS revision |
145 |
|
} |
146 |
|
return Alert.thresholdNORMAL; |
147 |
|
} |
148 |
+ |
|
149 |
+ |
/** |
150 |
+ |
* Gets an initial list of hosts from the config |
151 |
+ |
* and adds a fake set of heartbeats for them. |
152 |
+ |
* If the hosts don't respond within the timeout |
153 |
+ |
* period an alert will be raised. |
154 |
+ |
* |
155 |
+ |
* The effect of this is to allow us to know about |
156 |
+ |
* hosts which weren't on when we started up, and |
157 |
+ |
* will thus never have generated a heartbeat - yet |
158 |
+ |
* will still want to know they're not responding. |
159 |
+ |
*/ |
160 |
+ |
private void createInitialHosts() { |
161 |
+ |
// get the initial list of hosts from the config |
162 |
+ |
String initialHosts = ""; |
163 |
+ |
try { |
164 |
+ |
initialHosts = _cp.getProperty(_name, "Monitor.Heartbeat.initialHosts"); |
165 |
+ |
} catch (PropertyNotFoundException e) { |
166 |
+ |
// just leave initialHosts empty |
167 |
+ |
_logger.write(Heartbeat__Monitor.this.toString(), Logger.DEBUG, "No initial list of hosts set, defaulting to none."); |
168 |
+ |
} |
169 |
+ |
|
170 |
+ |
// parse through the initial hosts adding them |
171 |
+ |
StringTokenizer st = new StringTokenizer(initialHosts, ";"); |
172 |
+ |
while (st.hasMoreTokens()) { |
173 |
+ |
String source = st.nextToken(); |
174 |
+ |
// check if they already exist, don't want to add them twice |
175 |
+ |
if (!_hosts.containsKey(source)) { |
176 |
+ |
synchronized(this) { |
177 |
+ |
_hosts.put(source, new HeartbeatHolder(new Register(source, _name))); |
178 |
+ |
} |
179 |
+ |
} |
180 |
+ |
HeartbeatHolder lastHeartbeat = (HeartbeatHolder) _hosts.get(source); |
181 |
+ |
// set a "fake" heartbeat |
182 |
+ |
lastHeartbeat.setLastHeartbeat(System.currentTimeMillis()/1000); |
183 |
+ |
} |
184 |
+ |
} |
185 |
|
|
186 |
|
//---ACCESSOR/MUTATOR METHODS--- |
187 |
|
|
192 |
|
* @return a reference to a Queue to get data from |
193 |
|
*/ |
194 |
|
protected Queue getQueue() { |
195 |
< |
return MonitorManager.getInstance().getHeartbeatQueue(); |
195 |
> |
return MonitorManager.getInstance().getDataQueue(); |
196 |
|
} |
197 |
|
|
198 |
|
//---ATTRIBUTES--- |
339 |
|
// this should always exist, thus we set to 0 |
340 |
|
int hostHBinterval = 0; |
341 |
|
try { |
342 |
< |
hostHBinterval = Integer.parseInt(cp.getProperty("Host."+source, "Host.TCPUpdateTime")); |
342 |
> |
hostHBinterval = Integer.parseInt(cp.getProperty("Host."+source, "Host.UDPUpdateTime")); |
343 |
|
} catch (PropertyNotFoundException e) { |
344 |
|
hostHBinterval = 0; |
345 |
< |
_logger.write(Heartbeat__Monitor.this.toString(), Logger.WARNING, "TCPUpdateTime value unavailable using default of " + hostHBinterval + " seconds"); |
345 |
> |
_logger.write(Heartbeat__Monitor.this.toString(), Logger.WARNING, "UDPUpdateTime value unavailable using default of " + hostHBinterval + " seconds"); |
346 |
|
} catch (NumberFormatException e) { |
347 |
|
hostHBinterval = 0; |
348 |
< |
_logger.write(Heartbeat__Monitor.this.toString(), Logger.WARNING, "Erronous TCPUpdateTime value in configuration using default of " + hostHBinterval + " seconds"); |
348 |
> |
_logger.write(Heartbeat__Monitor.this.toString(), Logger.WARNING, "Erronous UDPUpdateTime value in configuration using default of " + hostHBinterval + " seconds"); |
349 |
|
} |
350 |
|
|
351 |
|
// get host's last HB time (seconds) |