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.4 by tdb, Mon Mar 5 23:14:53 2001 UTC vs.
Revision 1.20 by tdb, Wed Feb 5 16:43:45 2003 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines