1 |
/* |
2 |
* i-scream central monitoring system |
3 |
* http://www.i-scream.org |
4 |
* Copyright (C) 2000-2002 i-scream |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or |
7 |
* modify it under the terms of the GNU General Public License |
8 |
* as published by the Free Software Foundation; either version 2 |
9 |
* of the License, or (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
*/ |
20 |
|
21 |
//---PACKAGE DECLARATION--- |
22 |
package uk.org.iscream.cms.conient; |
23 |
|
24 |
//---IMPORTS--- |
25 |
import uk.org.iscream.cms.util.*; |
26 |
import uk.org.iscream.cms.conient.datacomponents.*; |
27 |
import java.util.HashMap; |
28 |
import java.util.Set; |
29 |
import java.util.Collections; |
30 |
import java.util.Iterator; |
31 |
import javax.swing.BoxLayout; |
32 |
import javax.swing.JPanel; |
33 |
import javax.swing.JProgressBar; |
34 |
import javax.swing.JButton; |
35 |
import javax.swing.JLabel; |
36 |
import javax.swing.JFrame; |
37 |
import javax.swing.Box; |
38 |
import java.awt.event.*; |
39 |
import java.awt.*; |
40 |
import javax.swing.SwingUtilities; |
41 |
import javax.swing.ImageIcon; |
42 |
|
43 |
/** |
44 |
* A HostDisplayPanel is simply a JPanel containing |
45 |
* DataComponents which relate to various host |
46 |
* attributes. Once created, it can be asked to |
47 |
* update the data it displays by passing it an XML |
48 |
* packet for the host it displaying for. |
49 |
* This then updates all the DataComponents with the |
50 |
* values in the packet. |
51 |
* |
52 |
* @author $Author: tdb $ |
53 |
* @version $Id: HostDisplayPanel.java,v 1.52 2004/08/01 10:40:06 tdb Exp $ |
54 |
*/ |
55 |
public class HostDisplayPanel extends JPanel { |
56 |
|
57 |
//---FINAL ATTRIBUTES--- |
58 |
|
59 |
/** |
60 |
* The current CVS revision of this class |
61 |
*/ |
62 |
public final String REVISION = "$Revision: 1.52 $"; |
63 |
|
64 |
//---STATIC METHODS--- |
65 |
|
66 |
//---CONSTRUCTORS--- |
67 |
|
68 |
/** |
69 |
* Creates a new Host Display Panel and adds |
70 |
* all the appropriate DataComponents |
71 |
*/ |
72 |
public HostDisplayPanel(String hostName) { |
73 |
super(); |
74 |
|
75 |
// set up the Panel |
76 |
setLayout(new BorderLayout()); |
77 |
_hostName = hostName; |
78 |
|
79 |
// check to config to see if we want extra data or not |
80 |
if(Configuration.getInstance().getProperty("displayExtraData").equals("1")) { |
81 |
_extraData = true; |
82 |
} |
83 |
|
84 |
GridBagLayout gridbag = new GridBagLayout(); |
85 |
GridBagConstraints c = new GridBagConstraints(); |
86 |
c.fill = GridBagConstraints.HORIZONTAL; |
87 |
c.anchor = GridBagConstraints.NORTH; |
88 |
c.weighty = 1.0; |
89 |
_center.setLayout(gridbag); |
90 |
|
91 |
JPanel centerHolder = new JPanel(); |
92 |
centerHolder.add(_center); |
93 |
add(centerHolder, "Center"); |
94 |
add(_north, "North"); |
95 |
|
96 |
addDataComponent(new StringDataComponent("Packet Type", "packet.attributes.type")); |
97 |
|
98 |
final StringDataComponent machineName = new StringDataComponent("Host Name", "packet.attributes.machine_name"); |
99 |
addDataComponent(machineName ); |
100 |
final StringDataComponent ip = new StringDataComponent("IP Address", "packet.attributes.ip"); |
101 |
addDataComponent(ip); |
102 |
final UptimeDataComponent uptime = new UptimeDataComponent("Uptime", "packet.os.uptime"); |
103 |
addDataComponent(uptime); |
104 |
final StringDataComponent seq_no = new StringDataComponent("Packets since host started", "packet.attributes.seq_no"); |
105 |
addDataComponent(seq_no); |
106 |
|
107 |
final StringDataComponent osName = new StringDataComponent("Operating System", "packet.os.name"); |
108 |
addDataComponent(osName ); |
109 |
final StringDataComponent osVer = new StringDataComponent("Operating System Version", "packet.os.version"); |
110 |
addDataComponent(osVer); |
111 |
final StringDataComponent osRelease = new StringDataComponent("Operating System Release", "packet.os.release"); |
112 |
addDataComponent(osRelease); |
113 |
final StringDataComponent osSysName = new StringDataComponent("System Name", "packet.os.sysname"); |
114 |
addDataComponent(osSysName ); |
115 |
final StringDataComponent netbiosName = new StringDataComponent("NetBIOS Name", "packet.os.netbios_name"); |
116 |
addDataComponent(netbiosName ); |
117 |
final StringDataComponent osPlatform = new StringDataComponent("System Architecture", "packet.os.platform"); |
118 |
addDataComponent(osPlatform ); |
119 |
|
120 |
JButton info = new JButton("Platform Information"); |
121 |
info.addActionListener(new ActionListener() { |
122 |
public void actionPerformed(ActionEvent e) { |
123 |
final JFrame infoFrame = new JFrame("Host platform information for - " + _hostName); |
124 |
Box content = Box.createVerticalBox(); |
125 |
content.add(machineName); |
126 |
content.add(ip); |
127 |
content.add(uptime); |
128 |
content.add(seq_no); |
129 |
content.add(osName); |
130 |
content.add(osVer); |
131 |
content.add(osRelease); |
132 |
content.add(osSysName); |
133 |
content.add(netbiosName); |
134 |
content.add(osPlatform); |
135 |
infoFrame.getContentPane().add(content, "Center"); |
136 |
JButton close = new JButton("Close Window"); |
137 |
close.addActionListener(new ActionListener() { |
138 |
public void actionPerformed(ActionEvent e) { |
139 |
infoFrame.dispose(); |
140 |
} |
141 |
}); |
142 |
infoFrame.getContentPane().add(close, "South"); |
143 |
infoFrame.setIconImage((new ImageIcon(getClass().getResource("/resources/server.gif"))).getImage()); |
144 |
infoFrame.pack(); |
145 |
infoFrame.setVisible(true); |
146 |
} |
147 |
}); |
148 |
try { |
149 |
_dataTimer = new PacketTimer("Next Data", Integer.parseInt(Configuration.getInstance().getServerProperty("Host." + hostName, "Host.UDPUpdateTime"))); |
150 |
} catch (NumberFormatException e) { |
151 |
throw new NumberFormatException("unable to obtain a valid value for Host.UDPUpdateTime"); |
152 |
} |
153 |
_north.setLayout(new GridLayout(3,1)); |
154 |
_north.add(new JLabel("Showing data from - " + hostName, JLabel.CENTER)); |
155 |
_north.add(_dataTimer); |
156 |
_north.add(info); |
157 |
|
158 |
|
159 |
JPanel date = new JPanel(); |
160 |
addVisibleDataComponent(date, new DateDataComponent("Host Time", "packet.attributes.date")); |
161 |
c.gridy = 0; |
162 |
gridbag.setConstraints(date, c); |
163 |
_center.add(date); |
164 |
|
165 |
// holder for labels |
166 |
JLabel label; |
167 |
|
168 |
label = new javax.swing.JLabel("--- CPU ---", JLabel.CENTER); |
169 |
c.gridy = 1; |
170 |
gridbag.setConstraints(label, c); |
171 |
_center.add(label); |
172 |
|
173 |
// add all the DataComponents that we know about |
174 |
JPanel cpu = new JPanel(); |
175 |
cpu.setLayout(new BoxLayout(cpu, BoxLayout.Y_AXIS)); |
176 |
addVisibleDataComponent(cpu, new CPUDataComponent("CPU Idle", "packet.cpu.idle")); |
177 |
addVisibleDataComponent(cpu, new CPUDataComponent("CPU User", "packet.cpu.user")); |
178 |
addVisibleDataComponent(cpu, new CPUDataComponent("CPU Kernel", "packet.cpu.kernel")); |
179 |
addVisibleDataComponent(cpu, new CPUDataComponent("CPU i/o wait", "packet.cpu.iowait")); |
180 |
addVisibleDataComponent(cpu, new CPUDataComponent("CPU swapping", "packet.cpu.swap")); |
181 |
c.gridy = 2; |
182 |
gridbag.setConstraints(cpu, c); |
183 |
_center.add(cpu); |
184 |
|
185 |
label = new javax.swing.JLabel("--- Load ---", JLabel.CENTER); |
186 |
c.gridy = 3; |
187 |
gridbag.setConstraints(label, c); |
188 |
_center.add(label); |
189 |
|
190 |
Box loadData = Box.createHorizontalBox(); |
191 |
addVisibleDataComponent(loadData, new ProcessesDataComponent("1 minute", "packet.load.load1")); |
192 |
addVisibleDataComponent(loadData, new ProcessesDataComponent("5 minutes", "packet.load.load5")); |
193 |
addVisibleDataComponent(loadData, new ProcessesDataComponent("15 minutes", "packet.load.load15")); |
194 |
|
195 |
c.gridy = 4; |
196 |
gridbag.setConstraints(loadData, c); |
197 |
_center.add(loadData); |
198 |
|
199 |
label = new javax.swing.JLabel("--- Processes ---", JLabel.CENTER); |
200 |
c.gridy = 5; |
201 |
gridbag.setConstraints(label, c); |
202 |
_center.add(label); |
203 |
|
204 |
Box processesData = Box.createHorizontalBox(); |
205 |
addVisibleDataComponent(processesData, new ProcessesDataComponent("Total", "packet.processes.total")); |
206 |
addVisibleDataComponent(processesData, new ProcessesDataComponent("Running", "packet.processes.cpu")); |
207 |
addVisibleDataComponent(processesData, new ProcessesDataComponent("Sleeping", "packet.processes.sleeping")); |
208 |
addVisibleDataComponent(processesData, new ProcessesDataComponent("Stopped", "packet.processes.stopped")); |
209 |
addVisibleDataComponent(processesData, new ProcessesDataComponent("Zombie", "packet.processes.zombie")); |
210 |
c.gridy = 6; |
211 |
gridbag.setConstraints(processesData, c); |
212 |
_center.add(processesData); |
213 |
|
214 |
label = new javax.swing.JLabel("--- Memory ---", JLabel.CENTER); |
215 |
c.gridy = 7; |
216 |
gridbag.setConstraints(label, c); |
217 |
_center.add(label); |
218 |
|
219 |
// these next two are passed the non-visible datacomponents |
220 |
JPanel memory = new JPanel(); |
221 |
memory.setLayout(new BoxLayout(memory, BoxLayout.Y_AXIS)); |
222 |
addVisibleDataComponent(memory, new StorageDataComponent("Memory in use", "packet.memory.free", "packet.memory.total", "Mb", 1024*1024)); |
223 |
addVisibleDataComponent(memory, new StorageDataComponent("Swap in use", "packet.swap.free", "packet.swap.total", "Mb", 1024*1024)); |
224 |
addVisibleDataComponent(memory, new IODataComponent("Pages in/out", "packet.pages.pageins", "packet.pages.pageouts")); |
225 |
// theses next two are DataComponents, but not VisibleDataComponents |
226 |
// this is because they hold the value but do NOT display it |
227 |
// just so we ignore the data, because the StorageDataComponent handles it |
228 |
addDataComponent(new StringDataComponent("packet.pages.pageouts", "packet.pages.pageouts")); |
229 |
addDataComponent(new StringDataComponent("packet.memory.total", "packet.memory.total")); |
230 |
addDataComponent(new StringDataComponent("packet.memory.used", "packet.memory.used")); |
231 |
// maybe this one should be used somewhere? |
232 |
addDataComponent(new StringDataComponent("packet.memory.cache", "packet.memory.cache")); |
233 |
addDataComponent(new StringDataComponent("packet.swap.total", "packet.swap.total")); |
234 |
addDataComponent(new StringDataComponent("packet.swap.used", "packet.swap.used")); |
235 |
c.gridy = 8; |
236 |
gridbag.setConstraints(memory, c); |
237 |
_center.add(memory); |
238 |
|
239 |
label = new javax.swing.JLabel("--- Network ---", JLabel.CENTER); |
240 |
c.gridy = 9; |
241 |
gridbag.setConstraints(label, c); |
242 |
_center.add(label); |
243 |
c.gridy = 10; |
244 |
gridbag.setConstraints(_net, c); |
245 |
_center.add(_net); |
246 |
|
247 |
label = new javax.swing.JLabel("--- Users ---", JLabel.CENTER); |
248 |
c.gridy = 11; |
249 |
gridbag.setConstraints(label, c); |
250 |
_center.add(label); |
251 |
|
252 |
JPanel users = new JPanel(); |
253 |
users.setLayout(new BoxLayout(users, BoxLayout.Y_AXIS)); |
254 |
addVisibleDataComponent(users, new StringDataComponent("Number of users", "packet.users.count")); |
255 |
UsersDataComponent userList = new UsersDataComponent("User List", "packet.users.list"); |
256 |
addVisibleDataComponent(users, userList); |
257 |
c.gridy = 12; |
258 |
gridbag.setConstraints(users, c); |
259 |
_center.add(users); |
260 |
|
261 |
label = new javax.swing.JLabel("--- Disks ---", JLabel.CENTER); |
262 |
c.gridy = 13; |
263 |
gridbag.setConstraints(label, c); |
264 |
_center.add(label); |
265 |
c.gridy = 14; |
266 |
gridbag.setConstraints(_disks, c); |
267 |
_center.add(_disks); |
268 |
c.gridy = 15; |
269 |
gridbag.setConstraints(_diskio, c); |
270 |
_center.add(_diskio); |
271 |
|
272 |
label = new javax.swing.JLabel("--- System Services ---", JLabel.CENTER); |
273 |
c.gridy = 16; |
274 |
gridbag.setConstraints(label, c); |
275 |
_center.add(label); |
276 |
c.gridy = 17; |
277 |
gridbag.setConstraints(_services, c); |
278 |
_center.add(_services); |
279 |
|
280 |
// everything else we get is "extra", but we may still want to display it |
281 |
if (_extraData) { |
282 |
label = new javax.swing.JLabel("--- Extra Data ---", JLabel.CENTER); |
283 |
c.gridy = 18; |
284 |
gridbag.setConstraints(label, c); |
285 |
_center.add(label); |
286 |
c.gridy = 19; |
287 |
gridbag.setConstraints(_extra, c); |
288 |
_center.add(_extra); |
289 |
} |
290 |
} |
291 |
|
292 |
//---PUBLIC METHODS--- |
293 |
|
294 |
/** |
295 |
* This method takes an XMLPacket containing |
296 |
* information about the host this HostDisplayPanel |
297 |
* is currently displaying. It then updates all of the |
298 |
* components with the new values. |
299 |
* |
300 |
* It also adds a standard StringDataComponent, should |
301 |
* an attribute come up that there are no DataComponents |
302 |
* associated with. |
303 |
* |
304 |
* @param packet the XML packet |
305 |
* @return if the update was sucessful |
306 |
*/ |
307 |
public boolean updateHost(XMLPacket packet) { |
308 |
// set that everything is ok so far |
309 |
boolean displaySucessful = true; |
310 |
|
311 |
// must be a normal data packet, update the display |
312 |
if((packet.getParam("packet.attributes.type")).equals("data")) { |
313 |
displaySucessful = processPacket(packet); |
314 |
_dataTimer.reset(); |
315 |
if(_dataTimerThread == null){ |
316 |
_dataTimerThread = new Thread(_dataTimer); |
317 |
_dataTimerThread.start(); |
318 |
} |
319 |
} |
320 |
return displaySucessful; |
321 |
} |
322 |
|
323 |
//---PRIVATE METHODS--- |
324 |
|
325 |
/** |
326 |
* Process an incoming packet, updates the components. |
327 |
* If extra data is configured to be displayed, it will |
328 |
* create a new StringDataComponent to display the data. |
329 |
* |
330 |
* @param packet the packet to process |
331 |
* |
332 |
* @return if the proceesing was successful |
333 |
*/ |
334 |
private boolean processPacket(XMLPacket packet) { |
335 |
// iterate over the packets data |
336 |
boolean displaySucessful = true; |
337 |
Set packetSet = packet.getSet(); |
338 |
Iterator i = packetSet.iterator(); |
339 |
while (i.hasNext()) { |
340 |
String dataKey = (String) i.next(); |
341 |
|
342 |
// if there are no components looking after this data |
343 |
// create a new StringDataComponent for it |
344 |
if(!_components.containsKey(dataKey)) { |
345 |
// check if its a disk drive, if it is then we need to deal with it |
346 |
if(dataKey.startsWith("packet.disk.p")) { |
347 |
createDiskPanel(dataKey, packet); |
348 |
// check for diskio stats |
349 |
} else if(dataKey.startsWith("packet.diskio.p")) { |
350 |
createDiskIOPanel(dataKey, packet); |
351 |
// check for network stats |
352 |
} else if(dataKey.startsWith("packet.net.p")) { |
353 |
createNetworkPanel(dataKey, packet); |
354 |
// !check for services here! to display |
355 |
} else if(dataKey.startsWith("packet.services.")) { |
356 |
createServicesPanel(dataKey); |
357 |
// otherwise we don't know about it... |
358 |
} else if (_extraData) { |
359 |
addVisibleDataComponent(_extra, new StringDataComponent(dataKey, dataKey)); |
360 |
} |
361 |
} |
362 |
|
363 |
// try and update the component, if it doesn't like what it gets |
364 |
// warn the user and set that this was an unsucessful display |
365 |
if(_components.containsKey(dataKey)) { |
366 |
|
367 |
try { |
368 |
((DataComponent) _components.get(dataKey)).setValue(packet); |
369 |
} catch (DataFormatException e) { |
370 |
Conient.addMessage("WARNING{host display}: " + e.getMessage()); |
371 |
displaySucessful = false; |
372 |
} |
373 |
} |
374 |
} |
375 |
return displaySucessful; |
376 |
} |
377 |
|
378 |
/** |
379 |
* Adds a DataComponent to the list of already |
380 |
* known data components. The list is aware of |
381 |
* what packet attributes that a DataComponent |
382 |
* is looking after. |
383 |
* |
384 |
* @param ref the packet attribute that this Component looks after |
385 |
* @param dataComponent the actual DataComponent |
386 |
*/ |
387 |
private void addDataComponent(DataComponent dataComponent) { |
388 |
_components.put(dataComponent.getPacketAttribute(), dataComponent); |
389 |
} |
390 |
|
391 |
/** |
392 |
* Adds a DataComponent to the list of already |
393 |
* known data components. The list is aware of |
394 |
* what packet attributes that a DataComponent |
395 |
* is looking after. |
396 |
* |
397 |
* Used for VISIBLE data components, as they are added to the display. |
398 |
* |
399 |
* @param ref the packet attribute that this Component looks after |
400 |
* @param dataComponent the actual DataComponent |
401 |
*/ |
402 |
public void addVisibleDataComponent(Container holder, VisibleDataComponent dataComponent) { |
403 |
_components.put(((DataComponent) dataComponent).getPacketAttribute(), (DataComponent) dataComponent); |
404 |
SwingSafeAdd task = new SwingSafeAdd(holder, dataComponent); |
405 |
SwingUtilities.invokeLater(task); |
406 |
} |
407 |
|
408 |
/** |
409 |
* Creates the disk components and adds them |
410 |
* do the list of components. It also displays |
411 |
* any relavant component. |
412 |
* |
413 |
* When a packet attribute is new to the system |
414 |
* and when it starts "packet.disk.p" then this |
415 |
* method is called. Thus it then accounts for |
416 |
* all attributes relating to that new disk. |
417 |
* |
418 |
* @param attribute the name of the attribute first encountered |
419 |
* @param packet the XMLPacket the data is being pulled from |
420 |
*/ |
421 |
private void createDiskPanel(String attribute, XMLPacket packet) { |
422 |
String diskNumber = ""; |
423 |
|
424 |
// pos is after "packet.disk.p" |
425 |
int pos = 13; |
426 |
while (attribute.charAt(pos) != '.') { |
427 |
diskNumber = diskNumber + attribute.charAt(pos); |
428 |
pos++; |
429 |
} |
430 |
String devAttribute = "packet.disk.p" + diskNumber + ".attributes.name"; |
431 |
String mountAttribute = "packet.disk.p" + diskNumber + ".attributes.mount"; |
432 |
String totalAttribute = "packet.disk.p" + diskNumber + ".attributes.total"; |
433 |
|
434 |
// the only visible component |
435 |
String availAttribute = "packet.disk.p" + diskNumber + ".attributes.avail"; |
436 |
DiskDataComponent disk = new DiskDataComponent("Disk", availAttribute, totalAttribute, mountAttribute, devAttribute , "Mb", 1024*1024); |
437 |
addVisibleDataComponent(_disks, disk); |
438 |
|
439 |
// currently this data isn't useful, so we don't display it |
440 |
// but we add it so that it is forgotten about |
441 |
addDataComponent(new StringDataComponent(devAttribute, devAttribute)); |
442 |
addDataComponent(new StringDataComponent(mountAttribute, mountAttribute)); |
443 |
addDataComponent(new StringDataComponent(totalAttribute, totalAttribute)); |
444 |
|
445 |
// add any further bits of data about this disk so we |
446 |
// don't try and do something with them later |
447 |
// -- this is not that tidy ;) |
448 |
Set packetSet = packet.getSet(); |
449 |
Iterator i = packetSet.iterator(); |
450 |
while (i.hasNext()) { |
451 |
String dataKey = (String) i.next(); |
452 |
if(dataKey.startsWith("packet.disk.p" + diskNumber +".") && !_components.containsKey(dataKey)) { |
453 |
addDataComponent(new StringDataComponent(dataKey, dataKey)); |
454 |
} |
455 |
} |
456 |
} |
457 |
|
458 |
/** |
459 |
* Creates the diskio components and adds them |
460 |
* do the list of components. |
461 |
* |
462 |
* When a packet attribute is new to the system |
463 |
* and when it starts "packet.diskio.p" then this |
464 |
* method is called. Thus it then accounts for |
465 |
* all attributes relating to that new diskio. |
466 |
* |
467 |
* @param attribute the name of the attribute first encountered |
468 |
* @param packet the XMLPacket the data is being pulled from |
469 |
*/ |
470 |
private void createDiskIOPanel(String attribute, XMLPacket packet) { |
471 |
String diskNumber = ""; |
472 |
|
473 |
// pos is after "packet.diskio.p" |
474 |
int pos = 15; |
475 |
while (attribute.charAt(pos) != '.') { |
476 |
diskNumber = diskNumber + attribute.charAt(pos); |
477 |
pos++; |
478 |
} |
479 |
|
480 |
// grab the attributes |
481 |
String nameAttribute = "packet.diskio.p" + diskNumber + ".attributes.name"; |
482 |
String wbytesAttribute = "packet.diskio.p" + diskNumber + ".attributes.wbytes"; |
483 |
String rbytesAttribute = "packet.diskio.p" + diskNumber + ".attributes.rbytes"; |
484 |
|
485 |
// use an IODataComponent to display the diskio |
486 |
IODataComponent diskio = new IODataComponent(packet.getParam(nameAttribute), rbytesAttribute, wbytesAttribute); |
487 |
addVisibleDataComponent(_diskio, diskio); |
488 |
|
489 |
// these attributes are also used, so we hold on to them |
490 |
// (as a side note, this way of "holding on" to attributes sucks ;) |
491 |
addDataComponent(new StringDataComponent(nameAttribute, nameAttribute)); |
492 |
addDataComponent(new StringDataComponent(wbytesAttribute, wbytesAttribute)); |
493 |
} |
494 |
|
495 |
/** |
496 |
* Creates the netwrok components and adds them |
497 |
* do the list of components. |
498 |
* |
499 |
* When a packet attribute is new to the system |
500 |
* and when it starts "packet.net.p" then this |
501 |
* method is called. Thus it then accounts for |
502 |
* all attributes relating to that network device. |
503 |
* |
504 |
* @param attribute the name of the attribute first encountered |
505 |
* @param packet the XMLPacket the data is being pulled from |
506 |
*/ |
507 |
private void createNetworkPanel(String attribute, XMLPacket packet) { |
508 |
String netNumber = ""; |
509 |
|
510 |
// pos is after "packet.net.p" |
511 |
int pos = 12; |
512 |
while (attribute.charAt(pos) != '.') { |
513 |
netNumber = netNumber + attribute.charAt(pos); |
514 |
pos++; |
515 |
} |
516 |
|
517 |
// grab the attributes |
518 |
String nameAttribute = "packet.net.p" + netNumber + ".attributes.name"; |
519 |
String txAttribute = "packet.net.p" + netNumber + ".attributes.tx"; |
520 |
String rxAttribute = "packet.net.p" + netNumber + ".attributes.rx"; |
521 |
|
522 |
// use an IODataComponent to display the diskio |
523 |
IODataComponent net = new IODataComponent(packet.getParam(nameAttribute), rxAttribute, txAttribute); |
524 |
addVisibleDataComponent(_net, net); |
525 |
|
526 |
// these attributes are also used, so we hold on to them |
527 |
addDataComponent(new StringDataComponent(nameAttribute, nameAttribute)); |
528 |
addDataComponent(new StringDataComponent(txAttribute, txAttribute)); |
529 |
} |
530 |
|
531 |
/** |
532 |
* Creates the servicecheck components and adds them |
533 |
* do the list of components. It also displays |
534 |
* any relavant component. |
535 |
* |
536 |
* When a packet attribute is new to the system |
537 |
* and when it starts "packet.services." then this |
538 |
* method is called. Thus it then accounts for |
539 |
* all attributes relating to that service. |
540 |
* |
541 |
* @param attribute the name of the attribute first encountered |
542 |
*/ |
543 |
private void createServicesPanel(String attribute) { |
544 |
String serviceType = ""; |
545 |
|
546 |
// pos is after "packet.services." |
547 |
int pos = 16; |
548 |
while (attribute.charAt(pos) != '.') { |
549 |
serviceType = serviceType + attribute.charAt(pos); |
550 |
pos++; |
551 |
} |
552 |
|
553 |
String statusAttribute = "packet.services." + serviceType + ".attributes.status"; |
554 |
// we hide this as the service data component uses this attribute |
555 |
addDataComponent(new StringDataComponent(serviceType + " service status", statusAttribute)); |
556 |
|
557 |
ServiceDataComponent service = new ServiceDataComponent(serviceType, "packet.services." + serviceType + ".attributes.message", statusAttribute); |
558 |
addVisibleDataComponent(_services, service); |
559 |
} |
560 |
|
561 |
//---ACCESSOR/MUTATOR METHODS--- |
562 |
|
563 |
//---ATTRIBUTES--- |
564 |
|
565 |
/** |
566 |
* The components that we already know about |
567 |
* connected with the attributes they care about |
568 |
* are stored here. |
569 |
*/ |
570 |
private HashMap _components = new HashMap(); |
571 |
|
572 |
/** |
573 |
* The north panel, currently used for the platform info button. |
574 |
*/ |
575 |
private final JPanel _north = new JPanel(); |
576 |
|
577 |
/** |
578 |
* The centre panel, where all the data is displayed. |
579 |
*/ |
580 |
private final JPanel _center = new JPanel(); |
581 |
|
582 |
/** |
583 |
* The countdown timer for normal data packets |
584 |
*/ |
585 |
private final PacketTimer _dataTimer; |
586 |
|
587 |
/** |
588 |
* A place for the data timer thread |
589 |
*/ |
590 |
private Thread _dataTimerThread = null; |
591 |
|
592 |
/** |
593 |
* The hostname this instance is keeping data for |
594 |
*/ |
595 |
private final String _hostName; |
596 |
|
597 |
/** |
598 |
* The disks panel |
599 |
*/ |
600 |
private final JPanel _disks = new JPanel(); |
601 |
{ |
602 |
_disks.setLayout(new BoxLayout(_disks, BoxLayout.Y_AXIS)); |
603 |
} |
604 |
|
605 |
/** |
606 |
* The diskio panel |
607 |
*/ |
608 |
private final JPanel _diskio = new JPanel(); |
609 |
{ |
610 |
_diskio.setLayout(new BoxLayout(_diskio, BoxLayout.Y_AXIS)); |
611 |
} |
612 |
|
613 |
/** |
614 |
* The network panel |
615 |
*/ |
616 |
private final JPanel _net = new JPanel(); |
617 |
{ |
618 |
_net.setLayout(new BoxLayout(_net, BoxLayout.Y_AXIS)); |
619 |
} |
620 |
|
621 |
/** |
622 |
* The extra panel, used to display unknown data in the packet |
623 |
*/ |
624 |
private final JPanel _extra = new JPanel(); |
625 |
{ |
626 |
_extra.setLayout(new BoxLayout(_extra, BoxLayout.Y_AXIS)); |
627 |
} |
628 |
|
629 |
/** |
630 |
* The services panel, currently used to display host service information |
631 |
* from heartbeat packets. |
632 |
*/ |
633 |
private final JPanel _services = new JPanel(); |
634 |
{ |
635 |
_services.setLayout(new BoxLayout(_services, BoxLayout.Y_AXIS)); |
636 |
} |
637 |
|
638 |
/** |
639 |
* Whether we a worrying about "extra" data |
640 |
* by default we don't, but we look in the configuration |
641 |
* in the constructor. |
642 |
*/ |
643 |
private boolean _extraData = false; |
644 |
|
645 |
//---STATIC ATTRIBUTES--- |
646 |
|
647 |
} |