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/Memory__Monitor.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/client/monitors/Memory__Monitor.java (file contents):
Revision 1.8 by tdb, Tue May 29 17:02:34 2001 UTC vs.
Revision 1.9 by tdb, Mon Nov 26 11:59:19 2001 UTC

# Line 49 | Line 49 | public class Memory__Monitor extends MonitorSkeleton {
49  
50          Register reg = (Register) _hosts.get(source);
51  
52        // find out the threshold level we're at
53        String attributeName = "Memory In Use %";
54
52          // get the packet data
53          double memoryTotal, memoryFree;
54          try {
# Line 80 | Line 77 | public class Memory__Monitor extends MonitorSkeleton {
77  
78          // this  bit determines if the memory check is a % check
79          // or a kb check
80 <        double memoryInUse;
80 >        String type;
81 >        double curValue;
82 >        int newThreshold;
83          if(useValue) {
84 <            // kb memory in use
85 <            memoryInUse = memoryTotal - memoryFree;
84 >            // kb memory available
85 >            curValue = memoryFree;
86 >            // negate check
87 >            newThreshold = checkAttributeThreshold(curValue, reg, true);
88 >            type = "kb";
89          } else {
90              // % memory in use
91 <            memoryInUse = (1-(memoryFree / memoryTotal)) * 100;
91 >            curValue = (1 - (memoryFree / memoryTotal)) * 100;
92 >            // normal check
93 >            newThreshold = checkAttributeThreshold(curValue, reg, false);
94 >            type = "%";
95          }
96  
92        int newThreshold = checkAttributeThreshold(memoryInUse, reg);
93
97          // format the memoryInUse to a String
98          NumberFormat nf = NumberFormat.getInstance();
99          nf.setMaximumFractionDigits(2);
100          nf.setMinimumFractionDigits(2);
101 <        String strMemoryInUse = nf.format(memoryInUse);
102 <
103 <        processAlert(newThreshold, attributeName, reg, source, strMemoryInUse);
101 >        String strCurValue = nf.format(curValue);
102 >        
103 >        // set the attributeName nicely
104 >        String attributeName = "Memory in use " + type;
105 >        
106 >        processAlert(newThreshold, attributeName, reg, source, strCurValue);
107      }
108  
109      /**
# Line 129 | Line 135 | public class Memory__Monitor extends MonitorSkeleton {
135       * Checks a piece of current data, and returns the
136       * threshold it breaches, if any.
137       *
138 <     * @param attributeString a String representing the current data value
138 >     * The option to negate the check can be used in
139 >     * situations where being *below* the threshold
140 >     * is an 'alertable' situation. In this specific
141 >     * case, we'd do this with kb disk checks.
142 >     *
143 >     * @param value the current value
144       * @param reg the Register for the host
145 +     * @param negateCheck whether to negate the check
146       * @return the threshold level breached, if any
147       */
148 <    private int checkAttributeThreshold(double memoryInUse, Register reg) {
148 >    private int checkAttributeThreshold(double value, Register reg, boolean negateCheck) {
149          for(int thresholdLevel = Alert.thresholdLevels.length - 1; thresholdLevel >= 0; thresholdLevel--) {
150              if (reg.getThreshold(thresholdLevel) != -1.0) {
151 <                if(((double) reg.getThreshold(thresholdLevel)) < memoryInUse) {
152 <                    return thresholdLevel;
151 >                if(!negateCheck) {
152 >                    // normal check - has the value gone *over* the threshold
153 >                    if(((double) reg.getThreshold(thresholdLevel)) < value) {
154 >                        return thresholdLevel;
155 >                    }
156 >                }
157 >                else {
158 >                    // negated check - has the value gone *under* the threshold
159 >                    if(((double) reg.getThreshold(thresholdLevel)) > value) {
160 >                        return thresholdLevel;
161 >                    }
162                  }
163              }
164          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines