--- projects/cms/source/server/uk/org/iscream/cms/server/client/monitors/Memory__Monitor.java 2001/05/29 17:02:34 1.8 +++ projects/cms/source/server/uk/org/iscream/cms/server/client/monitors/Memory__Monitor.java 2001/11/26 11:59:19 1.9 @@ -13,7 +13,7 @@ import uk.org.iscream.cms.server.componentmanager.*; * This Monitor watches the Memory for all machines * * @author $Author: tdb $ - * @version $Id: Memory__Monitor.java,v 1.8 2001/05/29 17:02:34 tdb Exp $ + * @version $Id: Memory__Monitor.java,v 1.9 2001/11/26 11:59:19 tdb Exp $ */ public class Memory__Monitor extends MonitorSkeleton { @@ -22,7 +22,7 @@ public class Memory__Monitor extends MonitorSkeleton { /** * The current CVS revision of this class */ - public final String REVISION = "$Revision: 1.8 $"; + public final String REVISION = "$Revision: 1.9 $"; /** * A description of this monitor @@ -49,9 +49,6 @@ public class Memory__Monitor extends MonitorSkeleton { Register reg = (Register) _hosts.get(source); - // find out the threshold level we're at - String attributeName = "Memory In Use %"; - // get the packet data double memoryTotal, memoryFree; try { @@ -80,24 +77,33 @@ public class Memory__Monitor extends MonitorSkeleton { // this bit determines if the memory check is a % check // or a kb check - double memoryInUse; + String type; + double curValue; + int newThreshold; if(useValue) { - // kb memory in use - memoryInUse = memoryTotal - memoryFree; + // kb memory available + curValue = memoryFree; + // negate check + newThreshold = checkAttributeThreshold(curValue, reg, true); + type = "kb"; } else { // % memory in use - memoryInUse = (1-(memoryFree / memoryTotal)) * 100; + curValue = (1 - (memoryFree / memoryTotal)) * 100; + // normal check + newThreshold = checkAttributeThreshold(curValue, reg, false); + type = "%"; } - int newThreshold = checkAttributeThreshold(memoryInUse, reg); - // format the memoryInUse to a String NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); - String strMemoryInUse = nf.format(memoryInUse); - - processAlert(newThreshold, attributeName, reg, source, strMemoryInUse); + String strCurValue = nf.format(curValue); + + // set the attributeName nicely + String attributeName = "Memory in use " + type; + + processAlert(newThreshold, attributeName, reg, source, strCurValue); } /** @@ -129,15 +135,30 @@ public class Memory__Monitor extends MonitorSkeleton { * Checks a piece of current data, and returns the * threshold it breaches, if any. * - * @param attributeString a String representing the current data value + * The option to negate the check can be used in + * situations where being *below* the threshold + * is an 'alertable' situation. In this specific + * case, we'd do this with kb disk checks. + * + * @param value the current value * @param reg the Register for the host + * @param negateCheck whether to negate the check * @return the threshold level breached, if any */ - private int checkAttributeThreshold(double memoryInUse, Register reg) { + private int checkAttributeThreshold(double value, Register reg, boolean negateCheck) { for(int thresholdLevel = Alert.thresholdLevels.length - 1; thresholdLevel >= 0; thresholdLevel--) { if (reg.getThreshold(thresholdLevel) != -1.0) { - if(((double) reg.getThreshold(thresholdLevel)) < memoryInUse) { - return thresholdLevel; + if(!negateCheck) { + // normal check - has the value gone *over* the threshold + if(((double) reg.getThreshold(thresholdLevel)) < value) { + return thresholdLevel; + } + } + else { + // negated check - has the value gone *under* the threshold + if(((double) reg.getThreshold(thresholdLevel)) > value) { + return thresholdLevel; + } } } }