| 14 |
|
* @author $Author$ |
| 15 |
|
* @version $Id$ |
| 16 |
|
*/ |
| 17 |
< |
public class CPU__Monitor implements PluginMonitor { |
| 17 |
> |
public class CPU__Monitor extends MonitorSkeleton { |
| 18 |
|
|
| 19 |
|
//---FINAL ATTRIBUTES--- |
| 20 |
|
|
| 35 |
|
if (packet.getParam("packet.attributes.type").equals("data")) { |
| 36 |
|
String source = packet.getParam("packet.attributes.machine_name"); |
| 37 |
|
if (!_hosts.containsKey(source)) { |
| 38 |
< |
_hosts.put(source, new Register(source, _name, _attributes.length)); |
| 38 |
> |
HashMap attributeRegisters = new HashMap(); |
| 39 |
> |
initAttributeRegsiters(source, attributeRegisters); |
| 40 |
> |
_hosts.put(source, attributeRegisters); |
| 41 |
|
} |
| 42 |
< |
|
| 43 |
< |
Register reg = (Register) _hosts.get(source); |
| 42 |
> |
|
| 43 |
> |
HashMap attributeRegisters = (HashMap) _hosts.get(source); |
| 44 |
|
for(int attributeNum = 0; attributeNum < _attributes.length; attributeNum++) { |
| 45 |
+ |
Register reg = (Register) attributeRegisters.get(_attributes[attributeNum]); |
| 46 |
|
// find out the threshold level we're at |
| 47 |
< |
int result = checkAttributeThreshold(packet.getParam(_attributes[attributeNum]), reg); |
| 48 |
< |
|
| 49 |
< |
// decide what threshold level we're on, if we've changed, record that |
| 50 |
< |
if (result != reg.getLastThresholdLevel(attributeNum)) { |
| 51 |
< |
reg.setLastThresholdLevel(attributeNum, result); |
| 49 |
< |
} |
| 50 |
< |
// as long as this isn't a normal level |
| 51 |
< |
if(reg.getLastThresholdLevel(attributeNum) != Alert.thresholdNORMAL) { |
| 52 |
< |
// if the time since the last alert is more than the time for |
| 53 |
< |
// its timeout, fire an alert, escalate the alert |
| 54 |
< |
long timeout = reg.getAlertTimeout(reg.getLastAlertLevel(attributeNum), attributeNum); |
| 55 |
< |
if ((timeout > 0) && (reg.getTimeLastSent(attributeNum) > 0)) { |
| 56 |
< |
if((System.currentTimeMillis() - reg.getTimeLastSent(attributeNum)) > timeout) { |
| 57 |
< |
reg.escalateAlert(attributeNum); |
| 58 |
< |
reg.setTimeLastSent(attributeNum, System.currentTimeMillis()); |
| 59 |
< |
fireAlert(reg, packet, attributeNum); |
| 60 |
< |
} |
| 61 |
< |
// if we don't have a timeout configured...we got STRAIGHT to the next level |
| 62 |
< |
} else { |
| 63 |
< |
reg.escalateAlert(attributeNum); |
| 64 |
< |
reg.setTimeLastSent(attributeNum, System.currentTimeMillis()); |
| 65 |
< |
fireAlert(reg, packet, attributeNum); |
| 66 |
< |
} |
| 67 |
< |
|
| 68 |
< |
// we must be on ok, check the timeout value for this |
| 69 |
< |
} else { |
| 70 |
< |
// if we were on an OK alert before, then we don't do anything |
| 71 |
< |
// but if we weren't we only set OK, once the timout of the last |
| 72 |
< |
// alert has occourd |
| 73 |
< |
if (reg.getLastAlertLevel(attributeNum) != Alert.alertOK) { |
| 74 |
< |
long timeout = reg.getAlertTimeout(reg.getLastAlertLevel(attributeNum), attributeNum); |
| 75 |
< |
if ((timeout > 0) && (reg.getTimeLastSent(attributeNum) > 0)) { |
| 76 |
< |
if ((System.currentTimeMillis() - reg.getTimeLastSent(attributeNum)) > timeout) { |
| 77 |
< |
reg.setLastAlertLevel(attributeNum, Alert.alertOK); |
| 78 |
< |
reg.setTimeLastSent(attributeNum, System.currentTimeMillis()); |
| 79 |
< |
fireAlert(reg, packet, attributeNum); |
| 80 |
< |
} |
| 81 |
< |
} else { |
| 82 |
< |
reg.setLastAlertLevel(attributeNum, Alert.alertOK); |
| 83 |
< |
reg.setTimeLastSent(attributeNum, System.currentTimeMillis()); |
| 84 |
< |
fireAlert(reg, packet, attributeNum); |
| 85 |
< |
} |
| 86 |
< |
} |
| 87 |
< |
} |
| 47 |
> |
String attribute = _attributes[attributeNum]; |
| 48 |
> |
String attributeName = _attributeNames[attributeNum]; |
| 49 |
> |
String currentValue = packet.getParam(attribute); |
| 50 |
> |
int newThreshold = checkAttributeThreshold(currentValue, reg); |
| 51 |
> |
processAlert(newThreshold, attributeName, reg, source, currentValue); |
| 52 |
|
} |
| 53 |
|
} |
| 54 |
|
} |
| 92 |
|
} |
| 93 |
|
} |
| 94 |
|
} |
| 95 |
< |
return 0; |
| 95 |
> |
return Alert.thresholdNORMAL; |
| 96 |
|
} |
| 97 |
|
|
| 98 |
< |
private void fireAlert(Register reg, XMLPacket packet, int attributeNum) { |
| 99 |
< |
int alertLevel = reg.getLastAlertLevel(attributeNum); |
| 100 |
< |
int thresholdLevel = reg.getLastThresholdLevel(attributeNum); |
| 137 |
< |
String source = packet.getParam("packet.attributes.machine_name"); |
| 138 |
< |
String currentValue = packet.getParam(_attributes[attributeNum]); |
| 139 |
< |
String attributeName = _attributeNames[attributeNum]; |
| 140 |
< |
String thresholdValue = Double.toString(reg.getThreshold(thresholdLevel)); |
| 141 |
< |
String time = Long.toString(reg.getAlertTimeout(reg.getLastAlertLevel(attributeNum), attributeNum) / 1000); |
| 142 |
< |
if (thresholdLevel == Alert.thresholdNORMAL) { |
| 143 |
< |
thresholdValue = "-"; |
| 98 |
> |
private void initAttributeRegsiters(String source, HashMap attributeRegisters) { |
| 99 |
> |
for(int attributeNum = 0; attributeNum < _attributes.length; attributeNum++) { |
| 100 |
> |
attributeRegisters.put(_attributes[attributeNum], new Register(source, _name)); |
| 101 |
|
} |
| 145 |
– |
if (alertLevel == Alert.alertOK) { |
| 146 |
– |
time = "0"; |
| 147 |
– |
} |
| 148 |
– |
Alert alert = new Alert(alertLevel, thresholdLevel, source, thresholdValue, currentValue, attributeName, time); |
| 149 |
– |
_alerterQueue.add(alert); |
| 150 |
– |
_logger.write(toString(), Logger.DEBUG, "Fired alert for source:" + source + " at alert level:" + Alert.alertLevels[alertLevel] + " on:" + attributeName + " for threshold level:" + Alert.thresholdLevels[thresholdLevel] + " at:" + currentValue + " exceeding threshold of:" +thresholdValue + " next alert sent in:" + time + "secs"); |
| 102 |
|
} |
| 103 |
|
|
| 104 |
|
//---ACCESSOR/MUTATOR METHODS--- |
| 115 |
|
* be changed to null for utility classes. |
| 116 |
|
*/ |
| 117 |
|
private String _name = "CPU"; |
| 167 |
– |
|
| 168 |
– |
/** |
| 169 |
– |
* This holds a reference to the |
| 170 |
– |
* system logger that is being used. |
| 171 |
– |
*/ |
| 172 |
– |
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
| 173 |
– |
|
| 174 |
– |
private Queue _alerterQueue = ClientMain._alerterQueue; |
| 118 |
|
|
| 119 |
|
/** |
| 120 |
|
* A reference to the configuration proxy in use |