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.9 by tdb, Tue May 29 17:02:34 2001 UTC vs.
Revision 1.16 by tdb, Sat May 18 18:16:00 2002 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * Copyright (C) 2000-2002 i-scream
4 + *
5 + * This program is free software; you can redistribute it and/or
6 + * modify it under the terms of the GNU General Public License
7 + * as published by the Free Software Foundation; either version 2
8 + * of the License, or (at your option) any later version.
9 + *
10 + * This program is distributed in the hope that it will be useful,
11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 + * GNU General Public License for more details.
14 + *
15 + * You should have received a copy of the GNU General Public License
16 + * along with this program; if not, write to the Free Software
17 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 + */
19 +
20   //---PACKAGE DECLARATION---
21   package uk.org.iscream.cms.server.client.monitors;
22  
# Line 55 | Line 74 | public class Disk__Monitor extends MonitorSkeleton {
74          // key prefix
75          String keyPrefix = "packet.disk.p";
76          
77 <        // a tempory holder for all the disk attributes we find
77 >        // a temporary holder for all the disk attributes we find
78          ArrayList disks = new ArrayList();
79  
80          // unfortunatly we need to check the whole packet
# Line 99 | Line 118 | public class Disk__Monitor extends MonitorSkeleton {
118  
119                      // check if we've seen this disk before on a previous run
120                      // if not, we need to create a register for it
121 <                    if(!diskRegisters.containsKey(diskNumber)) {
122 <                        diskRegisters.put(diskNumber, new Register(source, _name, mount));
121 >                    //   nb. use the mount as the key as this is unlikely to change,
122 >                    //       unlike diskNumber which could easily change
123 >                    //         (diskNumber is based on the order of df's output!)
124 >                    if(!diskRegisters.containsKey(mount)) {
125 >                        diskRegisters.put(mount, new Register(source, _name, mount));
126                      }
127  
128                      // get the register for this disk
129 <                    Register reg = (Register) diskRegisters.get(diskNumber);
129 >                    Register reg = (Register) diskRegisters.get(mount);
130  
131                      // get the packet data
132                      double diskTotal, diskAvail;
# Line 123 | Line 145 | public class Disk__Monitor extends MonitorSkeleton {
145  
146                      boolean useValue = false;
147                      try {
148 <                        String option = _cp.getProperty("Host." + source, "Monitor." + _name + ".thresholdMeasure");
148 >                        // try looking for a mount-point specific thresholdMeasure first
149 >                        String option = _cp.getProperty("Host." + source, "Monitor." + _name + "." + mount + ".thresholdMeasure");
150                          if (option.equals("VALUE")) {
151                              useValue = true;
152 <                        }                            
152 >                        }
153                      } catch (PropertyNotFoundException e) {
154 <                        // we default to percentage
154 >                        try {
155 >                            // now look for a more general thresholdMeasure
156 >                            String option = _cp.getProperty("Host." + source, "Monitor." + _name + ".thresholdMeasure");
157 >                            if (option.equals("VALUE")) {
158 >                                useValue = true;
159 >                            }
160 >                        } catch (PropertyNotFoundException f) {
161 >                            // we default to percentage in any case
162 >                        }
163                      }
164  
165                      // this  bit determines if the disk check is a % check
166                      // or a kb check
136                    double diskInUse;
167                      String type;
168 +                    double curValue;
169 +                    int newThreshold;
170                      if(useValue) {
171 <                        // kb disk in use
172 <                        diskInUse = diskTotal - diskAvail;
171 >                        // kb disk available
172 >                        curValue = diskAvail;
173 >                        // negate check
174 >                        newThreshold = checkAttributeThreshold(curValue, reg, true);
175                          type = "kb";
176                      } else {
177                          // % disk in use
178 <                        diskInUse = (1 - (diskAvail / diskTotal)) * 100;
178 >                        curValue = (1 - (diskAvail / diskTotal)) * 100;
179 >                        // normal check
180 >                        newThreshold = checkAttributeThreshold(curValue, reg, false);
181                          type = "%";
182                      }
183  
148
149
150                    int newThreshold = checkAttributeThreshold(diskInUse, reg);
151
184                      // format the diskInUse to a String
185                      NumberFormat nf = NumberFormat.getInstance();
186                      nf.setMaximumFractionDigits(2);
187                      nf.setMinimumFractionDigits(2);
188 <                    String strDiskInUse = nf.format(diskInUse);
188 >                    String strCurValue = nf.format(curValue);
189  
190                      // say which disk had the problem
191                      String attributeName = "Disk in use " + type + " on " + mount + " (" + device + ")";
192  
193 <                    processAlert(newThreshold, attributeName, reg, source, strDiskInUse);
193 >                    processAlert(newThreshold, attributeName, reg, source, strCurValue);
194                  }
195              }
196          }
# Line 193 | Line 225 | public class Disk__Monitor extends MonitorSkeleton {
225       * Checks a piece of current data, and returns the
226       * threshold it breaches, if any.
227       *
228 <     * @param diskInUse the amount of space in use
228 >     * The option to negate the check can be used in
229 >     * situations where being *below* the threshold
230 >     * is an 'alertable' situation. In this specific
231 >     * case, we'd do this with kb disk checks.
232 >     *
233 >     * @param value the current value
234       * @param reg the Register for the host
235 +     * @param negateCheck whether to negate the check
236       * @return the threshold level breached, if any
237       */
238 <    private int checkAttributeThreshold(double diskInUse, Register reg) {
238 >    private int checkAttributeThreshold(double value, Register reg, boolean negateCheck) {
239          for(int thresholdLevel = Alert.thresholdLevels.length - 1; thresholdLevel >= 0; thresholdLevel--) {
240              if (reg.getThreshold(thresholdLevel) != -1.0) {
241 <                if(((double) reg.getThreshold(thresholdLevel)) < diskInUse) {
242 <                    return thresholdLevel;
241 >                if(!negateCheck) {
242 >                    // normal check - has the value gone *over* the threshold
243 >                    if(((double) reg.getThreshold(thresholdLevel)) < value) {
244 >                        return thresholdLevel;
245 >                    }
246 >                }
247 >                else {
248 >                    // negated check - has the value gone *under* the threshold
249 >                    if(((double) reg.getThreshold(thresholdLevel)) > value) {
250 >                        return thresholdLevel;
251 >                    }
252                  }
253              }
254          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines