33 |
|
//---PUBLIC METHODS--- |
34 |
|
|
35 |
|
public void analysePacket(XMLPacket packet) { |
36 |
< |
if (packet.getParam("packet.attributes.type").equals("data")) { |
37 |
< |
String source = packet.getParam("packet.attributes.machine_name"); |
38 |
< |
if (!_hosts.containsKey(source)) { |
39 |
< |
_hosts.put(source, new Register(source, _name)); |
36 |
> |
String source = packet.getParam("packet.attributes.machine_name"); |
37 |
> |
if (!_hosts.containsKey(source)) { |
38 |
> |
_hosts.put(source, new Register(source, _name)); |
39 |
> |
} |
40 |
> |
|
41 |
> |
Register reg = (Register) _hosts.get(source); |
42 |
> |
|
43 |
> |
// find out the threshold level we're at |
44 |
> |
String attributeName = "Swap In Use %"; |
45 |
> |
|
46 |
> |
// get the packet data |
47 |
> |
double swapTotal, swapFree; |
48 |
> |
try { |
49 |
> |
String total = packet.getParam("packet.swap.total"); |
50 |
> |
String free = packet.getParam("packet.swap.free"); |
51 |
> |
if(total==null || free==null) { |
52 |
> |
throw new NumberFormatException("Memory data invalid"); |
53 |
|
} |
54 |
< |
|
55 |
< |
Register reg = (Register) _hosts.get(source); |
56 |
< |
|
57 |
< |
// find out the threshold level we're at |
58 |
< |
String attributeName = "Swap In Use %"; |
59 |
< |
|
47 |
< |
// get the packet data |
48 |
< |
double swapTotal, swapFree; |
49 |
< |
try { |
50 |
< |
String total = packet.getParam("packet.swap.total"); |
51 |
< |
String free = packet.getParam("packet.swap.free"); |
52 |
< |
if(total==null || free==null) { |
53 |
< |
throw new NumberFormatException("Memory data invalid"); |
54 |
< |
} |
55 |
< |
swapTotal = Double.parseDouble(total); |
56 |
< |
swapFree = Double.parseDouble(free); |
57 |
< |
} catch (NumberFormatException e) { |
58 |
< |
_logger.write(this.toString(), Logger.WARNING, "Received packet from "+source+" with bad swap information"+e); |
59 |
< |
// don't try to continue and process |
60 |
< |
return; |
61 |
< |
} |
62 |
< |
|
63 |
< |
// percentage of memory in use |
64 |
< |
double swapInUse = (1-(swapFree / swapTotal)) * 100; |
65 |
< |
int newThreshold = checkAttributeThreshold(swapInUse, reg); |
66 |
< |
|
67 |
< |
// format the memoryInUse to a String |
68 |
< |
NumberFormat nf = NumberFormat.getInstance(); |
69 |
< |
nf.setMaximumFractionDigits(2); |
70 |
< |
nf.setMinimumFractionDigits(2); |
71 |
< |
String strSwapInUse = nf.format(swapInUse); |
72 |
< |
|
73 |
< |
processAlert(newThreshold, attributeName, reg, source, strSwapInUse); |
74 |
< |
|
54 |
> |
swapTotal = Double.parseDouble(total); |
55 |
> |
swapFree = Double.parseDouble(free); |
56 |
> |
} catch (NumberFormatException e) { |
57 |
> |
_logger.write(this.toString(), Logger.WARNING, "Received packet from "+source+" with bad swap information"+e); |
58 |
> |
// don't try to continue and process |
59 |
> |
return; |
60 |
|
} |
61 |
+ |
|
62 |
+ |
// percentage of memory in use |
63 |
+ |
double swapInUse = (1-(swapFree / swapTotal)) * 100; |
64 |
+ |
int newThreshold = checkAttributeThreshold(swapInUse, reg); |
65 |
+ |
|
66 |
+ |
// format the memoryInUse to a String |
67 |
+ |
NumberFormat nf = NumberFormat.getInstance(); |
68 |
+ |
nf.setMaximumFractionDigits(2); |
69 |
+ |
nf.setMinimumFractionDigits(2); |
70 |
+ |
String strSwapInUse = nf.format(swapInUse); |
71 |
+ |
|
72 |
+ |
processAlert(newThreshold, attributeName, reg, source, strSwapInUse); |
73 |
+ |
|
74 |
|
} |
75 |
|
|
76 |
|
/** |
110 |
|
} |
111 |
|
|
112 |
|
//---ACCESSOR/MUTATOR METHODS--- |
113 |
+ |
|
114 |
+ |
protected Queue getQueue() { |
115 |
+ |
return MonitorManager.getInstance().getDataQueue(); |
116 |
+ |
} |
117 |
+ |
|
118 |
|
|
119 |
|
//---ATTRIBUTES--- |
120 |
|
|