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.cms.server.client.monitors; |
23 |
|
|
26 |
|
import java.text.NumberFormat; |
27 |
|
import uk.org.iscream.cms.server.client.*; |
28 |
|
import uk.org.iscream.cms.server.core.*; |
29 |
< |
import uk.org.iscream.cms.server.util.*; |
29 |
> |
import uk.org.iscream.cms.util.*; |
30 |
|
import uk.org.iscream.cms.server.componentmanager.*; |
31 |
|
|
32 |
|
/** |
63 |
|
*/ |
64 |
|
public void analysePacket(XMLPacket packet) { |
65 |
|
String source = packet.getParam("packet.attributes.machine_name"); |
66 |
+ |
if(!checkBooleanConfig("Host." + source, "Monitor." + _name + ".enable")) { |
67 |
+ |
return; |
68 |
+ |
} |
69 |
|
if (!_hosts.containsKey(source)) { |
70 |
|
_hosts.put(source, new Register(source, _name)); |
71 |
|
} |
73 |
|
Register reg = (Register) _hosts.get(source); |
74 |
|
|
75 |
|
// get the packet data |
76 |
< |
double memoryTotal, memoryFree; |
76 |
> |
double memoryTotal, memoryFree, memoryCache; |
77 |
|
try { |
78 |
|
String total = packet.getParam("packet.memory.total"); |
79 |
|
String free = packet.getParam("packet.memory.free"); |
80 |
|
if(total==null || free==null) { |
81 |
< |
throw new NumberFormatException("Memory data invalid"); |
81 |
> |
throw new NumberFormatException("Memory data invalid or not supplied"); |
82 |
|
} |
83 |
|
memoryTotal = Double.parseDouble(total); |
84 |
|
memoryFree = Double.parseDouble(free); |
85 |
+ |
// get hold of the cache data.. default to 0 |
86 |
+ |
memoryCache = 0.0; |
87 |
+ |
String cache = packet.getParam("packet.memory.cache"); |
88 |
+ |
if(cache != null) { |
89 |
+ |
memoryCache = Double.parseDouble(cache); |
90 |
+ |
} |
91 |
|
} catch (NumberFormatException e) { |
92 |
|
_logger.write(this.toString(), Logger.WARNING, "Received packet from "+source+" with bad memory information: "+e); |
93 |
|
// don't try to continue and process |
99 |
|
String option = _cp.getProperty("Host." + source, "Monitor." + _name + ".thresholdMeasure"); |
100 |
|
if (option.equals("VALUE")) { |
101 |
|
useValue = true; |
102 |
< |
} |
102 |
> |
} |
103 |
|
} catch (PropertyNotFoundException e) { |
104 |
|
// we default to percentage |
105 |
|
} |
106 |
< |
|
107 |
< |
// this bit determines if the memory check is a % check |
108 |
< |
// or a kb check |
106 |
> |
|
107 |
> |
boolean useCache = false; |
108 |
> |
try { |
109 |
> |
int useCacheAsFree = Integer.parseInt(_cp.getProperty("Host." + source, "Monitor." + _name + ".useCacheAsFree")); |
110 |
> |
useCache = (useCacheAsFree == 1); |
111 |
> |
} catch (PropertyNotFoundException e) { |
112 |
> |
// we default to false |
113 |
> |
} catch (NumberFormatException e) { |
114 |
> |
// we default to false |
115 |
> |
} |
116 |
> |
|
117 |
> |
// this bit determines if the memory check is a % check |
118 |
> |
// or a byte check |
119 |
|
String type; |
120 |
|
double curValue; |
121 |
|
int newThreshold; |
122 |
|
if(useValue) { |
123 |
< |
// kb memory available |
124 |
< |
curValue = memoryFree; |
123 |
> |
// bytes of memory available |
124 |
> |
if(useCache) { |
125 |
> |
// NOTE: we take cache as being "probably free" for this check |
126 |
> |
curValue = memoryFree + memoryCache; |
127 |
> |
} else { |
128 |
> |
curValue = memoryFree; |
129 |
> |
} |
130 |
|
// negate check |
131 |
|
newThreshold = checkAttributeThreshold(curValue, reg, true); |
132 |
< |
type = "kb"; |
132 |
> |
type = "bytes"; |
133 |
|
} else { |
134 |
|
// % memory in use |
135 |
< |
curValue = (1 - (memoryFree / memoryTotal)) * 100; |
135 |
> |
if(useCache) { |
136 |
> |
// NOTE: we take cache as being "probably free" for this check |
137 |
> |
curValue = (1 - (((double)memoryFree + (double)memoryCache) / (double)memoryTotal)) * 100; |
138 |
> |
} else { |
139 |
> |
curValue = (1 - ((double)memoryFree / (double)memoryTotal)) * 100; |
140 |
> |
} |
141 |
|
// normal check |
142 |
|
newThreshold = checkAttributeThreshold(curValue, reg, false); |
143 |
|
type = "%"; |
144 |
|
} |
145 |
|
|
146 |
< |
// format the memoryInUse to a String |
146 |
> |
// format the value to a String |
147 |
|
NumberFormat nf = NumberFormat.getInstance(); |
148 |
|
nf.setMaximumFractionDigits(2); |
149 |
|
nf.setMinimumFractionDigits(2); |
150 |
|
String strCurValue = nf.format(curValue); |
151 |
|
|
152 |
|
// set the attributeName nicely |
153 |
< |
String attributeName = "Memory in use " + type; |
153 |
> |
String attributeName = type + " Memory in use " + type; |
154 |
> |
if(useCache) { |
155 |
> |
attributeName += " (ex. cache)"; |
156 |
> |
} |
157 |
|
|
158 |
|
processAlert(newThreshold, attributeName, reg, source, strCurValue); |
159 |
|
} |
162 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
163 |
|
* method to provide clean logging (every class should have this). |
164 |
|
* |
165 |
< |
* This uses the uk.org.iscream.cms.server.util.NameFormat class |
165 |
> |
* This uses the uk.org.iscream.cms.util.NameFormat class |
166 |
|
* to format the toString() |
167 |
|
* |
168 |
|
* @return the name of this class and its CVS revision |