70 |
|
Register reg = (Register) _hosts.get(source); |
71 |
|
|
72 |
|
// get the packet data |
73 |
< |
double memoryTotal, memoryFree; |
73 |
> |
double memoryTotal, memoryFree, memoryCache; |
74 |
|
try { |
75 |
|
String total = packet.getParam("packet.memory.total"); |
76 |
|
String free = packet.getParam("packet.memory.free"); |
77 |
|
if(total==null || free==null) { |
78 |
< |
throw new NumberFormatException("Memory data invalid"); |
78 |
> |
throw new NumberFormatException("Memory data invalid or not supplied"); |
79 |
|
} |
80 |
|
memoryTotal = Double.parseDouble(total); |
81 |
|
memoryFree = Double.parseDouble(free); |
82 |
+ |
// get hold of the cache data.. default to 0 |
83 |
+ |
memoryCache = 0.0; |
84 |
+ |
String cache = packet.getParam("packet.memory.cache"); |
85 |
+ |
if(cache != null) { |
86 |
+ |
memoryCache = Double.parseDouble(cache); |
87 |
+ |
} |
88 |
|
} catch (NumberFormatException e) { |
89 |
|
_logger.write(this.toString(), Logger.WARNING, "Received packet from "+source+" with bad memory information: "+e); |
90 |
|
// don't try to continue and process |
96 |
|
String option = _cp.getProperty("Host." + source, "Monitor." + _name + ".thresholdMeasure"); |
97 |
|
if (option.equals("VALUE")) { |
98 |
|
useValue = true; |
99 |
< |
} |
99 |
> |
} |
100 |
|
} catch (PropertyNotFoundException e) { |
101 |
|
// we default to percentage |
102 |
|
} |
103 |
< |
|
103 |
> |
|
104 |
> |
boolean useCache = false; |
105 |
> |
try { |
106 |
> |
int useCacheAsFree = Integer.parseInt(_cp.getProperty("Host." + source, "Monitor." + _name + ".useCacheAsFree")); |
107 |
> |
useCache = (useCacheAsFree == 1); |
108 |
> |
} catch (PropertyNotFoundException e) { |
109 |
> |
// we default to false |
110 |
> |
} catch (NumberFormatException e) { |
111 |
> |
// we default to false |
112 |
> |
} |
113 |
> |
|
114 |
|
// this bit determines if the memory check is a % check |
115 |
|
// or a kb check |
116 |
|
String type; |
118 |
|
int newThreshold; |
119 |
|
if(useValue) { |
120 |
|
// kb memory available |
121 |
< |
curValue = memoryFree; |
121 |
> |
if(useCache) { |
122 |
> |
// NOTE: we take cache as being "probably free" for this check |
123 |
> |
curValue = memoryFree + memoryCache; |
124 |
> |
} else { |
125 |
> |
curValue = memoryFree; |
126 |
> |
} |
127 |
|
// negate check |
128 |
|
newThreshold = checkAttributeThreshold(curValue, reg, true); |
129 |
|
type = "kb"; |
130 |
|
} else { |
131 |
|
// % memory in use |
132 |
< |
curValue = (1 - (memoryFree / memoryTotal)) * 100; |
132 |
> |
if(useCache) { |
133 |
> |
// NOTE: we take cache as being "probably free" for this check |
134 |
> |
curValue = (1 - ((memoryFree + memoryCache) / memoryTotal)) * 100; |
135 |
> |
} else { |
136 |
> |
curValue = (1 - (memoryFree / memoryTotal)) * 100; |
137 |
> |
} |
138 |
|
// normal check |
139 |
|
newThreshold = checkAttributeThreshold(curValue, reg, false); |
140 |
|
type = "%"; |
147 |
|
String strCurValue = nf.format(curValue); |
148 |
|
|
149 |
|
// set the attributeName nicely |
150 |
< |
String attributeName = "Memory in use " + type; |
150 |
> |
String attributeName = type + " Memory in use"; |
151 |
> |
if(useCache) { |
152 |
> |
attributeName += " (ex. cache)"; |
153 |
> |
} |
154 |
|
|
155 |
|
processAlert(newThreshold, attributeName, reg, source, strCurValue); |
156 |
|
} |