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/Process__Monitor.java
Revision: 1.4
Committed: Tue May 29 17:02:34 2001 UTC (22 years, 11 months ago) by tdb
Branch: MAIN
Branch point for: SERVER_PIRCBOT
Changes since 1.3: +9 -9 lines
Log Message:
Major change in the java package naming. This has been held off for some time
now, but it really needed doing. The future packaging of all i-scream products
will be;

uk.org.iscream.<product>.<subpart>.*

In the case of the central monitoring system server this will be;

uk.org.iscream.cms.server.*

The whole server has been changed to follow this structure, and tested to a
smallish extent. Further changes in other parts of the CMS will follow.

File Contents

# User Rev Content
1 tdb 1.1 //---PACKAGE DECLARATION---
2 tdb 1.4 package uk.org.iscream.cms.server.client.monitors;
3 tdb 1.1
4     //---IMPORTS---
5     import java.util.HashMap;
6 tdb 1.4 import uk.org.iscream.cms.server.client.*;
7     import uk.org.iscream.cms.server.core.*;
8     import uk.org.iscream.cms.server.util.*;
9     import uk.org.iscream.cms.server.componentmanager.*;
10 tdb 1.1
11     /**
12     * This Monitor watches the Process Counts for all machines
13     *
14 tdb 1.4 * @author $Author: tdb1 $
15     * @version $Id: Process__Monitor.java,v 1.3 2001/03/23 02:32:49 tdb1 Exp $
16 tdb 1.1 */
17     public class Process__Monitor extends MonitorSkeleton {
18    
19     //---FINAL ATTRIBUTES---
20    
21     /**
22     * The current CVS revision of this class
23     */
24 tdb 1.4 public final String REVISION = "$Revision: 1.3 $";
25 tdb 1.1
26 tdb 1.3 /**
27     * A description of this monitor
28     */
29 tdb 1.1 public final String DESC = "Monitors Process Counts.";
30    
31     //---STATIC METHODS---
32    
33     //---CONSTRUCTORS---
34    
35     //---PUBLIC METHODS---
36 tdb 1.3
37     /**
38     * Analyse a packet of data, and generate an alert if
39     * necessary.
40     *
41     * @param packet the XMLPacket to analyse
42     */
43 tdb 1.1 public void analysePacket(XMLPacket packet) {
44    
45 ajm 1.2 String source = packet.getParam("packet.attributes.machine_name");
46     if (!_hosts.containsKey(source)) {
47     HashMap attributeRegisters = new HashMap();
48     initAttributeRegsiters(source, attributeRegisters);
49     _hosts.put(source, attributeRegisters);
50     }
51    
52     HashMap attributeRegisters = (HashMap) _hosts.get(source);
53     for(int attributeNum = 0; attributeNum < _attributes.length; attributeNum++) {
54     Register reg = (Register) attributeRegisters.get(_attributes[attributeNum]);
55     // find out the threshold level we're at
56     String attribute = _attributes[attributeNum];
57     String attributeName = _attributeNames[attributeNum];
58     String currentValue = packet.getParam(attribute);
59     int newThreshold = checkAttributeThreshold(currentValue, reg);
60     processAlert(newThreshold, attributeName, reg, source, currentValue);
61 tdb 1.1 }
62     }
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 tdb 1.4 * This uses the uk.org.iscream.cms.server.util.NameFormat class
69 tdb 1.1 * 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 monitor does
82     */
83     public String getDescription(){
84     return DESC;
85     }
86    
87     //---PRIVATE METHODS---
88 tdb 1.3
89     /**
90     * Checks a piece of current data, and returns the
91     * threshold it breaches, if any.
92     *
93     * @param attributeString a String representing the current data value
94     * @param reg the Register for the host
95     * @return the threshold level breached, if any
96     */
97 tdb 1.1 private int checkAttributeThreshold(String attributeString, Register reg) {
98     for(int thresholdLevel = Alert.thresholdLevels.length - 1; thresholdLevel >= 0; thresholdLevel--) {
99     if (reg.getThreshold(thresholdLevel) != -1.0) {
100     if(attributeString != null) {
101     try {
102     double attribute = Double.parseDouble(attributeString);
103     if (reg.getThreshold(thresholdLevel) < attribute) return thresholdLevel;
104     } catch (NumberFormatException e) {
105     // we got some duff data in the packet, but we shouldn't have
106     _logger.write(toString(), Logger.DEBUG, "possible errenous packet data, should be double value - " + attributeString);
107     }
108     }
109     }
110     }
111     return Alert.thresholdNORMAL;
112     }
113 tdb 1.3
114     /**
115     * Initialises a HashMap of Registers with the current list
116     * of attributes. This is only used if we are looking at more
117     * than one distinct attribute.
118     *
119     * @param source the host we are looking at
120     * @param attributeRegisters a HashMap to put the new Registers in
121     */
122 tdb 1.1 private void initAttributeRegsiters(String source, HashMap attributeRegisters) {
123     for(int attributeNum = 0; attributeNum < _attributes.length; attributeNum++) {
124     String attributeName = _attributes[attributeNum].substring(_attributes[attributeNum].lastIndexOf(".") + 1);
125     attributeRegisters.put(_attributes[attributeNum], new Register(source, _name, attributeName));
126     }
127     }
128    
129     //---ACCESSOR/MUTATOR METHODS---
130 tdb 1.3
131     /**
132     * Returns a reference to a specific Queue for this
133     * monitor. This Queue returns only the data packets
134     * (based on type) that we want too look at.
135     *
136     * @return a reference to a Queue
137     */
138 ajm 1.2 protected Queue getQueue() {
139     return MonitorManager.getInstance().getDataQueue();
140     }
141 tdb 1.1
142     //---ATTRIBUTES---
143    
144     /**
145     * This is the friendly identifier of the
146     * component this class is running in.
147     * eg, a Filter may be called "filter1",
148     * If this class does not have an owning
149     * component, a name from the configuration
150     * can be placed here. This name could also
151     * be changed to null for utility classes.
152     */
153     private String _name = "Process";
154    
155     /**
156 tdb 1.3 * A HashMap of Registers (or groups of Registers), one
157     * for each host we're monitoring.
158 tdb 1.1 */
159     private HashMap _hosts = new HashMap();
160 tdb 1.3
161     /**
162     * An array of attributes which we will be checking.
163     */
164 tdb 1.1 private String[] _attributes = { "packet.processes.total", "packet.processes.cpu", "packet.processes.sleeping", "packet.processes.stopped", "packet.processes.zombie" };
165 tdb 1.3
166     /**
167     * An array of "nice names" for the attributes in _attributes.
168     */
169 tdb 1.1 private String[] _attributeNames = {"Total Processes", "on CPU Processes", "Sleeping Processes", "Stopped Processes", "Zombie Processes"};
170    
171     //---STATIC ATTRIBUTES---
172    
173     }