--- projects/cms/source/server/uk/org/iscream/cms/server/client/monitors/Swap__Monitor.java 2003/02/05 16:43:46 1.11 +++ projects/cms/source/server/uk/org/iscream/cms/server/client/monitors/Swap__Monitor.java 2003/03/10 08:59:19 1.12 @@ -33,7 +33,7 @@ import uk.org.iscream.cms.server.componentmanager.*; * This Monitor watches the Swap for all machines * * @author $Author: tdb $ - * @version $Id: Swap__Monitor.java,v 1.11 2003/02/05 16:43:46 tdb Exp $ + * @version $Id: Swap__Monitor.java,v 1.12 2003/03/10 08:59:19 tdb Exp $ */ public class Swap__Monitor extends MonitorSkeleton { @@ -42,7 +42,7 @@ public class Swap__Monitor extends MonitorSkeleton { /** * The current CVS revision of this class */ - public final String REVISION = "$Revision: 1.11 $"; + public final String REVISION = "$Revision: 1.12 $"; /** * A description of this monitor @@ -69,16 +69,13 @@ public class Swap__Monitor extends MonitorSkeleton { Register reg = (Register) _hosts.get(source); - // find out the threshold level we're at - String attributeName = "Swap In Use %"; - // get the packet data double swapTotal, swapFree; try { String total = packet.getParam("packet.swap.total"); String free = packet.getParam("packet.swap.free"); if(total==null || free==null) { - throw new NumberFormatException("Memory data invalid"); + throw new NumberFormatException("Swap data invalid"); } swapTotal = Double.parseDouble(total); swapFree = Double.parseDouble(free); @@ -88,16 +85,43 @@ public class Swap__Monitor extends MonitorSkeleton { return; } - // percentage of memory in use - double swapInUse = (1-(swapFree / swapTotal)) * 100; - int newThreshold = checkAttributeThreshold(swapInUse, reg); + boolean useValue = false; + try { + String option = _cp.getProperty("Host." + source, "Monitor." + _name + ".thresholdMeasure"); + if (option.equals("VALUE")) { + useValue = true; + } + } catch (PropertyNotFoundException e) { + // we default to percentage + } - // format the memoryInUse to a String + // this bit determines if the swap check is a % check + // or a byte check + String type; + double curValue; + int newThreshold; + if(useValue) { + // bytes of swap available + curValue = swapFree; + // negate check + newThreshold = checkAttributeThreshold(curValue, reg, true); + type = "bytes"; + } else { + // % memory in use + curValue = (1 - ((double)swapFree / (double)swapTotal)) * 100; + // normal check + newThreshold = checkAttributeThreshold(curValue, reg, false); + type = "%"; + } + + // format the value to a String NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); String strSwapInUse = nf.format(swapInUse); + String attributeName = "Swap in use " + type; + processAlert(newThreshold, attributeName, reg, source, strSwapInUse); } @@ -131,15 +155,30 @@ public class Swap__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 swapInUse, 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)) < swapInUse) { - 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; + } } } }