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

Comparing projects/cms/source/server/uk/org/iscream/cms/server/client/Register.java (file contents):
Revision 1.2 by ajm, Sun Mar 4 02:41:16 2001 UTC vs.
Revision 1.18 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.ac.ukc.iscream.client;
21 > package uk.org.iscream.cms.server.client;
22  
23   //---IMPORTS---
24 < import uk.ac.ukc.iscream.util.*;
25 < import uk.ac.ukc.iscream.componentmanager.ConfigurationProxy;
24 > import uk.org.iscream.cms.server.util.*;
25 > import uk.org.iscream.cms.server.componentmanager.*;
26  
27   /**
28   * The Register class holds theshold values,
29   * the last level of alert for each attribute for a monitor
30 < * and the time of last alert sent for each alert level for
12 < * each attribute in this register.
30 > * and the time of last alert sent for each alert level.
31   *
32   * This class is used by monitor classes so they can determine
33   * how often they should send alerts when breaching alert levels.
# Line 34 | Line 52 | public class Register {
52      
53      /**
54       * Construct a Register with the hostname and monitorName
55 <     * (for obtaining the threshold values), and the number of
56 <     * attributes we are keeping track of.
55 >     * (for obtaining the threshold values).
56 >     * This constructs a generic register for a specific monitor.
57       *
58       * @param hostname the hostname this register is for
59       * @param monitorName the monitor this register is for
42     * @param numAttributes the number of attributes to track
60       */
61 <    public Register(String hostname, String monitorName, int numAttributes) {
61 >    public Register(String hostname, String monitorName) {
62 >        this(hostname, monitorName, null);    
63 >    }
64 >
65 >    /**
66 >     * Construct a Register with the hostname and monitorName
67 >     * (for obtaining the threshold values).
68 >     * This constructs a register for a specific attribute check
69 >     * by a monitor.
70 >     *
71 >     * @param hostname the hostname this register is for
72 >     * @param monitorName the monitor this register is for
73 >     * @param attributeName the specific attribute this register is for
74 >     */
75 >    public Register(String hostname, String monitorName, String attributeName) {
76          _hostname = hostname;
77          _monitorName = monitorName;
78 <        _lastAlertLevels = new int[numAttributes];
79 <        _lastThresholdLevels = new int[numAttributes];
80 <        _times = new long[numAttributes][Alert.alertLevels.length];
78 >        _attributeName = attributeName;
79 >        _lastAlertLevel = 0;
80 >        _lastThresholdLevel = 0;
81 >        _initialAlertTime= 0;
82 >        _lastAlertTimeout = 0;
83 >        _times = new long[Alert.alertLevels.length];
84          // initialise the arrays to 0
85 <        for (int x = 0; x < _lastAlertLevels.length; x++) {
86 <            _lastAlertLevels[x] = 0;
53 <            _lastThresholdLevels[x] = 0;
54 <            for(int y = 0; y < Alert.alertLevels.length; y++) {
55 <                _times[x][y] = 0;
56 <            }
85 >        for(int x = 0; x < Alert.alertLevels.length; x++) {
86 >            _times[x] = 0;
87          }
88      }
89 +        
90  
91   //---PUBLIC METHODS---
92  
93   //---PRIVATE METHODS---
94  
95 +    /**
96 +     * Obtains a threshold value from the configuration for a given level.
97 +     * The attribute name specifies which property to get.
98 +     * eg, attributeName = idle it will look for
99 +     *     Monitor.<monitor name>.idle.threshold.<alert level>
100 +     * eg, attributeName = null
101 +     *     Monitor.<monitor name>.threshold.<alert level>
102 +     *
103 +     * Note that if its null, this will get the threshold for the monitor
104 +     * as a whole, not the specific attribute.
105 +     *
106 +     * @param level the alert level to get the attribute for
107 +     * @param attributeName the attribute to get the threshold for
108 +     *
109 +     * @return the threshold obtained
110 +     */    
111 +    private String getThresholdConfig(int level, String attributeName) throws PropertyNotFoundException {
112 +        String temp = "";
113 +        if (attributeName != null) {
114 +            temp = "." + attributeName;
115 +        }
116 +        return _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + temp + ".threshold." + Alert.thresholdLevels[level]);
117 +    }
118 +
119   //---ACCESSOR/MUTATOR METHODS---
120      
121      /**
122 <     * Gets the last alert level for the
68 <     * given attribute.
122 >     * Gets the last alert level
123       *
70     * @param attributeNum the attribute to get
71     *
124       * @return the last alert level
125       */
126 <    public int getLastAlertLevel(int attributeNum) {
127 <        return _lastAlertLevels[attributeNum];
126 >    public int getLastAlertLevel() {
127 >        return _lastAlertLevel;
128      }
129      
130      /**
131 <     * Sets the last threshold level for the
80 <     * given attribute.
131 >     * Sets the last threshold level
132       *
82     * @param attributeNum the attribute to set
133       * @param level the new last threshold level
134       */
135 <    public void setLastThresholdLevel(int attributeNum, int level) {
136 <        _lastThresholdLevels[attributeNum] = level;
135 >    public void setLastThresholdLevel(int level) {
136 >        _lastThresholdLevel = level;
137      }
138      
139 <        /**
140 <     * Gets the last threshold level for the
91 <     * given attribute.
139 >    /**
140 >     * Gets the last threshold level
141       *
93     * @param attributeNum the attribute to get
94     *
142       * @return the last threshold level
143       */
144 <    public int getLastThresholdLevel(int attributeNum) {
145 <        return _lastThresholdLevels[attributeNum];
144 >    public int getLastThresholdLevel() {
145 >        return _lastThresholdLevel;
146      }
147      
148      /**
149 <     * Sets the last alert level for the
103 <     * given attribute.
149 >     * Sets the last alert level
150       *
151 <     * @param attributeNum the attribute to set
151 >     * Note that if this is setting to an OK
152 >     * level alert, it resets _maxLevelCount.
153 >     *
154 >     * This also sets the "initialAlertTime"
155 >     * if the next alert after OK is set.
156 >     * And resets it to 0 if it IS an OK.
157 >     *
158       * @param level the new last alert level
159       */
160 <    public void setLastAlertLevel(int attributeNum, int level) {
161 <        _lastAlertLevels[attributeNum] = level;
160 >    public void setLastAlertLevel(int level) {
161 >        _lastAlertLevel = level;
162 >        if (level == Alert.alertOK) {
163 >            _maxLevelCount = 0;
164 >            // we won't do this, so OK's still have the initialAlertTime
165 >            // of the original alert they're OK'ing
166 >            //_initialAlertTime = 0;
167 >        }
168 >        if (level == Alert.alertOK + 1) {
169 >            _initialAlertTime = System.currentTimeMillis();
170 >        }
171      }
172      
173      /**
174 <     * Gets the time an alert was sent for the
114 <     * given attribute at the given level.
174 >     * Gets the time an alert was sent at the given level.
175       *
116     * @param attributeNum the attribute to get
176       * @param level the alert level to get
177       *
178       * @return the time last sent
179       */
180 <    public long getTimeLastSent(int attributeNum) {
181 <        return _times[attributeNum][getLastAlertLevel(attributeNum)];
180 >    public long getTimeLastSent() {
181 >        return _times[getLastAlertLevel()];
182      }
183      
184      /**
185 <     * Gets the time an alert was sent for the
127 <     * given attribute at the given level.
185 >     * Gets the time an alert was sent at the given level.
186       *
129     * @param attributeNum the attribute to get
187       * @param level the alert level to get
188       * @param value the new time
189       */
190 <    public void setTimeLastSent(int attributeNum, long value) {
191 <        _times[attributeNum][getLastAlertLevel(attributeNum)] = value;
190 >    public void setTimeLastSent(long value) {
191 >        _times[getLastAlertLevel()] = value;
192      }
193      
194      /**
# Line 144 | Line 201 | public class Register {
201       * @param level the alert level
202       */
203      public double getThreshold(int level) {
204 +        // -1.0 means we don't use an alert level
205          double threshold = -1.0;
206 <        String thresholdString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".threshold." + Alert.thresholdLevels[level]);
207 <        if(thresholdString != null) {
206 >        try {
207 >            String thresholdString = "";
208              try {
209 <                threshold = Double.parseDouble(thresholdString);
210 <            } catch (NumberFormatException e) {
211 <                // -1.0 means we don't use an alert level
154 <                threshold = -1.0;
209 >                thresholdString = getThresholdConfig(level, _attributeName);
210 >            } catch (PropertyNotFoundException e) {
211 >                thresholdString = getThresholdConfig(level, null);
212              }
213 +            threshold = Double.parseDouble(thresholdString);
214 +        } catch (PropertyNotFoundException e) {
215 +            threshold = -1.0;
216 +        } catch (NumberFormatException e) {
217 +            threshold = -1.0;
218          }
219          return threshold;
220      }
# Line 163 | Line 225 | public class Register {
225       * and is converted from the value in the config,
226       * which should be seconds.
227       *
228 +     * Note that if the alert timeout for the current monitor
229 +     * is not configured, it will try to obtain the default
230 +     * timeout for all Monitor's.  If there is no alert timeout
231 +     * for either the monitor or a default setting this returns 0.
232 +     *
233       * Note that this is dependant on the threshold value
234       * given, the timeout is obatined from the config, then
235       * divided by the threshold value, this allows alerts to
236       * progress faster should a higher threshold value be passed
237       *
171     * If there is no alert timeout for a
172     * given level, this returns -1.0
173     *
238       * @param level the alert level
239       * @param thresholdLevel the threshold leve we are on
240       */
241 <    public long getAlertTimeout(int level, int attributeNum) {
241 >    public long getAlertTimeout(int level) {
242 >        // 0 means we don't use this value
243          long timeout = 0;
244 <        String timeoutString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".alertTimeout." + Alert.alertLevels[level]);
245 <        if(timeoutString != null) {
244 >        try {
245 >            String timeoutString;
246              try {
247 <                int threshold = getLastThresholdLevel(attributeNum);
248 <                if (threshold > 0) {
249 <                    timeout = (Long.parseLong(timeoutString) / threshold) * 1000;
250 <                }
251 <            } catch (NumberFormatException e) {
252 <                // -1.0 means we don't use this value
253 <                timeout = 0;
247 >                timeoutString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".alertTimeout." + Alert.alertLevels[level]);
248 >            } catch (PropertyNotFoundException e) {
249 >                // if there is no timeout for the monitor
250 >                // check for a default
251 >                timeoutString = _cp.getProperty("Host." + _hostname, "Monitor.alertTimeout." + Alert.alertLevels[level]);
252 >            }    
253 >            int threshold = getLastThresholdLevel();
254 >            if (threshold > 0) {
255 >                timeout = (Long.parseLong(timeoutString) / threshold) * 1000;
256              }
257 +        } catch (PropertyNotFoundException e) {
258 +            timeout = 0;
259 +        } catch (NumberFormatException e) {
260 +            timeout = 0;
261          }
262          return timeout;
263      }
# Line 196 | Line 267 | public class Register {
267       * the maximum alert level has been reached, simply returns
268       * that.
269       *
270 <     * @param attributeNum the attribute to get next alert for
270 >     * Note this method will NEVER reach the last alert level
271 >     * in the list, this is assumed to be FINAL, and special
272 >     * logic is in place to handle that.
273 >     *
274       */
275 <    public int getNextAlertLevel(int attributeNum) {
276 <        if((getLastAlertLevel(attributeNum) + 1) > (Alert.alertLevels.length - 1)) {
277 <            return getLastAlertLevel(attributeNum);
275 >    public int getNextAlertLevel() {
276 >        if((getLastAlertLevel() + 1) > (Alert.alertLevels.length - 2)) {
277 >            return getLastAlertLevel();
278          }
279 <        return getLastAlertLevel(attributeNum) + 1;
279 >        return getLastAlertLevel() + 1;
280      }
281  
282      /**
283 +     * Gets the timeout value of the last alert
284 +     * sent
285 +     *
286 +     * @return the last timeout value
287 +     */
288 +    public long getLastAlertTimeout() {
289 +        return _lastAlertTimeout;
290 +    }
291 +    
292 +    /**
293 +     * Sets the timeout value of the last alert
294 +     * sent
295 +     *
296 +     * @param timeout the new value
297 +     */
298 +    public void setLastAlertTimeout(long timeout) {
299 +        _lastAlertTimeout = timeout;
300 +    }
301 +
302 +    /**
303 +     * Returns the time that the first alert was sent
304 +     * for an attribute that has passed a threshold value
305 +     *
306 +     */
307 +    public long getInitialAlertTime() {
308 +        return _initialAlertTime;
309 +    }
310 +
311 +    /**
312       * Advances the alert level to the next one up.
313       *
314 <     * @param attributeNum the attribute to advance the alert for
314 >     * This keeps track of the number of the number
315 >     * of times the highest NON-FINAL alert level
316 >     * has been reached.  Note this isn't a specific
317 >     * level, just the highest, so you could configure
318 >     * more levels and not affect this.
319 >     *
320 >     * If the count exceeds the number of times
321 >     * set in the configuration, it escalates to
322 >     * a FINAL alert if we're using FINAL's.
323 >     *
324 >     * It determines if to use FINAL's from the config
325 >     * entry reachFINALcount, when the count exceeds
326 >     * this value, it escalates to a FINAL.  If that attribute
327 >     * is mis-read or is not configured.  It will NEVER reach
328 >     * a FINAL.
329 >     *
330       */
331 <    public void escalateAlert(int attributeNum) {
332 <        setLastAlertLevel(attributeNum, getNextAlertLevel(attributeNum));
331 >    public void escalateAlert() {
332 >        // don't escalate if we're already on the last alert
333 >        if(getLastAlertLevel() != Alert.alertLevels.length -1) {
334 >            setLastAlertLevel(getNextAlertLevel());
335 >        }
336 >        try {
337 >            // note if we fail to get this value, we won't process the res of this
338 >            int reachFINALcount = Integer.parseInt(_cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".reachFINALcount"));
339 >            if (getLastAlertLevel() == Alert.alertLevels.length - 2) {
340 >                _maxLevelCount++;
341 >                if(_maxLevelCount > reachFINALcount) {
342 >                    setLastAlertLevel(Alert.alertFINAL);
343 >                }
344 >            }
345 >        } catch (PropertyNotFoundException e) {
346 >            // we NEVER reach FINAL in this case
347 >        } catch (NumberFormatException e) {
348 >            // we NEVER reach FINAL in this case
349 >        }
350      }
351  
352   //---ATTRIBUTES---
# Line 225 | Line 360 | public class Register {
360       * The monitor this register is for
361       */
362      private String _monitorName;
363 +    
364 +    /**
365 +     * The attribute name, as obtained from
366 +     * the configuration.
367 +     * eg, idle or /var
368 +     */
369 +    private String _attributeName;
370  
371      /**
372       * An array of last alert levels for
373       * each attribute this register is looking
374       * after.
375       */
376 <    private int[] _lastAlertLevels;
376 >    private int _lastAlertLevel;
377      
378      /**
379       * An array of last threshold levels for
380       * each attribute this register is looking
381       * after.
382       */
383 <    private int[] _lastThresholdLevels;
383 >    private int _lastThresholdLevel;
384      
385      /**
386 +     * An array of last alert timeout levels for
387 +     * each attribute this register is looking
388 +     * after.
389 +     */
390 +    private long _lastAlertTimeout;
391 +    
392 +    /**
393       * An array of arrays containing
394       * time an alert of each level
395       * was last sent for each attribute.
396       */
397 <    private long[][] _times;
397 >    private long[] _times;
398 >    
399 >    /**
400 >     * Initial times that an alert was first
401 >     * raised.
402 >     */
403 >    private long _initialAlertTime;
404  
405      /**
406       * A reference to the configuration proxy in use
407       */
408      private ConfigurationProxy _cp = ConfigurationProxy.getInstance();
409 +    
410 +    /**
411 +     * The number of times the maximum level alert
412 +     * has occured IN A ROW, this is escalated by
413 +     * the escalate(int) method, and reset by the
414 +     * setLastAlertLevel(int, int) method
415 +     */
416 +    private int _maxLevelCount = 0;
417  
418   //---STATIC ATTRIBUTES---
419  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines