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/CPU__Monitor.java
Revision: 1.3
Committed: Fri Mar 2 00:35:52 2001 UTC (23 years, 3 months ago) by tdb
Branch: MAIN
Changes since 1.2: +11 -10 lines
Log Message:
It seems we forgot something vital... the source of the message :)

File Contents

# User Rev Content
1 tdb 1.1 //---PACKAGE DECLARATION---
2     package uk.ac.ukc.iscream.client.monitors;
3    
4     //---IMPORTS---
5     import uk.ac.ukc.iscream.client.*;
6     import uk.ac.ukc.iscream.core.*;
7     import uk.ac.ukc.iscream.util.*;
8     import uk.ac.ukc.iscream.componentmanager.*;
9    
10     /**
11     * This Monitor watches the CPU load for all machines
12     *
13 tdb 1.3 * @author $Author: ajm4 $
14     * @version $Id: CPU__Monitor.java,v 1.2 2001/03/02 00:16:20 ajm4 Exp $
15 tdb 1.1 */
16     public class CPU__Monitor implements Monitor {
17    
18     //---FINAL ATTRIBUTES---
19    
20     /**
21     * The current CVS revision of this class
22     */
23 tdb 1.3 public final String REVISION = "$Revision: 1.2 $";
24 tdb 1.1
25     public final String DESC = "Monitors CPU.";
26    
27     //---STATIC METHODS---
28    
29     //---CONSTRUCTORS---
30    
31 ajm 1.2 public CPU__Monitor() {
32     _alerterQueue = ClientMain._alerterQueue;
33     // get the configuration for this plug-in
34     Configuration config = _refman.getCM().getConfiguration(_name);
35     _levels = new double[(Alert.alerts).length];
36     for (int x = 0; x < Alert.alerts.length; x++) {
37     try {
38     _levels[x] = Double.parseDouble(config.getProperty("Monitor.CPU.level." + x));
39     } catch (NumberFormatException e) {
40     _levels[x] = -1;
41     }
42     }
43     }
44 tdb 1.1 //---PUBLIC METHODS---
45    
46     public void analysePacket(XMLPacket packet) {
47 tdb 1.3 String source = packet.getParam("packet.attributes.hostname");
48 ajm 1.2 for(int x=0; x < _levels.length; x++) {
49     if (_levels[x] != -1) {
50     double idle = Double.parseDouble(packet.getParam("packet.cpu.idle"));
51 tdb 1.3 if (_levels[x] < idle) fireAlert(x, source, idle, "idle");
52 ajm 1.2 double user = Double.parseDouble(packet.getParam("packet.cpu.user"));
53 tdb 1.3 if (_levels[x] < user) fireAlert(x, source, user, "user");
54 ajm 1.2 double kernel = Double.parseDouble(packet.getParam("packet.cpu.kernel"));
55 tdb 1.3 if (_levels[x] < kernel) fireAlert(x, source, kernel, "kernel");
56 ajm 1.2 double iowait = Double.parseDouble(packet.getParam("packet.cpu.iowait"));
57 tdb 1.3 if (_levels[x] < iowait) fireAlert(x, source, iowait, "iowait");
58 ajm 1.2 double swap = Double.parseDouble(packet.getParam("packet.cpu.swap"));
59 tdb 1.3 if (_levels[x] < swap) fireAlert(x, source, swap, "swap");
60 ajm 1.2 }
61     }
62 tdb 1.1 }
63    
64     /**
65     * Overrides the {@link java.lang.Object#toString() Object.toString()}
66     * method to provide clean logging (every class should have this).
67     *
68     * This uses the uk.ac.ukc.iscream.util.NameFormat class
69     * to format the toString()
70     *
71     * @return the name of this class and its CVS revision
72     */
73     public String toString() {
74     return FormatName.getName(
75     _name,
76     getClass().getName(),
77     REVISION);
78     }
79    
80     /**
81     * return the String representation of what the filter does
82     */
83     public String getDescription(){
84     return DESC;
85     }
86    
87     //---PRIVATE METHODS---
88    
89 tdb 1.3 private void fireAlert(int alertLevel, String source, double currentValue, String type) {
90 ajm 1.2 String value = Double.toString(currentValue);
91     String thresholdValue = Double.toString(_levels[alertLevel]);
92     String attributeName = "CPU " + type;
93 tdb 1.3 Alert alert = new Alert(alertLevel, source, thresholdValue, value, attributeName);
94 ajm 1.2 _alerterQueue.add(alert);
95     }
96    
97 tdb 1.1 //---ACCESSOR/MUTATOR METHODS---
98    
99     //---ATTRIBUTES---
100    
101     /**
102     * This is the friendly identifier of the
103     * component this class is running in.
104     * eg, a Filter may be called "filter1",
105     * If this class does not have an owning
106     * component, a name from the configuration
107     * can be placed here. This name could also
108     * be changed to null for utility classes.
109     */
110     private String _name = ClientMain.NAME;
111    
112     /**
113     * This holds a reference to the
114     * system logger that is being used.
115     */
116     private Logger _logger = ReferenceManager.getInstance().getLogger();
117 ajm 1.2
118     private double[] _levels;
119    
120     private Queue _alerterQueue;
121    
122     /**
123     * A reference to the reference manager in use
124     */
125     private ReferenceManager _refman = ReferenceManager.getInstance();
126 tdb 1.1
127     //---STATIC ATTRIBUTES---
128    
129     }