1 |
tdb |
1.1 |
/* |
2 |
|
|
* i-scream central monitoring system |
3 |
|
|
* http://www.i-scream.org.uk |
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.cms.server.client.monitors; |
23 |
|
|
|
24 |
|
|
//---IMPORTS--- |
25 |
|
|
import java.util.HashMap; |
26 |
|
|
import java.util.HashSet; |
27 |
|
|
import java.util.Set; |
28 |
|
|
import java.util.Iterator; |
29 |
|
|
import uk.org.iscream.cms.server.client.*; |
30 |
|
|
import uk.org.iscream.cms.server.core.*; |
31 |
|
|
import uk.org.iscream.cms.util.*; |
32 |
|
|
import uk.org.iscream.cms.server.componentmanager.*; |
33 |
|
|
|
34 |
|
|
/** |
35 |
|
|
* This Monitor watches the Disks for all machines |
36 |
|
|
* |
37 |
|
|
* @author $Author$ |
38 |
|
|
* @version $Id$ |
39 |
|
|
*/ |
40 |
|
|
public class DiskIO__Monitor extends MonitorSkeleton { |
41 |
|
|
|
42 |
|
|
//---FINAL ATTRIBUTES--- |
43 |
|
|
|
44 |
|
|
/** |
45 |
|
|
* The current CVS revision of this class |
46 |
|
|
*/ |
47 |
|
|
public final String REVISION = "$Revision: 1.1 $"; |
48 |
|
|
|
49 |
|
|
/** |
50 |
|
|
* A description of this monitor |
51 |
|
|
*/ |
52 |
|
|
public final String DESC = "Monitors disk IO on all hosts."; |
53 |
|
|
|
54 |
|
|
//---STATIC METHODS--- |
55 |
|
|
|
56 |
|
|
//---CONSTRUCTORS--- |
57 |
|
|
|
58 |
|
|
//---PUBLIC METHODS--- |
59 |
|
|
|
60 |
|
|
/** |
61 |
|
|
* Analyse a packet of data, and generate an alert if |
62 |
|
|
* necessary. |
63 |
|
|
* |
64 |
|
|
* @param packet the XMLPacket to analyse |
65 |
|
|
*/ |
66 |
|
|
public void analysePacket(XMLPacket packet) { |
67 |
|
|
String source = packet.getParam("packet.attributes.machine_name"); |
68 |
|
|
if (!_hostsR.containsKey(source)) { |
69 |
|
|
_hostsR.put(source, new HashMap()); |
70 |
|
|
} |
71 |
|
|
if (!_hostsW.containsKey(source)) { |
72 |
|
|
_hostsW.put(source, new HashMap()); |
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
HashMap diskRegistersR = (HashMap) _hostsR.get(source); |
76 |
|
|
HashMap diskRegistersW = (HashMap) _hostsW.get(source); |
77 |
|
|
|
78 |
|
|
// key prefix |
79 |
|
|
String keyPrefix = "packet.diskio.p"; |
80 |
|
|
|
81 |
|
|
// a temporary holder for all the disk attributes we find |
82 |
|
|
HashSet disks = new HashSet(); |
83 |
|
|
|
84 |
|
|
// unfortunatly we need to check the whole packet |
85 |
|
|
// to find the disks, and then get the data attributes |
86 |
|
|
Set packetSet = packet.getSet(); |
87 |
|
|
Iterator i = packetSet.iterator(); |
88 |
|
|
while (i.hasNext()) { |
89 |
|
|
String dataKey = (String) i.next(); |
90 |
|
|
if(dataKey.startsWith(keyPrefix)) { |
91 |
|
|
// pos is after "packet.diskio.p" |
92 |
|
|
int pos = keyPrefix.length(); |
93 |
|
|
String diskNumber = dataKey.substring(pos, dataKey.indexOf('.', pos)); |
94 |
|
|
String thisDisk = keyPrefix.concat(diskNumber); |
95 |
|
|
|
96 |
|
|
if(!disks.contains(thisDisk)) { |
97 |
|
|
// add the disk to our list |
98 |
|
|
disks.add(thisDisk); |
99 |
|
|
|
100 |
|
|
String name = packet.getParam(thisDisk + ".attributes.name"); |
101 |
|
|
|
102 |
|
|
String rbytes = packet.getParam(thisDisk + ".attributes.rbytes"); |
103 |
|
|
String wbytes = packet.getParam(thisDisk + ".attributes.wbytes"); |
104 |
|
|
|
105 |
|
|
// *** now process this disk *** |
106 |
|
|
|
107 |
|
|
// check if we've seen this disk before on a previous run |
108 |
|
|
// if not, we need to create a register for it |
109 |
|
|
if(!diskRegistersR.containsKey(name)) { |
110 |
|
|
diskRegistersR.put(name, new Register(source, _name + ".rbytes", name)); |
111 |
|
|
} |
112 |
|
|
if(!diskRegistersW.containsKey(name)) { |
113 |
|
|
diskRegistersW.put(name, new Register(source, _name + ".wbytes", name)); |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
// get the register for this disk |
117 |
|
|
Register regR = (Register) diskRegistersR.get(name); |
118 |
|
|
Register regW = (Register) diskRegistersW.get(name); |
119 |
|
|
|
120 |
|
|
// get the packet data |
121 |
|
|
int diskRbytes, diskWbytes; |
122 |
|
|
try { |
123 |
|
|
if(rbytes==null || wbytes==null) { |
124 |
|
|
throw new NumberFormatException("Disk data invalid"); |
125 |
|
|
} |
126 |
|
|
diskRbytes = Integer.parseInt(rbytes); |
127 |
|
|
diskWbytes = Integer.parseInt(wbytes); |
128 |
|
|
} catch (NumberFormatException e) { |
129 |
|
|
_logger.write(this.toString(), Logger.WARNING, "Received packet from "+source+" with bad diskio information: "+e); |
130 |
|
|
// don't try to continue and process, try next disk |
131 |
|
|
break; |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
int newThresholdR = checkAttributeThreshold(diskRbytes, regR); |
135 |
|
|
int newThresholdW = checkAttributeThreshold(diskWbytes, regW); |
136 |
|
|
|
137 |
|
|
// say which disk had the problem |
138 |
|
|
String attributeNameR = "Disk read bytes on " + name; |
139 |
|
|
String attributeNameW = "Disk write bytes on " + name; |
140 |
|
|
|
141 |
|
|
processAlert(newThresholdR, attributeNameR, regR, source, String.valueOf(diskRbytes)); |
142 |
|
|
processAlert(newThresholdW, attributeNameW, regW, source, String.valueOf(diskWbytes)); |
143 |
|
|
} |
144 |
|
|
} |
145 |
|
|
} |
146 |
|
|
} |
147 |
|
|
|
148 |
|
|
/** |
149 |
|
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
150 |
|
|
* method to provide clean logging (every class should have this). |
151 |
|
|
* |
152 |
|
|
* This uses the uk.org.iscream.cms.util.NameFormat class |
153 |
|
|
* to format the toString() |
154 |
|
|
* |
155 |
|
|
* @return the name of this class and its CVS revision |
156 |
|
|
*/ |
157 |
|
|
public String toString() { |
158 |
|
|
return FormatName.getName( |
159 |
|
|
_name, |
160 |
|
|
getClass().getName(), |
161 |
|
|
REVISION); |
162 |
|
|
} |
163 |
|
|
|
164 |
|
|
/** |
165 |
|
|
* return the String representation of what the monitor does |
166 |
|
|
*/ |
167 |
|
|
public String getDescription(){ |
168 |
|
|
return DESC; |
169 |
|
|
} |
170 |
|
|
|
171 |
|
|
//---PRIVATE METHODS--- |
172 |
|
|
|
173 |
|
|
/** |
174 |
|
|
* Checks a piece of current data, and returns the |
175 |
|
|
* threshold it breaches, if any. |
176 |
|
|
* |
177 |
|
|
* @param value the current value |
178 |
|
|
* @param reg the Register for the host |
179 |
|
|
* @return the threshold level breached, if any |
180 |
|
|
*/ |
181 |
|
|
private int checkAttributeThreshold(double value, Register reg) { |
182 |
|
|
for(int thresholdLevel = Alert.thresholdLevels.length - 1; thresholdLevel >= 0; thresholdLevel--) { |
183 |
|
|
if (reg.getThreshold(thresholdLevel) != -1.0) { |
184 |
|
|
// normal check - has the value gone *over* the threshold |
185 |
|
|
if(((double) reg.getThreshold(thresholdLevel)) < value) { |
186 |
|
|
return thresholdLevel; |
187 |
|
|
} |
188 |
|
|
} |
189 |
|
|
} |
190 |
|
|
return Alert.thresholdNORMAL; |
191 |
|
|
} |
192 |
|
|
|
193 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
194 |
|
|
|
195 |
|
|
/** |
196 |
|
|
* Returns a reference to a specific Queue for this |
197 |
|
|
* monitor. This Queue returns only the data packets |
198 |
|
|
* (based on type) that we want too look at. |
199 |
|
|
* |
200 |
|
|
* @return a reference to a Queue |
201 |
|
|
*/ |
202 |
|
|
protected Queue getQueue() { |
203 |
|
|
return MonitorManager.getInstance().getDataQueue(); |
204 |
|
|
} |
205 |
|
|
|
206 |
|
|
//---ATTRIBUTES--- |
207 |
|
|
|
208 |
|
|
/** |
209 |
|
|
* This is the friendly identifier of the |
210 |
|
|
* component this class is running in. |
211 |
|
|
* eg, a Filter may be called "filter1", |
212 |
|
|
* If this class does not have an owning |
213 |
|
|
* component, a name from the configuration |
214 |
|
|
* can be placed here. This name could also |
215 |
|
|
* be changed to null for utility classes. |
216 |
|
|
*/ |
217 |
|
|
private String _name = "DiskIO"; |
218 |
|
|
|
219 |
|
|
/** |
220 |
|
|
* A reference to the configuration proxy in use |
221 |
|
|
*/ |
222 |
|
|
private ConfigurationProxy _cp = ConfigurationProxy.getInstance(); |
223 |
|
|
|
224 |
|
|
/** |
225 |
|
|
* A HashMap of Registers (or groups of Registers), one |
226 |
|
|
* for each host we're monitoring (reads). |
227 |
|
|
*/ |
228 |
|
|
private HashMap _hostsR = new HashMap(); |
229 |
|
|
|
230 |
|
|
/** |
231 |
|
|
* A HashMap of Registers (or groups of Registers), one |
232 |
|
|
* for each host we're monitoring (writes). |
233 |
|
|
*/ |
234 |
|
|
private HashMap _hostsW = new HashMap(); |
235 |
|
|
|
236 |
|
|
//---STATIC ATTRIBUTES--- |
237 |
|
|
|
238 |
|
|
} |