ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/conient/uk/org/iscream/cms/conient/HostDisplayPanel.java
Revision: 1.39
Committed: Tue May 29 17:41:32 2001 UTC (22 years, 11 months ago) by tdb
Branch: MAIN
Changes since 1.38: +6 -6 lines
Log Message:
The last of the central monitoring system packages to be changed to the newer
structure. It has changed from;

uk.org.iscream.conient.*

to;

uk.org.iscream.cms.conient.*

This is in keeping with the new style of packaging.

File Contents

# User Rev Content
1 ajm 1.1 //---PACKAGE DECLARATION---
2 tdb 1.39 package uk.org.iscream.cms.conient;
3 ajm 1.1
4     //---IMPORTS---
5 tdb 1.39 import uk.org.iscream.cms.server.util.*;
6     import uk.org.iscream.cms.conient.datacomponents.*;
7 ajm 1.4 import java.util.HashMap;
8     import java.util.Set;
9     import java.util.Collections;
10     import java.util.Iterator;
11     import javax.swing.BoxLayout;
12     import javax.swing.JPanel;
13     import javax.swing.JProgressBar;
14 ajm 1.13 import javax.swing.JButton;
15     import javax.swing.JLabel;
16     import javax.swing.JFrame;
17     import javax.swing.Box;
18     import java.awt.event.*;
19 ajm 1.31 import java.awt.*;
20 ajm 1.15 import javax.swing.SwingUtilities;
21 tdb 1.17 import javax.swing.ImageIcon;
22 ajm 1.1
23     /**
24 ajm 1.7 * A HostDisplayPanel is simply a JPanel containing
25     * DataComponents which relate to various host
26     * attributes. Once created, it can be asked to
27     * update the data it displays by passing it an XML
28     * packet for the host it displaying for.
29     * This then updates all the DataComponents with the
30     * values in the packet.
31 ajm 1.1 *
32 tdb 1.39 * @author $Author: tdb1 $
33     * @version $Id: HostDisplayPanel.java,v 1.38 2001/03/19 18:06:21 tdb1 Exp $
34 ajm 1.1 */
35     public class HostDisplayPanel extends JPanel {
36    
37     //---FINAL ATTRIBUTES---
38    
39     /**
40     * The current CVS revision of this class
41     */
42 tdb 1.39 public final String REVISION = "$Revision: 1.38 $";
43 ajm 1.1
44     //---STATIC METHODS---
45    
46     //---CONSTRUCTORS---
47    
48     /**
49 ajm 1.7 * Creates a new Host Display Panel and adds
50     * all the appropriate DataComponents
51 ajm 1.1 */
52 ajm 1.13 public HostDisplayPanel(String hostName) {
53 ajm 1.33 super();
54    
55 ajm 1.7 // set up the Panel
56 ajm 1.4 setLayout(new BorderLayout());
57 ajm 1.13 _hostName = hostName;
58    
59 ajm 1.16 // check to config to see if we want extra data or not
60 ajm 1.25 if(Configuration.getInstance().getProperty("displayExtraData").equals("1")) {
61 ajm 1.27 _extraData = true;
62 ajm 1.16 }
63 ajm 1.13
64 ajm 1.31 GridBagLayout gridbag = new GridBagLayout();
65     GridBagConstraints c = new GridBagConstraints();
66     c.fill = GridBagConstraints.HORIZONTAL;
67     c.anchor = GridBagConstraints.NORTH;
68     c.weighty = 1.0;
69     _center.setLayout(gridbag);
70    
71 ajm 1.32 JPanel centerHolder = new JPanel();
72     centerHolder.add(_center);
73     add(centerHolder, "Center");
74 ajm 1.13 add(_north, "North");
75 ajm 1.29
76 ajm 1.13 addDataComponent(new StringDataComponent("Packet Type", "packet.attributes.type"));
77    
78     final StringDataComponent machineName = new StringDataComponent("Host Name", "packet.attributes.machine_name");
79     addDataComponent(machineName );
80     final StringDataComponent ip = new StringDataComponent("IP Address", "packet.attributes.ip");
81     addDataComponent(ip);
82 ajm 1.18 final UptimeDataComponent uptime = new UptimeDataComponent("Uptime", "packet.os.uptime");
83 ajm 1.13 addDataComponent(uptime);
84 ajm 1.15 final StringDataComponent seq_no = new StringDataComponent("Packets since host started", "packet.attributes.seq_no");
85     addDataComponent(seq_no);
86 ajm 1.13
87     final StringDataComponent osName = new StringDataComponent("Operating System", "packet.os.name");
88     addDataComponent(osName );
89     final StringDataComponent osVer = new StringDataComponent("Operating System Version", "packet.os.version");
90     addDataComponent(osVer);
91     final StringDataComponent osRelease = new StringDataComponent("Operating System Release", "packet.os.release");
92     addDataComponent(osRelease);
93     final StringDataComponent osSysName = new StringDataComponent("System Name", "packet.os.sysname");
94     addDataComponent(osSysName );
95 ajm 1.32 final StringDataComponent netbiosName = new StringDataComponent("NetBIOS Name", "packet.os.netbios_name");
96     addDataComponent(netbiosName );
97 ajm 1.13 final StringDataComponent osPlatform = new StringDataComponent("System Architecture", "packet.os.platform");
98     addDataComponent(osPlatform );
99    
100     JButton info = new JButton("Platform Information");
101     info.addActionListener(new ActionListener() {
102     public void actionPerformed(ActionEvent e) {
103     final JFrame infoFrame = new JFrame("Host platform information for - " + _hostName);
104     Box content = Box.createVerticalBox();
105     content.add(machineName);
106     content.add(ip);
107     content.add(uptime);
108 ajm 1.15 content.add(seq_no);
109 ajm 1.13 content.add(osName);
110     content.add(osVer);
111     content.add(osRelease);
112     content.add(osSysName);
113 ajm 1.32 content.add(netbiosName);
114 ajm 1.13 content.add(osPlatform);
115     infoFrame.getContentPane().add(content, "Center");
116     JButton close = new JButton("Close Window");
117     close.addActionListener(new ActionListener() {
118     public void actionPerformed(ActionEvent e) {
119     infoFrame.dispose();
120     }
121     });
122     infoFrame.getContentPane().add(close, "South");
123 ajm 1.24 infoFrame.setIconImage((new ImageIcon("./resources/server.gif")).getImage());
124 ajm 1.13 infoFrame.pack();
125     infoFrame.setVisible(true);
126     }
127     });
128 ajm 1.29 try {
129 tdb 1.38 _heartbeatTimer = new PacketTimer("Next Heartbeat", Integer.parseInt(Configuration.getInstance().getServerProperty("Host." + hostName, "Host.TCPUpdateTime")));
130 ajm 1.35 _dataTimer = new PacketTimer("Next Data", Integer.parseInt(Configuration.getInstance().getServerProperty("Host." + hostName, "Host.UDPUpdateTime")));
131 ajm 1.29 } catch (NumberFormatException e) {
132     throw new NumberFormatException("unable to obtain a valid value for Host.UDP/TCPUpdateTime");
133     }
134 ajm 1.36 _north.setLayout(new GridLayout(2,1));
135     JPanel top1 = new JPanel(new GridLayout(1,1));
136     top1.add(new JLabel("Showing data from - " + hostName, JLabel.CENTER));
137     _north.add(top1);
138     JPanel top2 = new JPanel(new GridLayout(1,3));
139     top2.add(_dataTimer);
140     top2.add(info);
141     top2.add(_heartbeatTimer);
142     _north.add(top2);
143    
144 ajm 1.13
145 ajm 1.19 JPanel date = new JPanel();
146     addVisibleDataComponent(date, new DateDataComponent("Host Time", "packet.attributes.date"));
147 ajm 1.31 c.gridy = 0;
148     gridbag.setConstraints(date, c);
149 ajm 1.19 _center.add(date);
150 ajm 1.13
151 ajm 1.31 // holder for labels
152     JLabel label;
153    
154     label = new javax.swing.JLabel("--- CPU ---", JLabel.CENTER);
155     c.gridy = 1;
156     gridbag.setConstraints(label, c);
157     _center.add(label);
158 tdb 1.6
159 ajm 1.7 // add all the DataComponents that we know about
160 ajm 1.13 JPanel cpu = new JPanel();
161     cpu.setLayout(new BoxLayout(cpu, BoxLayout.Y_AXIS));
162     addVisibleDataComponent(cpu, new CPUDataComponent("CPU Idle", "packet.cpu.idle"));
163     addVisibleDataComponent(cpu, new CPUDataComponent("CPU User", "packet.cpu.user"));
164     addVisibleDataComponent(cpu, new CPUDataComponent("CPU Kernel", "packet.cpu.kernel"));
165     addVisibleDataComponent(cpu, new CPUDataComponent("CPU i/o wait", "packet.cpu.iowait"));
166     addVisibleDataComponent(cpu, new CPUDataComponent("CPU swapping", "packet.cpu.swap"));
167 ajm 1.31 c.gridy = 2;
168     gridbag.setConstraints(cpu, c);
169 ajm 1.13 _center.add(cpu);
170    
171 ajm 1.31 label = new javax.swing.JLabel("--- Load ---", JLabel.CENTER);
172     c.gridy = 3;
173     gridbag.setConstraints(label, c);
174     _center.add(label);
175 ajm 1.13
176     Box loadData = Box.createHorizontalBox();
177     addVisibleDataComponent(loadData, new ProcessesDataComponent("1 minute", "packet.load.load1"));
178     addVisibleDataComponent(loadData, new ProcessesDataComponent("5 minutes", "packet.load.load5"));
179     addVisibleDataComponent(loadData, new ProcessesDataComponent("15 minutes", "packet.load.load15"));
180 ajm 1.31
181     c.gridy = 4;
182     gridbag.setConstraints(loadData, c);
183 ajm 1.13 _center.add(loadData);
184    
185 ajm 1.31 label = new javax.swing.JLabel("--- Processes ---", JLabel.CENTER);
186     c.gridy = 5;
187     gridbag.setConstraints(label, c);
188     _center.add(label);
189 ajm 1.13
190     Box processesData = Box.createHorizontalBox();
191     addVisibleDataComponent(processesData, new ProcessesDataComponent("Total", "packet.processes.total"));
192     addVisibleDataComponent(processesData, new ProcessesDataComponent("Running", "packet.processes.cpu"));
193     addVisibleDataComponent(processesData, new ProcessesDataComponent("Sleeping", "packet.processes.sleeping"));
194     addVisibleDataComponent(processesData, new ProcessesDataComponent("Stopped", "packet.processes.stopped"));
195     addVisibleDataComponent(processesData, new ProcessesDataComponent("Zombie", "packet.processes.zombie"));
196 ajm 1.31 c.gridy = 6;
197     gridbag.setConstraints(processesData, c);
198 ajm 1.13 _center.add(processesData);
199 ajm 1.30
200 ajm 1.31 label = new javax.swing.JLabel("--- Memory ---", JLabel.CENTER);
201     c.gridy = 7;
202     gridbag.setConstraints(label, c);
203     _center.add(label);
204 tdb 1.6
205 ajm 1.7 // these next two are passed the non-visible datacomponents
206 ajm 1.13 JPanel memory = new JPanel();
207     memory.setLayout(new BoxLayout(memory, BoxLayout.Y_AXIS));
208 ajm 1.30 addVisibleDataComponent(memory, new StorageDataComponent("Memory in use", "packet.memory.free", "packet.memory.total","Mb"));
209     addVisibleDataComponent(memory, new StorageDataComponent("Swap in use", "packet.swap.free", "packet.swap.total", "Mb"));
210     // theses next two are DataComponents, but not VisibleDataComponents
211     // this is because they hold the value but do NOT display it
212     // just so we ignore the data, because the StorageDataComponent handles it
213     addDataComponent(new StringDataComponent("packet.memory.total", "packet.memory.total"));
214     addDataComponent(new StringDataComponent("packet.swap.total", "packet.swap.total"));
215 ajm 1.31 c.gridy = 8;
216     gridbag.setConstraints(memory, c);
217 ajm 1.13 _center.add(memory);
218 ajm 1.19
219 ajm 1.31 label = new javax.swing.JLabel("--- Users ---", JLabel.CENTER);
220     c.gridy = 9;
221     gridbag.setConstraints(label, c);
222     _center.add(label);
223    
224 ajm 1.19 JPanel users = new JPanel();
225 ajm 1.31 users.setLayout(new BoxLayout(users, BoxLayout.Y_AXIS));
226 ajm 1.19 addVisibleDataComponent(users, new StringDataComponent("Number of users", "packet.users.count"));
227     UsersDataComponent userList = new UsersDataComponent("User List", "packet.users.list");
228     addVisibleDataComponent(users, userList);
229 ajm 1.31 c.gridy = 10;
230     gridbag.setConstraints(users, c);
231 ajm 1.19 _center.add(users);
232 ajm 1.31
233     label = new javax.swing.JLabel("--- Disks ---", JLabel.CENTER);
234     c.gridy = 11;
235     gridbag.setConstraints(label, c);
236     _center.add(label);
237     c.gridy = 12;
238     gridbag.setConstraints(_disks, c);
239 ajm 1.14 _center.add(_disks);
240    
241 ajm 1.31 label = new javax.swing.JLabel("--- System Services ---", JLabel.CENTER);
242     c.gridy = 13;
243     gridbag.setConstraints(label, c);
244     _center.add(label);
245     c.gridy = 14;
246     gridbag.setConstraints(_services, c);
247 ajm 1.20 _center.add(_services);
248    
249 ajm 1.16 // everything else we get is "extra", but we may still want to display it
250 ajm 1.27 if (_extraData) {
251 ajm 1.31 label = new javax.swing.JLabel("--- Extra Data ---", JLabel.CENTER);
252     c.gridy = 15;
253     gridbag.setConstraints(label, c);
254     _center.add(label);
255     c.gridy = 16;
256     gridbag.setConstraints(_extra, c);
257 ajm 1.20 _center.add(_extra);
258 ajm 1.16 }
259 ajm 1.37
260     // a bit of a gap, then a banner to advertise the product
261     c.gridy=17;
262     Component spacer = Box.createRigidArea(new Dimension(468, 30));
263     gridbag.setConstraints(spacer,c);
264     _center.add(spacer);
265     c.gridy=18;
266     JLabel image = new JLabel(new ImageIcon("./resources/banner3.gif"));
267     gridbag.setConstraints(image,c);
268     _center.add(image);
269 ajm 1.1 }
270    
271     //---PUBLIC METHODS---
272    
273 ajm 1.7 /**
274     * This method takes an XMLPacket containing
275     * information about the host this HostDisplayPanel
276     * is currently displaying. It then updates all of the
277     * components with the new values.
278     *
279     * It also adds a standard StringDataComponent, should
280     * an attribute come up that there are no DataComponents
281     * associated with.
282     *
283     * @param packet the XML packet
284     * @return if the update was sucessful
285     */
286     public boolean updateHost(XMLPacket packet) {
287     // set that everything is ok so far
288 ajm 1.20 boolean displaySucessful = true;
289 ajm 1.7
290     // a simple way to handle heatbeats - this WILL change
291 ajm 1.4 if ((packet.getParam("packet.attributes.type")).equals("heartbeat")) {
292 ajm 1.12 _heartbeatTimer.reset();
293     if(_heartbeatTimerThread == null){
294     _heartbeatTimerThread = new Thread(_heartbeatTimer);
295     _heartbeatTimerThread.start();
296 ajm 1.19 }
297 ajm 1.27 displaySucessful = processPacket(packet);
298 ajm 1.7
299     // must be a normal data packet, update the display
300 ajm 1.12 } else if((packet.getParam("packet.attributes.type")).equals("data")) {
301 ajm 1.27 displaySucessful = processPacket(packet);
302 ajm 1.12 _dataTimer.reset();
303     if(_dataTimerThread == null){
304     _dataTimerThread = new Thread(_dataTimer);
305     _dataTimerThread.start();
306     }
307 ajm 1.20 }
308     return displaySucessful;
309     }
310    
311     //---PRIVATE METHODS---
312    
313     /**
314     * Process an incoming packet, updates the components.
315     * If extra data is configured to be displayed, it will
316     * create a new StringDataComponent to display the data.
317     *
318     * @param packet the packet to process
319     *
320     * @return if the proceesing was successful
321     */
322 ajm 1.27 private boolean processPacket(XMLPacket packet) {
323 ajm 1.20 // iterate over the packets data
324     boolean displaySucessful = true;
325     Set packetSet = packet.getSet();
326     Iterator i = packetSet.iterator();
327     while (i.hasNext()) {
328     String dataKey = (String) i.next();
329    
330     // if there are no components looking after this data
331     // create a new StringDataComponent for it
332     if(!_components.containsKey(dataKey)) {
333     // check if its a disk drive, if it is then we need to deal with it
334     if(dataKey.startsWith("packet.disk.p")) {
335     createDiskPanel(dataKey);
336    
337     // !check for services here! to display
338 ajm 1.27 } else if(dataKey.startsWith("packet.services.")) {
339     createServicesPanel(dataKey);
340 ajm 1.20
341 ajm 1.27 } else if (_extraData) {
342     addVisibleDataComponent(_extra, new StringDataComponent(dataKey, dataKey));
343 ajm 1.4 }
344 ajm 1.20 }
345 ajm 1.22
346 ajm 1.20 // try and update the component, if it doesn't like what it gets
347     // warn the user and set that this was an unsucessful display
348 ajm 1.22 if(_components.containsKey(dataKey)) {
349    
350     try {
351 ajm 1.30 ((DataComponent) _components.get(dataKey)).setValue(packet);
352 ajm 1.22 } catch (DataFormatException e) {
353     Conient.addMessage("WARNING{host display}: " + e.getMessage());
354     displaySucessful = false;
355     }
356 ajm 1.4 }
357 ajm 1.3 }
358 ajm 1.20 return displaySucessful;
359 ajm 1.4 }
360 ajm 1.15
361 ajm 1.7 /**
362     * Adds a DataComponent to the list of already
363     * known data components. The list is aware of
364     * what packet attributes that a DataComponent
365     * is looking after.
366     *
367     * @param ref the packet attribute that this Component looks after
368     * @param dataComponent the actual DataComponent
369     */
370 ajm 1.13 private void addDataComponent(DataComponent dataComponent) {
371     _components.put(dataComponent.getPacketAttribute(), dataComponent);
372 ajm 1.7 }
373    
374     /**
375     * Adds a DataComponent to the list of already
376     * known data components. The list is aware of
377     * what packet attributes that a DataComponent
378     * is looking after.
379     *
380     * Used for VISIBLE data components, as they are added to the display.
381     *
382     * @param ref the packet attribute that this Component looks after
383     * @param dataComponent the actual DataComponent
384     */
385 ajm 1.13 public void addVisibleDataComponent(Container holder, VisibleDataComponent dataComponent) {
386     _components.put(((DataComponent) dataComponent).getPacketAttribute(), (DataComponent) dataComponent);
387 ajm 1.15 SwingSafeAdd task = new SwingSafeAdd(holder, dataComponent);
388     SwingUtilities.invokeLater(task);
389     }
390    
391     /**
392     * Creates the disk components and adds them
393     * do the list of components. It also displays
394     * any relavant component.
395     *
396     * When a packet attribute is new to the system
397     * and when it starts "packet.disk.p" then this
398     * method is called. Thus it then accounts for
399     * all attributes relating to that new disk.
400     *
401     * @param attribute the name of the attrivbute first encountered
402     */
403     private void createDiskPanel(String attribute) {
404     String diskNumber = "";
405    
406     // pos is after "packet.disk.p"
407     int pos = 13;
408     while (attribute.charAt(pos) != '.') {
409     diskNumber = diskNumber + attribute.charAt(pos);
410     pos++;
411     }
412 ajm 1.30 String devAttribute = "packet.disk.p" + diskNumber + ".attributes.name";
413     String mountAttribute = "packet.disk.p" + diskNumber + ".attributes.mount";
414     String totalAttribute = "packet.disk.p" + diskNumber + ".attributes.kbytes";
415    
416     // the only visible component
417     String availAttribute = "packet.disk.p" + diskNumber + ".attributes.avail";
418     DiskDataComponent disk = new DiskDataComponent("Disk", availAttribute, totalAttribute, mountAttribute, devAttribute , "Mb", 1024);
419     addVisibleDataComponent(_disks, disk);
420 ajm 1.15
421 ajm 1.16 // currently this data isn't useful, so we don't display it
422     // but we add it so that it is forgotten about
423 ajm 1.30 addDataComponent(new StringDataComponent(devAttribute, devAttribute));
424     addDataComponent(new StringDataComponent(mountAttribute, mountAttribute));
425     addDataComponent(new StringDataComponent(totalAttribute, totalAttribute));
426 tdb 1.17 addDataComponent(new StringDataComponent("packet.disk.p" + diskNumber + ".used", "packet.disk.p" + diskNumber + ".attributes.used"));
427 ajm 1.1 }
428 ajm 1.27
429     /**
430     * Creates the disk components and adds them
431     * do the list of components. It also displays
432     * any relavant component.
433     *
434     * When a packet attribute is new to the system
435     * and when it starts "packet.disk.p" then this
436     * method is called. Thus it then accounts for
437     * all attributes relating to that new disk.
438     *
439     * @param attribute the name of the attrivbute first encountered
440     */
441     private void createServicesPanel(String attribute) {
442     String serviceType = "";
443    
444     // pos is after "packet.services."
445     int pos = 16;
446     while (attribute.charAt(pos) != '.') {
447     serviceType = serviceType + attribute.charAt(pos);
448     pos++;
449     }
450 ajm 1.30
451     String statusAttribute = "packet.services." + serviceType + ".attributes.status";
452     // we hide this as the service data component uses this attribute
453     addDataComponent(new StringDataComponent(serviceType + " service status", statusAttribute));
454 ajm 1.27
455 ajm 1.30 ServiceDataComponent service = new ServiceDataComponent(serviceType, "packet.services." + serviceType + ".attributes.message", statusAttribute);
456 ajm 1.27 addVisibleDataComponent(_services, service);
457     }
458 ajm 1.15
459     //---ACCESSOR/MUTATOR METHODS---
460 ajm 1.1
461 ajm 1.7 //---ATTRIBUTES---
462    
463     /**
464     * The components that we already know about
465     * connected with the attributes they care about
466     * are stored here.
467     */
468     private HashMap _components = new HashMap();
469 ajm 1.12
470 ajm 1.7 /**
471 ajm 1.13 * The north panel, currently used for the platform info button.
472     */
473     private final JPanel _north = new JPanel();
474 ajm 1.12
475     /**
476 ajm 1.7 * The centre panel, where all the data is displayed.
477     */
478 ajm 1.11 private final JPanel _center = new JPanel();
479 ajm 1.1
480 ajm 1.16 /**
481     * The countdown timer for heartbeats
482     */
483 ajm 1.12 private final PacketTimer _heartbeatTimer;
484 ajm 1.16
485     /**
486     * The countdown timer for normal data packets
487     */
488 ajm 1.12 private final PacketTimer _dataTimer;
489 ajm 1.16
490     /**
491     * A place for the heartbeat timer thread
492     */
493 ajm 1.12 private Thread _heartbeatTimerThread = null;
494 ajm 1.16
495     /**
496     * A place for the data timer thread
497     */
498 ajm 1.12 private Thread _dataTimerThread = null;
499 ajm 1.16
500     /**
501     * The hostname this instance is keeping data for
502     */
503 ajm 1.13 private final String _hostName;
504 ajm 1.16
505     /**
506     * The disks panel
507     */
508 ajm 1.20 private final JPanel _disks = new JPanel();
509     {
510     _disks.setLayout(new BoxLayout(_disks, BoxLayout.Y_AXIS));
511     }
512    
513     /**
514     * The extra panel, used to display unknown data in the packet
515     */
516     private final JPanel _extra = new JPanel();
517     {
518     _extra.setLayout(new BoxLayout(_extra, BoxLayout.Y_AXIS));
519     }
520    
521     /**
522     * The services panel, currently used to display host service information
523     * from heartbeat packets.
524     */
525     private final JPanel _services = new JPanel();
526     {
527     _services.setLayout(new BoxLayout(_services, BoxLayout.Y_AXIS));
528     }
529 ajm 1.16
530     /**
531     * Whether we a worrying about "extra" data
532 ajm 1.25 * by default we don't, but we look in the configuration
533 ajm 1.16 * in the constructor.
534     */
535 ajm 1.27 private boolean _extraData = false;
536 ajm 1.14
537 ajm 1.1 //---STATIC ATTRIBUTES---
538    
539 ajm 1.3 }