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.9 by tdb, Tue Mar 6 20:03:50 2001 UTC vs.
Revision 1.17 by tdb, Tue May 29 17:02:34 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.ac.ukc.iscream.client;
2 > package uk.org.iscream.cms.server.client;
3  
4   //---IMPORTS---
5 < import uk.ac.ukc.iscream.util.*;
6 < import uk.ac.ukc.iscream.componentmanager.*;
5 > import uk.org.iscream.cms.server.util.*;
6 > import uk.org.iscream.cms.server.componentmanager.*;
7  
8   /**
9   * The Register class holds theshold values,
10   * the last level of alert for each attribute for a monitor
11 < * and the time of last alert sent for each alert level for
12 < * each attribute in this register.
11 > * and the time of last alert sent for each alert level.
12   *
13   * This class is used by monitor classes so they can determine
14   * how often they should send alerts when breaching alert levels.
# Line 34 | Line 33 | public class Register {
33      
34      /**
35       * Construct a Register with the hostname and monitorName
36 <     * (for obtaining the threshold values), and the number of
37 <     * attributes we are keeping track of.
36 >     * (for obtaining the threshold values).
37 >     * This constructs a generic register for a specific monitor.
38       *
39       * @param hostname the hostname this register is for
40       * @param monitorName the monitor this register is for
42     * @param numAttributes the number of attributes to track
41       */
42 <    public Register(String hostname, String monitorName, int numAttributes) {
42 >    public Register(String hostname, String monitorName) {
43 >        this(hostname, monitorName, null);    
44 >    }
45 >
46 >    /**
47 >     * Construct a Register with the hostname and monitorName
48 >     * (for obtaining the threshold values).
49 >     * This constructs a register for a specific attribute check
50 >     * by a monitor.
51 >     *
52 >     * @param hostname the hostname this register is for
53 >     * @param monitorName the monitor this register is for
54 >     * @param attributeName the specific attribute this register is for
55 >     */
56 >    public Register(String hostname, String monitorName, String attributeName) {
57          _hostname = hostname;
58          _monitorName = monitorName;
59 <        _lastAlertLevels = new int[numAttributes];
60 <        _lastThresholdLevels = new int[numAttributes];
61 <        _initialAlertTime = new long[numAttributes];
62 <        _lastAlertTimeout = new long[numAttributes];
63 <        _times = new long[numAttributes][Alert.alertLevels.length];
59 >        _attributeName = attributeName;
60 >        _lastAlertLevel = 0;
61 >        _lastThresholdLevel = 0;
62 >        _initialAlertTime= 0;
63 >        _lastAlertTimeout = 0;
64 >        _times = new long[Alert.alertLevels.length];
65          // initialise the arrays to 0
66 <        for (int x = 0; x < _lastAlertLevels.length; x++) {
67 <            _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 <            }
66 >        for(int x = 0; x < Alert.alertLevels.length; x++) {
67 >            _times[x] = 0;
68          }
69      }
70 +        
71  
72   //---PUBLIC METHODS---
73  
74   //---PRIVATE METHODS---
75  
76 +    /**
77 +     * Obtains a threshold value from the configuration for a given level.
78 +     * The attribute name specifies which property to get.
79 +     * eg, attributeName = idle it will look for
80 +     *     Monitor.<monitor name>.idle.threshold.<alert level>
81 +     * eg, attributeName = null
82 +     *     Monitor.<monitor name>.threshold.<alert level>
83 +     *
84 +     * Note that if its null, this will get the threshold for the monitor
85 +     * as a whole, not the specific attribute.
86 +     *
87 +     * @param level the alert level to get the attribute for
88 +     * @param attributeName the attribute to get the threshold for
89 +     *
90 +     * @return the threshold obtained
91 +     */    
92 +    private String getThresholdConfig(int level, String attributeName) throws PropertyNotFoundException {
93 +        String temp = "";
94 +        if (attributeName != null) {
95 +            temp = "." + attributeName;
96 +        }
97 +        return _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + temp + ".threshold." + Alert.thresholdLevels[level]);
98 +    }
99 +
100   //---ACCESSOR/MUTATOR METHODS---
101      
102      /**
103 <     * Gets the last alert level for the
72 <     * given attribute.
103 >     * Gets the last alert level
104       *
74     * @param attributeNum the attribute to get
75     *
105       * @return the last alert level
106       */
107 <    public int getLastAlertLevel(int attributeNum) {
108 <        return _lastAlertLevels[attributeNum];
107 >    public int getLastAlertLevel() {
108 >        return _lastAlertLevel;
109      }
110      
111      /**
112 <     * Sets the last threshold level for the
84 <     * given attribute.
112 >     * Sets the last threshold level
113       *
86     * @param attributeNum the attribute to set
114       * @param level the new last threshold level
115       */
116 <    public void setLastThresholdLevel(int attributeNum, int level) {
117 <        _lastThresholdLevels[attributeNum] = level;
116 >    public void setLastThresholdLevel(int level) {
117 >        _lastThresholdLevel = level;
118      }
119      
120 <        /**
121 <     * Gets the last threshold level for the
95 <     * given attribute.
120 >    /**
121 >     * Gets the last threshold level
122       *
97     * @param attributeNum the attribute to get
98     *
123       * @return the last threshold level
124       */
125 <    public int getLastThresholdLevel(int attributeNum) {
126 <        return _lastThresholdLevels[attributeNum];
125 >    public int getLastThresholdLevel() {
126 >        return _lastThresholdLevel;
127      }
128      
129      /**
130 <     * Sets the last alert level for the
107 <     * given attribute.
130 >     * Sets the last alert level
131       *
132       * Note that if this is setting to an OK
133       * level alert, it resets _maxLevelCount.
# Line 113 | Line 136 | public class Register {
136       * if the next alert after OK is set.
137       * And resets it to 0 if it IS an OK.
138       *
116     * @param attributeNum the attribute to set
139       * @param level the new last alert level
140       */
141 <    public void setLastAlertLevel(int attributeNum, int level) {
142 <        _lastAlertLevels[attributeNum] = level;
141 >    public void setLastAlertLevel(int level) {
142 >        _lastAlertLevel = level;
143          if (level == Alert.alertOK) {
144              _maxLevelCount = 0;
145 <            _initialAlertTime[attributeNum] = 0;
145 >            // we won't do this, so OK's still have the initialAlertTime
146 >            // of the original alert they're OK'ing
147 >            //_initialAlertTime = 0;
148          }
149          if (level == Alert.alertOK + 1) {
150 <            _initialAlertTime[attributeNum] = System.currentTimeMillis();
150 >            _initialAlertTime = System.currentTimeMillis();
151          }
152      }
153      
154      /**
155 <     * Gets the time an alert was sent for the
132 <     * given attribute at the given level.
155 >     * Gets the time an alert was sent at the given level.
156       *
134     * @param attributeNum the attribute to get
157       * @param level the alert level to get
158       *
159       * @return the time last sent
160       */
161 <    public long getTimeLastSent(int attributeNum) {
162 <        return _times[attributeNum][getLastAlertLevel(attributeNum)];
161 >    public long getTimeLastSent() {
162 >        return _times[getLastAlertLevel()];
163      }
164      
165      /**
166 <     * Gets the time an alert was sent for the
145 <     * given attribute at the given level.
166 >     * Gets the time an alert was sent at the given level.
167       *
147     * @param attributeNum the attribute to get
168       * @param level the alert level to get
169       * @param value the new time
170       */
171 <    public void setTimeLastSent(int attributeNum, long value) {
172 <        _times[attributeNum][getLastAlertLevel(attributeNum)] = value;
171 >    public void setTimeLastSent(long value) {
172 >        _times[getLastAlertLevel()] = value;
173      }
174      
175      /**
# Line 165 | Line 185 | public class Register {
185          // -1.0 means we don't use an alert level
186          double threshold = -1.0;
187          try {
188 <            String thresholdString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".threshold." + Alert.thresholdLevels[level]);
188 >            String thresholdString = "";
189 >            try {
190 >                thresholdString = getThresholdConfig(level, _attributeName);
191 >            } catch (PropertyNotFoundException e) {
192 >                thresholdString = getThresholdConfig(level, null);
193 >            }
194              threshold = Double.parseDouble(thresholdString);
195          } catch (PropertyNotFoundException e) {
196              threshold = -1.0;
# Line 181 | Line 206 | public class Register {
206       * and is converted from the value in the config,
207       * which should be seconds.
208       *
209 +     * Note that if the alert timeout for the current monitor
210 +     * is not configured, it will try to obtain the default
211 +     * timeout for all Monitor's.  If there is no alert timeout
212 +     * for either the monitor or a default setting this returns 0.
213 +     *
214       * Note that this is dependant on the threshold value
215       * given, the timeout is obatined from the config, then
216       * divided by the threshold value, this allows alerts to
217       * progress faster should a higher threshold value be passed
218       *
189     * If there is no alert timeout for a
190     * given level, this returns 0
191     *
219       * @param level the alert level
220       * @param thresholdLevel the threshold leve we are on
221       */
222 <    public long getAlertTimeout(int level, int attributeNum) {
222 >    public long getAlertTimeout(int level) {
223          // 0 means we don't use this value
224          long timeout = 0;
225          try {
226 <            String timeoutString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".alertTimeout." + Alert.alertLevels[level]);
227 <            int threshold = getLastThresholdLevel(attributeNum);
226 >            String timeoutString;
227 >            try {
228 >                timeoutString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".alertTimeout." + Alert.alertLevels[level]);
229 >            } catch (PropertyNotFoundException e) {
230 >                // if there is no timeout for the monitor
231 >                // check for a default
232 >                timeoutString = _cp.getProperty("Host." + _hostname, "Monitor.alertTimeout." + Alert.alertLevels[level]);
233 >            }    
234 >            int threshold = getLastThresholdLevel();
235              if (threshold > 0) {
236                  timeout = (Long.parseLong(timeoutString) / threshold) * 1000;
237              }
# Line 218 | Line 252 | public class Register {
252       * in the list, this is assumed to be FINAL, and special
253       * logic is in place to handle that.
254       *
221     * @param attributeNum the attribute to get next alert for
255       */
256 <    public int getNextAlertLevel(int attributeNum) {
257 <        if((getLastAlertLevel(attributeNum) + 1) > (Alert.alertLevels.length - 2)) {
258 <            return getLastAlertLevel(attributeNum);
256 >    public int getNextAlertLevel() {
257 >        if((getLastAlertLevel() + 1) > (Alert.alertLevels.length - 2)) {
258 >            return getLastAlertLevel();
259          }
260 <        return getLastAlertLevel(attributeNum) + 1;
260 >        return getLastAlertLevel() + 1;
261      }
262  
263      /**
264       * Gets the timeout value of the last alert
265       * sent
266       *
234     * @param attrubuteNum the attribute to get the last timeout for
267       * @return the last timeout value
268       */
269 <    public long getLastAlertTimeout(int attributeNum) {
270 <        return _lastAlertTimeout[attributeNum];
269 >    public long getLastAlertTimeout() {
270 >        return _lastAlertTimeout;
271      }
272      
273      /**
274       * Sets the timeout value of the last alert
275       * sent
276       *
245     * @param attrubuteNum the attribute to get the last timeout for
277       * @param timeout the new value
278       */
279 <    public void setLastAlertTimeout(int attributeNum, long timeout) {
280 <        _lastAlertTimeout[attributeNum] = timeout;
279 >    public void setLastAlertTimeout(long timeout) {
280 >        _lastAlertTimeout = timeout;
281      }
282  
283      /**
284       * Returns the time that the first alert was sent
285       * for an attribute that has passed a threshold value
286       *
256     * @param attrubuteNum the attribute to get the first alert time for
287       */
288 <    public long getInitialAlertTime(int attributeNum) {
289 <        return _initialAlertTime[attributeNum];
288 >    public long getInitialAlertTime() {
289 >        return _initialAlertTime;
290      }
291  
292      /**
# Line 278 | Line 308 | public class Register {
308       * is mis-read or is not configured.  It will NEVER reach
309       * a FINAL.
310       *
281     * @param attributeNum the attribute to advance the alert for
311       */
312 <    public void escalateAlert(int attributeNum) {
312 >    public void escalateAlert() {
313          // don't escalate if we're already on the last alert
314 <        if(getLastAlertLevel(attributeNum) != Alert.alertLevels.length -1) {
315 <            setLastAlertLevel(attributeNum, getNextAlertLevel(attributeNum));
314 >        if(getLastAlertLevel() != Alert.alertLevels.length -1) {
315 >            setLastAlertLevel(getNextAlertLevel());
316          }
317          try {
318              // note if we fail to get this value, we won't process the res of this
319              int reachFINALcount = Integer.parseInt(_cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".reachFINALcount"));
320 <            if (getLastAlertLevel(attributeNum) == Alert.alertLevels.length - 2) {
320 >            if (getLastAlertLevel() == Alert.alertLevels.length - 2) {
321                  _maxLevelCount++;
322 <                if(_maxLevelCount >= reachFINALcount) {
323 <                    setLastAlertLevel(attributeNum, Alert.alertFINAL);
322 >                if(_maxLevelCount > reachFINALcount) {
323 >                    setLastAlertLevel(Alert.alertFINAL);
324                  }
325              }
326          } catch (PropertyNotFoundException e) {
# Line 312 | Line 341 | public class Register {
341       * The monitor this register is for
342       */
343      private String _monitorName;
344 +    
345 +    /**
346 +     * The attribute name, as obtained from
347 +     * the configuration.
348 +     * eg, idle or /var
349 +     */
350 +    private String _attributeName;
351  
352      /**
353       * An array of last alert levels for
354       * each attribute this register is looking
355       * after.
356       */
357 <    private int[] _lastAlertLevels;
357 >    private int _lastAlertLevel;
358      
359      /**
360       * An array of last threshold levels for
361       * each attribute this register is looking
362       * after.
363       */
364 <    private int[] _lastThresholdLevels;
364 >    private int _lastThresholdLevel;
365      
366      /**
367       * An array of last alert timeout levels for
368       * each attribute this register is looking
369       * after.
370       */
371 <    private long[] _lastAlertTimeout;
371 >    private long _lastAlertTimeout;
372      
373      /**
374       * An array of arrays containing
375       * time an alert of each level
376       * was last sent for each attribute.
377       */
378 <    private long[][] _times;
378 >    private long[] _times;
379      
380      /**
381       * Initial times that an alert was first
382       * raised.
383       */
384 <    private long[] _initialAlertTime;
384 >    private long _initialAlertTime;
385  
386      /**
387       * A reference to the configuration proxy in use

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines