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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines