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 |
ajm |
1.5 |
* @author $Author: ajm4 $ |
14 |
ajm |
1.6 |
* @version $Id: CPU__Monitor.java,v 1.5 2001/03/02 01:05:53 ajm4 Exp $ |
15 |
tdb |
1.1 |
*/ |
16 |
ajm |
1.6 |
public class CPU__Monitor implements PluginMonitor { |
17 |
tdb |
1.1 |
|
18 |
|
|
//---FINAL ATTRIBUTES--- |
19 |
|
|
|
20 |
|
|
/** |
21 |
|
|
* The current CVS revision of this class |
22 |
|
|
*/ |
23 |
ajm |
1.6 |
public final String REVISION = "$Revision: 1.5 $"; |
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 |
ajm |
1.5 |
_logger.write(toString(), Logger.ERROR, "Invalid configured value for alert level " + x + " - ignoring level."); |
41 |
ajm |
1.2 |
_levels[x] = -1; |
42 |
ajm |
1.4 |
} catch (org.omg.CORBA.MARSHAL e2) { |
43 |
ajm |
1.5 |
_logger.write(toString(), Logger.WARNING, "Alert level " + x + " unused."); |
44 |
ajm |
1.4 |
_levels[x] = -1; |
45 |
ajm |
1.2 |
} |
46 |
ajm |
1.4 |
|
47 |
ajm |
1.2 |
} |
48 |
|
|
} |
49 |
tdb |
1.1 |
//---PUBLIC METHODS--- |
50 |
|
|
|
51 |
|
|
public void analysePacket(XMLPacket packet) { |
52 |
tdb |
1.3 |
String source = packet.getParam("packet.attributes.hostname"); |
53 |
ajm |
1.2 |
for(int x=0; x < _levels.length; x++) { |
54 |
|
|
if (_levels[x] != -1) { |
55 |
|
|
double idle = Double.parseDouble(packet.getParam("packet.cpu.idle")); |
56 |
tdb |
1.3 |
if (_levels[x] < idle) fireAlert(x, source, idle, "idle"); |
57 |
ajm |
1.2 |
double user = Double.parseDouble(packet.getParam("packet.cpu.user")); |
58 |
tdb |
1.3 |
if (_levels[x] < user) fireAlert(x, source, user, "user"); |
59 |
ajm |
1.2 |
double kernel = Double.parseDouble(packet.getParam("packet.cpu.kernel")); |
60 |
tdb |
1.3 |
if (_levels[x] < kernel) fireAlert(x, source, kernel, "kernel"); |
61 |
ajm |
1.2 |
double iowait = Double.parseDouble(packet.getParam("packet.cpu.iowait")); |
62 |
tdb |
1.3 |
if (_levels[x] < iowait) fireAlert(x, source, iowait, "iowait"); |
63 |
ajm |
1.2 |
double swap = Double.parseDouble(packet.getParam("packet.cpu.swap")); |
64 |
tdb |
1.3 |
if (_levels[x] < swap) fireAlert(x, source, swap, "swap"); |
65 |
ajm |
1.2 |
} |
66 |
|
|
} |
67 |
tdb |
1.1 |
} |
68 |
|
|
|
69 |
|
|
/** |
70 |
|
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
71 |
|
|
* method to provide clean logging (every class should have this). |
72 |
|
|
* |
73 |
|
|
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
74 |
|
|
* to format the toString() |
75 |
|
|
* |
76 |
|
|
* @return the name of this class and its CVS revision |
77 |
|
|
*/ |
78 |
|
|
public String toString() { |
79 |
|
|
return FormatName.getName( |
80 |
|
|
_name, |
81 |
|
|
getClass().getName(), |
82 |
|
|
REVISION); |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
/** |
86 |
|
|
* return the String representation of what the filter does |
87 |
|
|
*/ |
88 |
|
|
public String getDescription(){ |
89 |
|
|
return DESC; |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
//---PRIVATE METHODS--- |
93 |
|
|
|
94 |
tdb |
1.3 |
private void fireAlert(int alertLevel, String source, double currentValue, String type) { |
95 |
ajm |
1.2 |
String value = Double.toString(currentValue); |
96 |
|
|
String thresholdValue = Double.toString(_levels[alertLevel]); |
97 |
|
|
String attributeName = "CPU " + type; |
98 |
tdb |
1.3 |
Alert alert = new Alert(alertLevel, source, thresholdValue, value, attributeName); |
99 |
ajm |
1.2 |
_alerterQueue.add(alert); |
100 |
|
|
} |
101 |
|
|
|
102 |
tdb |
1.1 |
//---ACCESSOR/MUTATOR METHODS--- |
103 |
|
|
|
104 |
|
|
//---ATTRIBUTES--- |
105 |
|
|
|
106 |
|
|
/** |
107 |
|
|
* This is the friendly identifier of the |
108 |
|
|
* component this class is running in. |
109 |
|
|
* eg, a Filter may be called "filter1", |
110 |
|
|
* If this class does not have an owning |
111 |
|
|
* component, a name from the configuration |
112 |
|
|
* can be placed here. This name could also |
113 |
|
|
* be changed to null for utility classes. |
114 |
|
|
*/ |
115 |
|
|
private String _name = ClientMain.NAME; |
116 |
|
|
|
117 |
|
|
/** |
118 |
|
|
* This holds a reference to the |
119 |
|
|
* system logger that is being used. |
120 |
|
|
*/ |
121 |
|
|
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
122 |
ajm |
1.2 |
|
123 |
|
|
private double[] _levels; |
124 |
|
|
|
125 |
|
|
private Queue _alerterQueue; |
126 |
|
|
|
127 |
|
|
/** |
128 |
|
|
* A reference to the reference manager in use |
129 |
|
|
*/ |
130 |
|
|
private ReferenceManager _refman = ReferenceManager.getInstance(); |
131 |
tdb |
1.1 |
|
132 |
|
|
//---STATIC ATTRIBUTES--- |
133 |
|
|
|
134 |
|
|
} |