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.18 by tdb, Wed Feb 5 16:43:45 2003 UTC vs.
Revision 1.20 by tdb, Thu Jan 15 13:41:47 2004 UTC

# Line 23 | Line 23 | package uk.org.iscream.cms.server.client.monitors;
23  
24   //---IMPORTS---
25   import java.util.HashMap;
26 < import java.util.ArrayList;
26 > import java.util.HashSet;
27   import java.util.Set;
28   import java.util.Iterator;
29   import java.text.NumberFormat;
# Line 66 | Line 66 | public class Disk__Monitor extends MonitorSkeleton {
66       */
67      public void analysePacket(XMLPacket packet) {
68          String source = packet.getParam("packet.attributes.machine_name");
69 +        if(!checkBooleanConfig(source, "Monitor." + _name + ".enable")) {
70 +            return;
71 +        }
72          if (!_hosts.containsKey(source)) {
73              _hosts.put(source, new HashMap());
74          }
75 +        if (!_hostsInode.containsKey(source)) {
76 +            _hostsInode.put(source, new HashMap());
77 +        }
78  
79          HashMap diskRegisters = (HashMap) _hosts.get(source);
80 +        HashMap diskInodeRegisters = (HashMap) _hostsInode.get(source);
81          
82          // key prefix
83          String keyPrefix = "packet.disk.p";
84          
85          // a temporary holder for all the disk attributes we find
86 <        ArrayList disks = new ArrayList();
86 >        HashSet disks = new HashSet();
87  
88          // unfortunatly we need to check the whole packet
89          // to find the disks, and then get the data attributes
# Line 85 | Line 92 | public class Disk__Monitor extends MonitorSkeleton {
92          while (i.hasNext()) {
93              String dataKey = (String) i.next();
94              if(dataKey.startsWith(keyPrefix)) {
95 <                if(!disks.contains(dataKey)) {
96 <                    String diskNumber = "";
95 >                // pos is after "packet.disk.p"
96 >                int pos = keyPrefix.length();
97 >                String diskNumber = dataKey.substring(pos, dataKey.indexOf('.', pos));
98 >                String thisDisk = keyPrefix.concat(diskNumber);
99 >                
100 >                if(!disks.contains(thisDisk)) {
101 >                    // add the disk to our list
102 >                    disks.add(thisDisk);
103  
91                    // pos is after "packet.disk.p"
92                    int pos = keyPrefix.length();
93                    while (dataKey.charAt(pos) != '.') {
94                        diskNumber = diskNumber + dataKey.charAt(pos);
95                        pos++;
96                    }
97
98                    // add the disk to our list, with the packet data
99
100                    // used (we won't use this value - but we need it to forget about it ;)
101                    disks.add(keyPrefix + diskNumber + ".attributes.used");
102
104                      // device
105 <                    disks.add(keyPrefix + diskNumber + ".attributes.name");
105 <                    String device = packet.getParam(keyPrefix + diskNumber + ".attributes.name");
105 >                    String device = packet.getParam(thisDisk + ".attributes.name");
106                      // mount point
107 <                    disks.add(keyPrefix + diskNumber + ".attributes.mount");
108 <                    String mount = packet.getParam(keyPrefix + diskNumber + ".attributes.mount");
107 >                    String mount = packet.getParam(thisDisk + ".attributes.mount");
108  
109                      // these next two will be used to calculate the %age
110                      // total
111 <                    disks.add(keyPrefix + diskNumber + ".attributes.kbytes");
113 <                    String total = packet.getParam(keyPrefix + diskNumber + ".attributes.kbytes");
111 >                    String total = packet.getParam(thisDisk + ".attributes.total");
112                      // available
113 <                    disks.add(keyPrefix + diskNumber + ".attributes.avail");
114 <                    String avail = packet.getParam(keyPrefix + diskNumber + ".attributes.avail");
113 >                    String avail = packet.getParam(thisDisk + ".attributes.avail");
114 >                    
115 >                    String totalInodes = packet.getParam(thisDisk + ".attributes.totalinodes");
116 >                    String availInodes = packet.getParam(thisDisk + ".attributes.freeinodes");
117  
118                      // *** now process this disk ***
119  
# Line 125 | Line 125 | public class Disk__Monitor extends MonitorSkeleton {
125                      if(!diskRegisters.containsKey(mount)) {
126                          diskRegisters.put(mount, new Register(source, _name, mount));
127                      }
128 +                    if(!diskInodeRegisters.containsKey(mount)) {
129 +                        diskInodeRegisters.put(mount, new Register(source, _nameInode, mount));
130 +                    }
131  
132                      // get the register for this disk
133                      Register reg = (Register) diskRegisters.get(mount);
134 +                    Register regInode = (Register) diskInodeRegisters.get(mount);
135  
136                      // get the packet data
137                      double diskTotal, diskAvail;
138 +                    int diskInodeTotal, diskInodeAvail;
139                      try {
140  
141 <                        if(total==null || avail==null) {
141 >                        if(total==null || avail==null || totalInodes==null || availInodes==null) {
142                              throw new NumberFormatException("Disk data invalid");
143                          }
144                          diskTotal = Double.parseDouble(total);
145                          diskAvail = Double.parseDouble(avail);
146 +                        diskInodeTotal = Integer.parseInt(totalInodes);
147 +                        diskInodeAvail = Integer.parseInt(availInodes);
148                      } catch (NumberFormatException e) {
149                          _logger.write(this.toString(), Logger.WARNING, "Received packet from "+source+" with bad disk information: "+e);
150                          // don't try to continue and process, try next disk
# Line 145 | Line 152 | public class Disk__Monitor extends MonitorSkeleton {
152                      }
153  
154                      boolean useValue = false;
155 +                    boolean useValueInode = false;
156                      try {
157                          // try looking for a mount-point specific thresholdMeasure first
158                          String option = _cp.getProperty("Host." + source, "Monitor." + _name + "." + mount + ".thresholdMeasure");
159                          if (option.equals("VALUE")) {
160                              useValue = true;
161                          }
162 +                        option = _cp.getProperty("Host." + source, "Monitor." + _nameInode + "." + mount + ".thresholdMeasure");
163 +                        if (option.equals("VALUE")) {
164 +                            useValueInode = true;
165 +                        }
166                      } catch (PropertyNotFoundException e) {
167                          try {
168                              // now look for a more general thresholdMeasure
# Line 158 | Line 170 | public class Disk__Monitor extends MonitorSkeleton {
170                              if (option.equals("VALUE")) {
171                                  useValue = true;
172                              }
173 +                            option = _cp.getProperty("Host." + source, "Monitor." + _nameInode + ".thresholdMeasure");
174 +                            if (option.equals("VALUE")) {
175 +                                useValueInode = true;
176 +                            }
177                          } catch (PropertyNotFoundException f) {
178                              // we default to percentage in any case
179                          }
180                      }
181  
182                      // this  bit determines if the disk check is a % check
183 <                    // or a kb check
183 >                    // or a byte check
184                      String type;
185                      double curValue;
186                      int newThreshold;
187                      if(useValue) {
188 <                        // kb disk available
188 >                        // byte disk available
189                          curValue = diskAvail;
190                          // negate check
191                          newThreshold = checkAttributeThreshold(curValue, reg, true);
192 <                        type = "kb";
192 >                        type = "bytes";
193                      } else {
194                          // % disk in use
195 <                        curValue = (1 - (diskAvail / diskTotal)) * 100;
195 >                        curValue = (1 - ((double)diskAvail / (double)diskTotal)) * 100;
196                          // normal check
197                          newThreshold = checkAttributeThreshold(curValue, reg, false);
198                          type = "%";
199                      }
200 <
200 >                    
201 >                    String typeInode;
202 >                    double curValueInode;
203 >                    int newThresholdInode;
204 >                    if(useValueInode) {
205 >                        // inodes available
206 >                        curValueInode = diskInodeAvail;
207 >                        // negate check
208 >                        newThresholdInode = checkAttributeThreshold(curValueInode, regInode, true);
209 >                        typeInode = "count";
210 >                    } else {
211 >                        // % inodes in use
212 >                        curValueInode = (1 - ((double)diskInodeAvail / (double)diskInodeTotal)) * 100;
213 >                        // normal check
214 >                        newThresholdInode = checkAttributeThreshold(curValueInode, regInode, false);
215 >                        typeInode = "%";
216 >                    }
217 >                    
218                      // format the diskInUse to a String
219                      NumberFormat nf = NumberFormat.getInstance();
220                      nf.setMaximumFractionDigits(2);
221                      nf.setMinimumFractionDigits(2);
222                      String strCurValue = nf.format(curValue);
223 +                    String strCurValueInode = nf.format(curValueInode);
224  
225                      // say which disk had the problem
226                      String attributeName = "Disk in use " + type + " on " + mount + " (" + device + ")";
227 +                    String attributeNameInode = "Disk inodes in use " + type + " on " + mount + " (" + device +")";
228  
229                      processAlert(newThreshold, attributeName, reg, source, strCurValue);
230 +                    processAlert(newThresholdInode, attributeNameInode, regInode, source, strCurValueInode);
231                  }
232              }
233          }
# Line 283 | Line 319 | public class Disk__Monitor extends MonitorSkeleton {
319      private String _name = "Disk";
320      
321      /**
322 +     * Inodes have the name "DiskInode" in the
323 +     * configuration.
324 +     */
325 +    private String _nameInode = "DiskInode";
326 +    
327 +    /**
328       * A reference to the configuration proxy in use
329       */
330      private ConfigurationProxy _cp = ConfigurationProxy.getInstance();
# Line 292 | Line 334 | public class Disk__Monitor extends MonitorSkeleton {
334       * for each host we're monitoring.
335       */
336      private HashMap _hosts = new HashMap();
337 +    
338 +    /**
339 +     * A HashMap of Registers (or groups of Registers), one
340 +     * for each host we're monitoring (inodes).
341 +     */
342 +    private HashMap _hostsInode = new HashMap();
343  
344   //---STATIC ATTRIBUTES---
345  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines