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; |
7 |
|
import java.util.Set; |
8 |
|
import java.util.Iterator; |
9 |
|
import java.text.NumberFormat; |
10 |
< |
import uk.ac.ukc.iscream.client.*; |
11 |
< |
import uk.ac.ukc.iscream.core.*; |
12 |
< |
import uk.ac.ukc.iscream.util.*; |
13 |
< |
import uk.ac.ukc.iscream.componentmanager.*; |
10 |
> |
import uk.org.iscream.client.*; |
11 |
> |
import uk.org.iscream.core.*; |
12 |
> |
import uk.org.iscream.util.*; |
13 |
> |
import uk.org.iscream.componentmanager.*; |
14 |
|
|
15 |
|
/** |
16 |
|
* This Monitor watches the Disks for all machines |
36 |
|
//---PUBLIC METHODS--- |
37 |
|
|
38 |
|
public void analysePacket(XMLPacket packet) { |
39 |
< |
if (packet.getParam("packet.attributes.type").equals("data")) { |
40 |
< |
String source = packet.getParam("packet.attributes.machine_name"); |
41 |
< |
if (!_hosts.containsKey(source)) { |
42 |
< |
_hosts.put(source, new HashMap()); |
43 |
< |
} |
44 |
< |
|
45 |
< |
HashMap diskRegisters = (HashMap) _hosts.get(source); |
46 |
< |
|
47 |
< |
// a tempory holder for all the disk attributes we find |
48 |
< |
ArrayList disks = new ArrayList(); |
49 |
< |
|
50 |
< |
// unfortunatly we need to check the whole packet |
51 |
< |
// to find the disks, and then get the data attributes |
52 |
< |
Set packetSet = packet.getSet(); |
53 |
< |
Iterator i = packetSet.iterator(); |
54 |
< |
while (i.hasNext()) { |
55 |
< |
String dataKey = (String) i.next(); |
56 |
< |
if(dataKey.startsWith("packet.disk.p")) { |
57 |
< |
if(!disks.contains(dataKey)) { |
58 |
< |
String diskNumber = ""; |
59 |
< |
|
60 |
< |
// pos is after "packet.disk.p" |
61 |
< |
int pos = 13; |
62 |
< |
while (dataKey.charAt(pos) != '.') { |
63 |
< |
diskNumber = diskNumber + dataKey.charAt(pos); |
64 |
< |
pos++; |
65 |
< |
} |
66 |
< |
|
67 |
< |
// add the disk to our list, with the packet data |
68 |
< |
|
69 |
< |
// used (we won't use this value - but we need it to forget about it ;) |
70 |
< |
disks.add("packet.disk.p" + diskNumber + ".attributes.used"); |
71 |
< |
|
72 |
< |
// device |
73 |
< |
disks.add("packet.disk.p" + diskNumber + ".attributes.name"); |
74 |
< |
String device = packet.getParam("packet.disk.p" + diskNumber + ".attributes.name"); |
75 |
< |
// mount point |
76 |
< |
disks.add("packet.disk.p" + diskNumber + ".attributes.mount"); |
77 |
< |
String mount = packet.getParam("packet.disk.p" + diskNumber + ".attributes.mount"); |
39 |
> |
String source = packet.getParam("packet.attributes.machine_name"); |
40 |
> |
if (!_hosts.containsKey(source)) { |
41 |
> |
_hosts.put(source, new HashMap()); |
42 |
> |
} |
43 |
|
|
44 |
< |
// these next two will be used to calculate the %age |
80 |
< |
// total |
81 |
< |
disks.add("packet.disk.p" + diskNumber + ".attributes.kbytes"); |
82 |
< |
String total = packet.getParam("packet.disk.p" + diskNumber + ".attributes.kbytes"); |
83 |
< |
// available |
84 |
< |
disks.add("packet.disk.p" + diskNumber + ".attributes.avail"); |
85 |
< |
String avail = packet.getParam("packet.disk.p" + diskNumber + ".attributes.avail"); |
44 |
> |
HashMap diskRegisters = (HashMap) _hosts.get(source); |
45 |
|
|
46 |
< |
// *** now process this disk *** |
46 |
> |
// a tempory holder for all the disk attributes we find |
47 |
> |
ArrayList disks = new ArrayList(); |
48 |
|
|
49 |
< |
// check if we've seen this disk before on a previous run |
50 |
< |
// if not, we need to create a register for it |
51 |
< |
if(!diskRegisters.containsKey(diskNumber)) { |
52 |
< |
diskRegisters.put(diskNumber, new Register(source, _name)); |
53 |
< |
} |
49 |
> |
// unfortunatly we need to check the whole packet |
50 |
> |
// to find the disks, and then get the data attributes |
51 |
> |
Set packetSet = packet.getSet(); |
52 |
> |
Iterator i = packetSet.iterator(); |
53 |
> |
while (i.hasNext()) { |
54 |
> |
String dataKey = (String) i.next(); |
55 |
> |
if(dataKey.startsWith("packet.disk.p")) { |
56 |
> |
if(!disks.contains(dataKey)) { |
57 |
> |
String diskNumber = ""; |
58 |
|
|
59 |
< |
// get the register for this disk |
60 |
< |
Register reg = (Register) diskRegisters.get(diskNumber); |
59 |
> |
// pos is after "packet.disk.p" |
60 |
> |
int pos = 13; |
61 |
> |
while (dataKey.charAt(pos) != '.') { |
62 |
> |
diskNumber = diskNumber + dataKey.charAt(pos); |
63 |
> |
pos++; |
64 |
> |
} |
65 |
|
|
66 |
< |
// get the packet data |
67 |
< |
double diskTotal, diskAvail; |
68 |
< |
try { |
69 |
< |
|
70 |
< |
if(total==null || avail==null) { |
71 |
< |
throw new NumberFormatException("Disk data invalid"); |
72 |
< |
} |
73 |
< |
diskTotal = Double.parseDouble(total); |
74 |
< |
diskAvail = Double.parseDouble(avail); |
75 |
< |
} catch (NumberFormatException e) { |
76 |
< |
_logger.write(this.toString(), Logger.WARNING, "Received packet from "+source+" with bad disk information: "+e); |
77 |
< |
// don't try to continue and process, try next disk |
78 |
< |
break; |
66 |
> |
// add the disk to our list, with the packet data |
67 |
> |
|
68 |
> |
// used (we won't use this value - but we need it to forget about it ;) |
69 |
> |
disks.add("packet.disk.p" + diskNumber + ".attributes.used"); |
70 |
> |
|
71 |
> |
// device |
72 |
> |
disks.add("packet.disk.p" + diskNumber + ".attributes.name"); |
73 |
> |
String device = packet.getParam("packet.disk.p" + diskNumber + ".attributes.name"); |
74 |
> |
// mount point |
75 |
> |
disks.add("packet.disk.p" + diskNumber + ".attributes.mount"); |
76 |
> |
String mount = packet.getParam("packet.disk.p" + diskNumber + ".attributes.mount"); |
77 |
> |
|
78 |
> |
// these next two will be used to calculate the %age |
79 |
> |
// total |
80 |
> |
disks.add("packet.disk.p" + diskNumber + ".attributes.kbytes"); |
81 |
> |
String total = packet.getParam("packet.disk.p" + diskNumber + ".attributes.kbytes"); |
82 |
> |
// available |
83 |
> |
disks.add("packet.disk.p" + diskNumber + ".attributes.avail"); |
84 |
> |
String avail = packet.getParam("packet.disk.p" + diskNumber + ".attributes.avail"); |
85 |
> |
|
86 |
> |
// *** now process this disk *** |
87 |
> |
|
88 |
> |
// check if we've seen this disk before on a previous run |
89 |
> |
// if not, we need to create a register for it |
90 |
> |
if(!diskRegisters.containsKey(diskNumber)) { |
91 |
> |
diskRegisters.put(diskNumber, new Register(source, _name, mount)); |
92 |
> |
} |
93 |
> |
|
94 |
> |
// get the register for this disk |
95 |
> |
Register reg = (Register) diskRegisters.get(diskNumber); |
96 |
> |
|
97 |
> |
// get the packet data |
98 |
> |
double diskTotal, diskAvail; |
99 |
> |
try { |
100 |
> |
|
101 |
> |
if(total==null || avail==null) { |
102 |
> |
throw new NumberFormatException("Disk data invalid"); |
103 |
|
} |
104 |
< |
|
105 |
< |
// percentage of memory in use |
106 |
< |
double diskInUse = (1 - (diskAvail / diskTotal)) * 100; |
107 |
< |
int newThreshold = checkAttributeThreshold(diskInUse, reg); |
108 |
< |
|
109 |
< |
// format the memoryInUse to a String |
118 |
< |
NumberFormat nf = NumberFormat.getInstance(); |
119 |
< |
nf.setMaximumFractionDigits(2); |
120 |
< |
nf.setMinimumFractionDigits(2); |
121 |
< |
String strDiskInUse = nf.format(diskInUse); |
122 |
< |
|
123 |
< |
// say which disk had the problem |
124 |
< |
String attributeName = "Disk in use % on " + mount + " (" + device + ")"; |
125 |
< |
|
126 |
< |
processAlert(newThreshold, attributeName, reg, source, strDiskInUse); |
104 |
> |
diskTotal = Double.parseDouble(total); |
105 |
> |
diskAvail = Double.parseDouble(avail); |
106 |
> |
} catch (NumberFormatException e) { |
107 |
> |
_logger.write(this.toString(), Logger.WARNING, "Received packet from "+source+" with bad disk information: "+e); |
108 |
> |
// don't try to continue and process, try next disk |
109 |
> |
break; |
110 |
|
} |
111 |
+ |
|
112 |
+ |
boolean useValue = false; |
113 |
+ |
try { |
114 |
+ |
String option = _cp.getProperty("Host." + source, "Monitor." + _name + ".thresholdMeasure"); |
115 |
+ |
if (option.equals("VALUE")) { |
116 |
+ |
useValue = true; |
117 |
+ |
} |
118 |
+ |
} catch (PropertyNotFoundException e) { |
119 |
+ |
// we default to percentage |
120 |
+ |
} |
121 |
+ |
|
122 |
+ |
// this bit determines if the disk check is a % check |
123 |
+ |
// or a kb check |
124 |
+ |
double diskInUse; |
125 |
+ |
String type; |
126 |
+ |
if(useValue) { |
127 |
+ |
// kb disk in use |
128 |
+ |
diskInUse = diskTotal - diskAvail; |
129 |
+ |
type = "kb"; |
130 |
+ |
} else { |
131 |
+ |
// % disk in use |
132 |
+ |
diskInUse = (1 - (diskAvail / diskTotal)) * 100; |
133 |
+ |
type = "%"; |
134 |
+ |
} |
135 |
+ |
|
136 |
+ |
|
137 |
+ |
|
138 |
+ |
int newThreshold = checkAttributeThreshold(diskInUse, reg); |
139 |
+ |
|
140 |
+ |
// format the diskInUse to a String |
141 |
+ |
NumberFormat nf = NumberFormat.getInstance(); |
142 |
+ |
nf.setMaximumFractionDigits(2); |
143 |
+ |
nf.setMinimumFractionDigits(2); |
144 |
+ |
String strDiskInUse = nf.format(diskInUse); |
145 |
+ |
|
146 |
+ |
// say which disk had the problem |
147 |
+ |
String attributeName = "Disk in use " + type + " on " + mount + " (" + device + ")"; |
148 |
+ |
|
149 |
+ |
processAlert(newThreshold, attributeName, reg, source, strDiskInUse); |
150 |
|
} |
151 |
|
} |
152 |
|
} |
156 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
157 |
|
* method to provide clean logging (every class should have this). |
158 |
|
* |
159 |
< |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
159 |
> |
* This uses the uk.org.iscream.util.NameFormat class |
160 |
|
* to format the toString() |
161 |
|
* |
162 |
|
* @return the name of this class and its CVS revision |
189 |
|
} |
190 |
|
|
191 |
|
//---ACCESSOR/MUTATOR METHODS--- |
192 |
< |
|
192 |
> |
|
193 |
> |
protected Queue getQueue() { |
194 |
> |
return MonitorManager.getInstance().getDataQueue(); |
195 |
> |
} |
196 |
> |
|
197 |
|
//---ATTRIBUTES--- |
198 |
|
|
199 |
|
/** |