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.10 by tdb, Tue Mar 6 20:26:27 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.*;
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 <        _initialAlertTime = new long[numAttributes];
81 <        _lastAlertTimeout = new long[numAttributes];
82 <        _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;
55 <            _initialAlertTime[x] = 0;
56 <            _lastThresholdLevels[x] = 0;
57 <            _lastAlertTimeout[x] = 0;
58 <            for(int y = 0; y < Alert.alertLevels.length; y++) {
59 <                _times[x][y] = 0;
60 <            }
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
72 <     * given attribute.
122 >     * Gets the last alert level
123       *
74     * @param attributeNum the attribute to get
75     *
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
84 <     * given attribute.
131 >     * Sets the last threshold level
132       *
86     * @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
95 <     * given attribute.
139 >    /**
140 >     * Gets the last threshold level
141       *
97     * @param attributeNum the attribute to get
98     *
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
107 <     * given attribute.
149 >     * Sets the last alert level
150       *
151       * Note that if this is setting to an OK
152       * level alert, it resets _maxLevelCount.
# Line 113 | Line 155 | public class Register {
155       * if the next alert after OK is set.
156       * And resets it to 0 if it IS an OK.
157       *
116     * @param attributeNum the attribute to set
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 <            _initialAlertTime[attributeNum] = 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[attributeNum] = System.currentTimeMillis();
169 >            _initialAlertTime = System.currentTimeMillis();
170          }
171      }
172      
173      /**
174 <     * Gets the time an alert was sent for the
132 <     * given attribute at the given level.
174 >     * Gets the time an alert was sent at the given level.
175       *
134     * @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
145 <     * given attribute at the given level.
185 >     * Gets the time an alert was sent at the given level.
186       *
147     * @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 165 | Line 204 | public class Register {
204          // -1.0 means we don't use an alert level
205          double threshold = -1.0;
206          try {
207 <            String thresholdString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".threshold." + Alert.thresholdLevels[level]);
207 >            String thresholdString = "";
208 >            try {
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;
# Line 181 | 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       *
189     * If there is no alert timeout for a
190     * given level, this returns 0
191     *
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          try {
245 <            String timeoutString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".alertTimeout." + Alert.alertLevels[level]);
246 <            int threshold = getLastThresholdLevel(attributeNum);
245 >            String timeoutString;
246 >            try {
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              }
# Line 218 | Line 271 | public class Register {
271       * in the list, this is assumed to be FINAL, and special
272       * logic is in place to handle that.
273       *
221     * @param attributeNum the attribute to get next alert for
274       */
275 <    public int getNextAlertLevel(int attributeNum) {
276 <        if((getLastAlertLevel(attributeNum) + 1) > (Alert.alertLevels.length - 2)) {
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       *
234     * @param attrubuteNum the attribute to get the last timeout for
286       * @return the last timeout value
287       */
288 <    public long getLastAlertTimeout(int attributeNum) {
289 <        return _lastAlertTimeout[attributeNum];
288 >    public long getLastAlertTimeout() {
289 >        return _lastAlertTimeout;
290      }
291      
292      /**
293       * Sets the timeout value of the last alert
294       * sent
295       *
245     * @param attrubuteNum the attribute to get the last timeout for
296       * @param timeout the new value
297       */
298 <    public void setLastAlertTimeout(int attributeNum, long timeout) {
299 <        _lastAlertTimeout[attributeNum] = timeout;
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       *
256     * @param attrubuteNum the attribute to get the first alert time for
306       */
307 <    public long getInitialAlertTime(int attributeNum) {
308 <        return _initialAlertTime[attributeNum];
307 >    public long getInitialAlertTime() {
308 >        return _initialAlertTime;
309      }
310  
311      /**
# Line 278 | Line 327 | public class Register {
327       * is mis-read or is not configured.  It will NEVER reach
328       * a FINAL.
329       *
281     * @param attributeNum the attribute to advance the alert for
330       */
331 <    public void escalateAlert(int attributeNum) {
331 >    public void escalateAlert() {
332          // don't escalate if we're already on the last alert
333 <        if(getLastAlertLevel(attributeNum) != Alert.alertLevels.length -1) {
334 <            setLastAlertLevel(attributeNum, getNextAlertLevel(attributeNum));
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(attributeNum) == Alert.alertLevels.length - 2) {
339 >            if (getLastAlertLevel() == Alert.alertLevels.length - 2) {
340                  _maxLevelCount++;
341                  if(_maxLevelCount > reachFINALcount) {
342 <                    setLastAlertLevel(attributeNum, Alert.alertFINAL);
342 >                    setLastAlertLevel(Alert.alertFINAL);
343                  }
344              }
345          } catch (PropertyNotFoundException e) {
# Line 312 | 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;
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;
403 >    private long _initialAlertTime;
404  
405      /**
406       * A reference to the configuration proxy in use

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines