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

Comparing projects/cms/source/server/uk/org/iscream/cms/server/client/monitors/Disk__Monitor.java (file contents):
Revision 1.8 by tdb, Fri Mar 23 02:32:49 2001 UTC vs.
Revision 1.15 by tdb, Sat Jan 19 17:54:57 2002 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.org.iscream.client.monitors;
2 > package uk.org.iscream.cms.server.client.monitors;
3  
4   //---IMPORTS---
5   import java.util.HashMap;
# Line 7 | Line 7 | import java.util.ArrayList;
7   import java.util.Set;
8   import java.util.Iterator;
9   import java.text.NumberFormat;
10 < import uk.org.iscream.client.*;
11 < import uk.org.iscream.core.*;
12 < import uk.org.iscream.util.*;
13 < import uk.org.iscream.componentmanager.*;
10 > import uk.org.iscream.cms.server.client.*;
11 > import uk.org.iscream.cms.server.core.*;
12 > import uk.org.iscream.cms.server.util.*;
13 > import uk.org.iscream.cms.server.componentmanager.*;
14  
15   /**
16   * This Monitor watches the Disks for all machines
# Line 55 | Line 55 | public class Disk__Monitor extends MonitorSkeleton {
55          // key prefix
56          String keyPrefix = "packet.disk.p";
57          
58 <        // a tempory holder for all the disk attributes we find
58 >        // a temporary holder for all the disk attributes we find
59          ArrayList disks = new ArrayList();
60  
61          // unfortunatly we need to check the whole packet
# Line 99 | Line 99 | public class Disk__Monitor extends MonitorSkeleton {
99  
100                      // check if we've seen this disk before on a previous run
101                      // if not, we need to create a register for it
102 <                    if(!diskRegisters.containsKey(diskNumber)) {
103 <                        diskRegisters.put(diskNumber, new Register(source, _name, mount));
102 >                    //   nb. use the mount as the key as this is unlikely to change,
103 >                    //       unlike diskNumber which could easily change
104 >                    //         (diskNumber is based on the order of df's output!)
105 >                    if(!diskRegisters.containsKey(mount)) {
106 >                        diskRegisters.put(mount, new Register(source, _name, mount));
107                      }
108  
109                      // get the register for this disk
110 <                    Register reg = (Register) diskRegisters.get(diskNumber);
110 >                    Register reg = (Register) diskRegisters.get(mount);
111  
112                      // get the packet data
113                      double diskTotal, diskAvail;
# Line 123 | Line 126 | public class Disk__Monitor extends MonitorSkeleton {
126  
127                      boolean useValue = false;
128                      try {
129 <                        String option = _cp.getProperty("Host." + source, "Monitor." + _name + ".thresholdMeasure");
129 >                        // try looking for a mount-point specific thresholdMeasure first
130 >                        String option = _cp.getProperty("Host." + source, "Monitor." + _name + "." + mount + ".thresholdMeasure");
131                          if (option.equals("VALUE")) {
132                              useValue = true;
133 <                        }                            
133 >                        }
134                      } catch (PropertyNotFoundException e) {
135 <                        // we default to percentage
135 >                        try {
136 >                            // now look for a more general thresholdMeasure
137 >                            String option = _cp.getProperty("Host." + source, "Monitor." + _name + ".thresholdMeasure");
138 >                            if (option.equals("VALUE")) {
139 >                                useValue = true;
140 >                            }
141 >                        } catch (PropertyNotFoundException f) {
142 >                            // we default to percentage in any case
143 >                        }
144                      }
145  
146                      // this  bit determines if the disk check is a % check
147                      // or a kb check
136                    double diskInUse;
148                      String type;
149 +                    double curValue;
150 +                    int newThreshold;
151                      if(useValue) {
152 <                        // kb disk in use
153 <                        diskInUse = diskTotal - diskAvail;
152 >                        // kb disk available
153 >                        curValue = diskAvail;
154 >                        // negate check
155 >                        newThreshold = checkAttributeThreshold(curValue, reg, true);
156                          type = "kb";
157                      } else {
158                          // % disk in use
159 <                        diskInUse = (1 - (diskAvail / diskTotal)) * 100;
159 >                        curValue = (1 - (diskAvail / diskTotal)) * 100;
160 >                        // normal check
161 >                        newThreshold = checkAttributeThreshold(curValue, reg, false);
162                          type = "%";
163                      }
164  
148
149
150                    int newThreshold = checkAttributeThreshold(diskInUse, reg);
151
165                      // format the diskInUse to a String
166                      NumberFormat nf = NumberFormat.getInstance();
167                      nf.setMaximumFractionDigits(2);
168                      nf.setMinimumFractionDigits(2);
169 <                    String strDiskInUse = nf.format(diskInUse);
169 >                    String strCurValue = nf.format(curValue);
170  
171                      // say which disk had the problem
172                      String attributeName = "Disk in use " + type + " on " + mount + " (" + device + ")";
173  
174 <                    processAlert(newThreshold, attributeName, reg, source, strDiskInUse);
174 >                    processAlert(newThreshold, attributeName, reg, source, strCurValue);
175                  }
176              }
177          }
# Line 168 | Line 181 | public class Disk__Monitor extends MonitorSkeleton {
181       * Overrides the {@link java.lang.Object#toString() Object.toString()}
182       * method to provide clean logging (every class should have this).
183       *
184 <     * This uses the uk.org.iscream.util.NameFormat class
184 >     * This uses the uk.org.iscream.cms.server.util.NameFormat class
185       * to format the toString()
186       *
187       * @return the name of this class and its CVS revision
# Line 193 | Line 206 | public class Disk__Monitor extends MonitorSkeleton {
206       * Checks a piece of current data, and returns the
207       * threshold it breaches, if any.
208       *
209 <     * @param diskInUse the amount of space in use
209 >     * The option to negate the check can be used in
210 >     * situations where being *below* the threshold
211 >     * is an 'alertable' situation. In this specific
212 >     * case, we'd do this with kb disk checks.
213 >     *
214 >     * @param value the current value
215       * @param reg the Register for the host
216 +     * @param negateCheck whether to negate the check
217       * @return the threshold level breached, if any
218       */
219 <    private int checkAttributeThreshold(double diskInUse, Register reg) {
219 >    private int checkAttributeThreshold(double value, Register reg, boolean negateCheck) {
220          for(int thresholdLevel = Alert.thresholdLevels.length - 1; thresholdLevel >= 0; thresholdLevel--) {
221              if (reg.getThreshold(thresholdLevel) != -1.0) {
222 <                if(((double) reg.getThreshold(thresholdLevel)) < diskInUse) {
223 <                    return thresholdLevel;
222 >                if(!negateCheck) {
223 >                    // normal check - has the value gone *over* the threshold
224 >                    if(((double) reg.getThreshold(thresholdLevel)) < value) {
225 >                        return thresholdLevel;
226 >                    }
227 >                }
228 >                else {
229 >                    // negated check - has the value gone *under* the threshold
230 >                    if(((double) reg.getThreshold(thresholdLevel)) > value) {
231 >                        return thresholdLevel;
232 >                    }
233                  }
234              }
235          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines