ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/client/monitors/Swap__Monitor.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/client/monitors/Swap__Monitor.java (file contents):
Revision 1.11 by tdb, Wed Feb 5 16:43:46 2003 UTC vs.
Revision 1.12 by tdb, Mon Mar 10 08:59:19 2003 UTC

# Line 69 | Line 69 | public class Swap__Monitor extends MonitorSkeleton {
69  
70          Register reg = (Register) _hosts.get(source);
71  
72        // find out the threshold level we're at
73        String attributeName = "Swap In Use %";
74
72          // get the packet data
73          double swapTotal, swapFree;
74          try {
75              String total = packet.getParam("packet.swap.total");
76              String free = packet.getParam("packet.swap.free");
77              if(total==null || free==null) {
78 <                throw new NumberFormatException("Memory data invalid");
78 >                throw new NumberFormatException("Swap data invalid");
79              }
80              swapTotal = Double.parseDouble(total);
81              swapFree = Double.parseDouble(free);
# Line 88 | Line 85 | public class Swap__Monitor extends MonitorSkeleton {
85              return;
86          }
87  
88 <        // percentage of memory in use
89 <        double swapInUse = (1-(swapFree / swapTotal)) * 100;
90 <        int newThreshold = checkAttributeThreshold(swapInUse, reg);
88 >        boolean useValue = false;
89 >        try {
90 >           String option = _cp.getProperty("Host." + source, "Monitor." + _name + ".thresholdMeasure");
91 >           if (option.equals("VALUE")) {
92 >               useValue = true;
93 >           }
94 >        } catch (PropertyNotFoundException e) {
95 >            // we default to percentage
96 >        }
97  
98 <        // format the memoryInUse to a String
98 >        // this bit determines if the swap check is a % check
99 >        // or a byte check
100 >        String type;
101 >        double curValue;
102 >        int newThreshold;
103 >        if(useValue) {
104 >            // bytes of swap available
105 >            curValue = swapFree;
106 >            // negate check
107 >            newThreshold = checkAttributeThreshold(curValue, reg, true);
108 >            type = "bytes";
109 >        } else {
110 >            // % memory in use
111 >            curValue = (1 - ((double)swapFree / (double)swapTotal)) * 100;
112 >            // normal check
113 >            newThreshold = checkAttributeThreshold(curValue, reg, false);
114 >            type = "%";
115 >        }
116 >
117 >        // format the value to a String
118          NumberFormat nf = NumberFormat.getInstance();
119          nf.setMaximumFractionDigits(2);
120          nf.setMinimumFractionDigits(2);
121          String strSwapInUse = nf.format(swapInUse);
122  
123 +        String attributeName = "Swap in use " + type;
124 +
125          processAlert(newThreshold, attributeName, reg, source, strSwapInUse);
126              
127      }
# Line 131 | Line 155 | public class Swap__Monitor extends MonitorSkeleton {
155       * Checks a piece of current data, and returns the
156       * threshold it breaches, if any.
157       *
158 <     * @param attributeString a String representing the current data value
158 >     * The option to negate the check can be used in
159 >     * situations where being *below* the threshold
160 >     * is an 'alertable' situation. In this specific
161 >     * case, we'd do this with kb disk checks.
162 >     *
163 >     * @param value the current value
164       * @param reg the Register for the host
165 +     * @param negateCheck whether to negate the check
166       * @return the threshold level breached, if any
167       */
168 <    private int checkAttributeThreshold(double swapInUse, Register reg) {
168 >    private int checkAttributeThreshold(double value, Register reg, boolean negateCheck) {
169          for(int thresholdLevel = Alert.thresholdLevels.length - 1; thresholdLevel >= 0; thresholdLevel--) {
170              if (reg.getThreshold(thresholdLevel) != -1.0) {
171 <                if(((double) reg.getThreshold(thresholdLevel)) < swapInUse) {
172 <                    return thresholdLevel;
171 >                if(!negateCheck) {
172 >                    // normal check - has the value gone *over* the threshold
173 >                    if(((double) reg.getThreshold(thresholdLevel)) < value) {
174 >                        return thresholdLevel;
175 >                    }
176 >                }
177 >                else {
178 >                    // negated check - has the value gone *under* the threshold
179 >                    if(((double) reg.getThreshold(thresholdLevel)) > value) {
180 >                        return thresholdLevel;
181 >                    }
182                  }
183              }
184          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines