1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* Copyright (C) 2000-2002 i-scream |
4 |
+ |
* |
5 |
+ |
* This program is free software; you can redistribute it and/or |
6 |
+ |
* modify it under the terms of the GNU General Public License |
7 |
+ |
* as published by the Free Software Foundation; either version 2 |
8 |
+ |
* of the License, or (at your option) any later version. |
9 |
+ |
* |
10 |
+ |
* This program is distributed in the hope that it will be useful, |
11 |
+ |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
+ |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
+ |
* GNU General Public License for more details. |
14 |
+ |
* |
15 |
+ |
* You should have received a copy of the GNU General Public License |
16 |
+ |
* along with this program; if not, write to the Free Software |
17 |
+ |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
+ |
*/ |
19 |
+ |
|
20 |
|
//---PACKAGE DECLARATION--- |
21 |
+ |
package uk.org.iscream.cms.conient; |
22 |
|
|
23 |
|
//---IMPORTS--- |
24 |
|
import javax.swing.*; |
25 |
|
import javax.swing.border.*; |
6 |
– |
import java.awt.Color; |
7 |
– |
|
26 |
|
import java.awt.*; |
27 |
|
import java.awt.event.*; |
10 |
– |
import java.net.*; |
11 |
– |
import java.io.*; |
28 |
|
|
29 |
|
/** |
30 |
< |
* NASTY AND BASIC, PLEASE DON'T COMPLAIN |
30 |
> |
* This is the main class of the Conient client. |
31 |
|
* |
32 |
+ |
* This sets up the control panel, the data panel |
33 |
+ |
* and its own display. |
34 |
+ |
* |
35 |
|
* @author $Author$ |
36 |
|
* @version $Id$ |
37 |
|
*/ |
38 |
< |
public class SwingClient extends JFrame implements Runnable { |
38 |
> |
public class Conient extends JFrame { |
39 |
|
|
40 |
|
//---FINAL ATTRIBUTES--- |
41 |
|
|
43 |
|
* The current CVS revision of this class |
44 |
|
*/ |
45 |
|
public final String REVISION = "$Revision$"; |
46 |
+ |
|
47 |
+ |
/** |
48 |
+ |
* The initial width of the window |
49 |
+ |
*/ |
50 |
+ |
private final int DEFAULT_WIDTH = 700; |
51 |
|
|
52 |
< |
private final int width = 300; |
53 |
< |
private final int height = 700; |
52 |
> |
/** |
53 |
> |
* The initial height of the window |
54 |
> |
*/ |
55 |
> |
private final int DEFAULT_HEIGHT = 600; |
56 |
|
|
57 |
+ |
/** |
58 |
+ |
* The default configuration fle |
59 |
+ |
* This can be specified on the command line |
60 |
+ |
*/ |
61 |
+ |
public static final String DEFAULT_CONFIG_FILE = "./etc/default.conf"; |
62 |
+ |
|
63 |
+ |
/** |
64 |
+ |
* The time in seconds to display the splash |
65 |
+ |
* screen for |
66 |
+ |
*/ |
67 |
+ |
public static final int DISPLAY_SPLASH_TIME_SECONDS = 3; |
68 |
+ |
|
69 |
|
//---STATIC METHODS--- |
70 |
|
|
71 |
+ |
/** |
72 |
+ |
* The first method that is called. |
73 |
+ |
* Sets up the various panels |
74 |
+ |
* |
75 |
+ |
* @param args the command line arguments |
76 |
+ |
*/ |
77 |
|
public static void main(String[] args) { |
78 |
< |
try { |
79 |
< |
String host = args[0]; |
80 |
< |
int port = 4510; |
81 |
< |
Socket socket = new Socket(host, port); |
82 |
< |
BufferedReader inBound = new BufferedReader(new InputStreamReader(socket.getInputStream())); |
83 |
< |
PrintWriter outBound = new PrintWriter(socket.getOutputStream()); |
84 |
< |
DataReader data = new DataReader(inBound); |
78 |
> |
// get the host from the command line if they gave it |
79 |
> |
String host = null; |
80 |
> |
String configFile = DEFAULT_CONFIG_FILE; |
81 |
> |
if (args.length == 1) { |
82 |
> |
configFile = args[0]; |
83 |
> |
} |
84 |
> |
|
85 |
> |
// start the configuration system |
86 |
> |
Configuration.initialise(configFile); |
87 |
> |
|
88 |
> |
// the data display panel |
89 |
> |
DataPanel data = new DataPanel(); |
90 |
|
|
91 |
< |
SwingClient cli = new SwingClient(data); |
92 |
< |
Thread cliThread = new Thread(cli); |
93 |
< |
cliThread.start(); |
94 |
< |
} catch (Exception e) { |
95 |
< |
System.err.println("ERROR: " + e); |
96 |
< |
} |
91 |
> |
// the control panel |
92 |
> |
ControlPanel control = new ControlPanel(data); |
93 |
> |
|
94 |
> |
// the main frame (passed the two panels) |
95 |
> |
Conient client = new Conient(data, control); |
96 |
> |
conientFrame = (Frame) client; |
97 |
> |
Conient.addMessage("Conient {an i-scream Client} (c) 2001 The i-scream Project (http://www.i-scream.org.uk)"); |
98 |
> |
|
99 |
> |
Conient.addMessage("Conient ready."); |
100 |
> |
|
101 |
|
} |
102 |
|
|
103 |
+ |
/** |
104 |
+ |
* A static accessor, allowing components of the system |
105 |
+ |
* to get hold of the root frame of the system. |
106 |
+ |
* |
107 |
+ |
* see conientFrame attribute for details. |
108 |
+ |
* |
109 |
+ |
* @return the root Conient frame |
110 |
+ |
*/ |
111 |
+ |
public static Frame getFrame() { |
112 |
+ |
return conientFrame; |
113 |
+ |
} |
114 |
+ |
|
115 |
|
//---CONSTRUCTORS--- |
116 |
|
|
117 |
|
/** |
118 |
< |
* Creates a new Swing Client. |
118 |
> |
* Creates a new Swing Client Frame |
119 |
|
*/ |
120 |
< |
public SwingClient(DataReader data) { |
56 |
< |
_data = data; |
120 |
> |
private Conient(JSplitPane data, ControlPanel control) { |
121 |
|
// set up the Frame |
122 |
< |
setTitle("I-Scream Client"); |
123 |
< |
setSize(width, height); |
124 |
< |
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); |
61 |
< |
Box box = Box.createVerticalBox(); |
62 |
< |
|
63 |
< |
// create the i-scream logo at the top |
64 |
< |
JLabel iscream = new JLabel(new ImageIcon("i-scream.gif")); |
65 |
< |
JLabel comment = new JLabel(" I-Scream Client"); |
66 |
< |
comment.setForeground( new Color(0, 0, 102)); |
67 |
< |
Box header = Box.createHorizontalBox(); |
68 |
< |
header.add(comment); |
69 |
< |
header.add(Box.createHorizontalGlue()); |
70 |
< |
header.add(iscream); |
122 |
> |
super("Conient {an i-scream Client}"); |
123 |
> |
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); |
124 |
> |
setJMenuBar(control.getMenuBar()); |
125 |
|
|
126 |
< |
ImageIcon icon = new ImageIcon("server.gif"); |
127 |
< |
JTabbedPane tabbedPane = new JTabbedPane(); |
128 |
< |
JPanel mainPanel = new JPanel(); |
129 |
< |
mainPanel.setLayout(new GridLayout(21, 1)); |
126 |
> |
// set what happens when the X in the corner is clicked |
127 |
> |
addWindowListener(new WindowAdapter() { |
128 |
> |
public void windowClosing(WindowEvent e) {System.exit(0);} |
129 |
> |
}); |
130 |
|
|
131 |
< |
JPanel panel1 = makeTextPanel("Machine Name : ", _machine_name); |
132 |
< |
JPanel panel2 = makeTextPanel("IP : ", _ip); |
133 |
< |
JPanel panel3 = makeTextPanel("Date : ", _date); |
134 |
< |
JPanel panel4 = makeTextPanel("Sequence Number : ", _seq_no); |
81 |
< |
JPanel panel5 = makeTextPanel("sTime : ", _sTime); |
82 |
< |
JPanel panel6 = makeTextPanel("Load Average (1 min) : ", _load_load1); |
83 |
< |
JPanel panel7 = makeTextPanel("Load Average (5 min) : ", _load_load5); |
84 |
< |
JPanel panel8 = makeTextPanel("Load Average (15 min) : ", _load_load15); |
85 |
< |
JPanel panel9 = makeTextPanel("Processes Total : ", _processes_total); |
86 |
< |
JPanel panel10 = makeTextPanel("Processes Sleeping : ", _processes_sleeping); |
87 |
< |
JPanel panel11 = makeTextPanel("Processes Zombie : ", _processes_zombie); |
88 |
< |
JPanel panel12 = makeTextPanel("Processes Stopped : ", _processes_stopped); |
89 |
< |
JPanel panel13 = makeTextPanel("CPU % idle : ", _cpu_idle); |
90 |
< |
JPanel panel14 = makeTextPanel("CPU % user : ", _cpu_user); |
91 |
< |
JPanel panel15 = makeTextPanel("CPU % kernel : ", _cpu_kernel); |
92 |
< |
JPanel panel16 = makeTextPanel("CPU % i/o wait : ", _cpu_iowait); |
93 |
< |
JPanel panel17 = makeTextPanel("CPU % swapping : ", _cpu_swap); |
94 |
< |
JPanel panel18 = makeTextPanel("Real Memory : ", _memory_real); |
95 |
< |
JPanel panel19 = makeTextPanel("Real Free : ", _memory_free); |
96 |
< |
JPanel panel20 = makeTextPanel("Swap in use : ", _memory_swapinuse); |
97 |
< |
JPanel panel21 = makeTextPanel("Swap free : ", _memory_swapfree); |
98 |
< |
mainPanel.add(panel1); |
99 |
< |
mainPanel.add(panel2); |
100 |
< |
mainPanel.add(panel3); |
101 |
< |
mainPanel.add(panel4); |
102 |
< |
mainPanel.add(panel5); |
103 |
< |
mainPanel.add(panel6); |
104 |
< |
mainPanel.add(panel7); |
105 |
< |
mainPanel.add(panel8); |
106 |
< |
mainPanel.add(panel9); |
107 |
< |
mainPanel.add(panel10); |
108 |
< |
mainPanel.add(panel11); |
109 |
< |
mainPanel.add(panel12); |
110 |
< |
mainPanel.add(panel13); |
111 |
< |
mainPanel.add(panel14); |
112 |
< |
mainPanel.add(panel15); |
113 |
< |
mainPanel.add(panel16); |
114 |
< |
mainPanel.add(panel17); |
115 |
< |
mainPanel.add(panel18); |
116 |
< |
mainPanel.add(panel19); |
117 |
< |
mainPanel.add(panel20); |
118 |
< |
mainPanel.add(panel21); |
119 |
< |
|
120 |
< |
tabbedPane.addTab("Raptor", icon, mainPanel, "Monitor raptor.ukc.ac.uk"); |
121 |
< |
|
122 |
< |
tabbedPane.setSelectedIndex(0); |
131 |
> |
// add the control pane to the top border |
132 |
> |
getContentPane().add(control, "North"); |
133 |
> |
// add the data pane to the centre |
134 |
> |
getContentPane().add(data); |
135 |
|
|
136 |
< |
// build the frame |
137 |
< |
box.add(header); |
138 |
< |
box.add(tabbedPane); |
139 |
< |
getContentPane().add(box); |
136 |
> |
// setup the status panel |
137 |
> |
JPanel bottom = new JPanel(); |
138 |
> |
bottom.setLayout(new BorderLayout()); |
139 |
> |
_messages.setEditable(false); |
140 |
> |
_messages.setRows(3); |
141 |
> |
JScrollPane messagesPane = new JScrollPane(_messages); |
142 |
> |
messagesPane.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Messages ")); |
143 |
> |
bottom.add(messagesPane, "Center"); |
144 |
> |
JPanel statusPanel = new JPanel(); |
145 |
> |
JPanel linkPanel = new JPanel(); |
146 |
> |
linkPanel.setLayout(new GridLayout(1,2)); |
147 |
> |
linkPanel.add(_controlStatus); |
148 |
> |
linkPanel.add(_dataStatus); |
149 |
> |
statusPanel.setLayout(new GridLayout(2,1)); |
150 |
> |
statusPanel.add(linkPanel); |
151 |
> |
statusPanel.add(_queueStatus); |
152 |
> |
bottom.add(statusPanel, "South"); |
153 |
|
|
154 |
< |
// show the window |
154 |
> |
// add the status panel to the bottom border |
155 |
> |
getContentPane().add(bottom, "South"); |
156 |
> |
|
157 |
> |
// a nice icon for the window |
158 |
> |
setIconImage((new ImageIcon("./resources/server.gif")).getImage()); |
159 |
> |
|
160 |
> |
// and just because we can, a silly splash screen |
161 |
> |
// of the dudes that did this funky jibble |
162 |
> |
Splash splash = new Splash(); |
163 |
> |
splash.show(); |
164 |
> |
// wait |
165 |
> |
try { |
166 |
> |
Thread.sleep(DISPLAY_SPLASH_TIME_SECONDS * 1000); |
167 |
> |
} catch (InterruptedException e) { |
168 |
> |
// don't do anything, we don't care |
169 |
> |
} |
170 |
> |
//loose the window |
171 |
> |
splash.dispose(); |
172 |
> |
splash = null; |
173 |
> |
// show the main window |
174 |
|
show(); |
175 |
|
} |
176 |
|
|
177 |
|
//---PUBLIC METHODS--- |
178 |
|
|
135 |
– |
public void run() { |
136 |
– |
_data.start(); |
137 |
– |
while(true) { |
138 |
– |
String xml = _data.getXML(); |
139 |
– |
if (xml == null) { |
140 |
– |
// nothing |
141 |
– |
} else { |
142 |
– |
|
143 |
– |
// Get a string without any null characters in it. |
144 |
– |
// -- maybe String.trim() would be better here ? |
145 |
– |
if (xml.indexOf(0) != -1) { |
146 |
– |
xml = xml.substring(0, xml.indexOf(0)); |
147 |
– |
} |
148 |
– |
else { |
149 |
– |
xml = xml.substring(0, xml.length()); |
150 |
– |
} |
151 |
– |
|
152 |
– |
// Use XMLPacketMaker to make an XMLPacket object. |
153 |
– |
XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml); |
154 |
– |
XMLPacket packet = xmlPacketMaker.createXMLPacket(); |
155 |
– |
|
156 |
– |
_machine_name.setText(packet.getParam("packet.attributes.machine_name")); |
157 |
– |
_ip.setText(packet.getParam("packet.attributes.ip")); |
158 |
– |
_date.setText(packet.getParam("packet.attributes.date")); |
159 |
– |
_seq_no.setText(packet.getParam("packet.attributes.seq_no")); |
160 |
– |
|
161 |
– |
_sTime.setText(packet.getParam("packet.sTime")); |
162 |
– |
|
163 |
– |
_load_load1.setText(packet.getParam("packet.load.load1")); |
164 |
– |
_load_load5.setText(packet.getParam("packet.load.load5")); |
165 |
– |
_load_load15.setText(packet.getParam("packet.load.load15")); |
166 |
– |
|
167 |
– |
_processes_total.setText(packet.getParam("packet.processes.total")); |
168 |
– |
_processes_sleeping.setText(packet.getParam("packet.processes.sleeping")); |
169 |
– |
_processes_zombie.setText(packet.getParam("packet.processes.zombie")); |
170 |
– |
_processes_stopped.setText(packet.getParam("packet.processes.stopped")); |
171 |
– |
|
172 |
– |
_cpu_idle.setText(packet.getParam("packet.cpu.idle")); |
173 |
– |
_cpu_user.setText(packet.getParam("packet.cpu.user")); |
174 |
– |
_cpu_kernel.setText(packet.getParam("packet.cpu.kernel")); |
175 |
– |
_cpu_iowait.setText(packet.getParam("packet.cpu.iowait")); |
176 |
– |
_cpu_swap.setText(packet.getParam("packet.cpu.swap")); |
177 |
– |
|
178 |
– |
_memory_real.setText(packet.getParam("packet.memory.real")); |
179 |
– |
_memory_free.setText(packet.getParam("packet.memory.free")); |
180 |
– |
_memory_swapinuse.setText(packet.getParam("packet.memory.swapinuse")); |
181 |
– |
_memory_swapfree.setText(packet.getParam("packet.memory.swapfree")); |
182 |
– |
} |
183 |
– |
} |
184 |
– |
} |
185 |
– |
|
179 |
|
//---PRIVATE METHODS--- |
180 |
+ |
|
181 |
+ |
//---ACCESSOR/MUTATOR METHODS--- |
182 |
+ |
|
183 |
+ |
/** |
184 |
+ |
* Sets the control link status. |
185 |
+ |
* |
186 |
+ |
* @param status the message |
187 |
+ |
*/ |
188 |
+ |
public static void setControlStatus(String status) { |
189 |
+ |
_controlStatus.setText("Control Link: " + status); |
190 |
+ |
_controlStatus.repaint(); |
191 |
+ |
} |
192 |
|
|
193 |
< |
protected JPanel makeTextPanel(String text, JLabel item) { |
194 |
< |
JPanel panel = new JPanel(false); |
195 |
< |
JLabel label = new JLabel(text); |
196 |
< |
label.setHorizontalAlignment(JLabel.RIGHT); |
197 |
< |
item.setHorizontalAlignment(JLabel.LEFT); |
198 |
< |
panel.setLayout(new GridLayout(1, 2)); |
199 |
< |
panel.add(label); |
200 |
< |
panel.add(item); |
196 |
< |
return panel; |
193 |
> |
/** |
194 |
> |
* Sets the data link status. |
195 |
> |
* |
196 |
> |
* @param status the message |
197 |
> |
*/ |
198 |
> |
public static void setDataStatus(String status) { |
199 |
> |
_dataStatus.setText("Data Link: " + status); |
200 |
> |
_dataStatus.repaint(); |
201 |
|
} |
202 |
|
|
203 |
+ |
/** |
204 |
+ |
* Updates the queue status. |
205 |
+ |
* |
206 |
+ |
* @param currentQueue |
207 |
+ |
* @param numElements |
208 |
+ |
*/ |
209 |
+ |
public static void setQueueStatus(int currentQueue, int numElements) { |
210 |
+ |
_queueStatus.setText("Data Queue : " + currentQueue + " Packets Recieved : " + numElements); |
211 |
+ |
_queueStatus.repaint(); |
212 |
+ |
} |
213 |
|
|
214 |
< |
//---ACCESSOR/MUTATOR METHODS--- |
214 |
> |
/** |
215 |
> |
* Adds a system message to the messages list |
216 |
> |
* |
217 |
> |
* @param message the new message |
218 |
> |
*/ |
219 |
> |
public static void addMessage(String message) { |
220 |
> |
_messages.insert(message + "\n", 0); |
221 |
> |
} |
222 |
|
|
223 |
|
//---ATTRIBUTES--- |
203 |
– |
|
204 |
– |
JLabel _machine_name = new JLabel(); |
205 |
– |
JLabel _ip = new JLabel(); |
206 |
– |
JLabel _date = new JLabel(); |
207 |
– |
JLabel _seq_no = new JLabel(); |
224 |
|
|
225 |
< |
JLabel _sTime = new JLabel(); |
225 |
> |
//---STATIC ATTRIBUTES--- |
226 |
|
|
227 |
< |
JLabel _load_load1 = new JLabel(); |
228 |
< |
JLabel _load_load5 = new JLabel(); |
229 |
< |
JLabel _load_load15 = new JLabel(); |
227 |
> |
/** |
228 |
> |
* Displays information about the data link |
229 |
> |
*/ |
230 |
> |
static JLabel _controlStatus = new JLabel("Control Link: Disconnected", JLabel.LEFT); |
231 |
> |
{ |
232 |
> |
_controlStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED)); |
233 |
> |
} |
234 |
|
|
235 |
< |
JLabel _processes_total = new JLabel(); |
236 |
< |
JLabel _processes_sleeping = new JLabel(); |
237 |
< |
JLabel _processes_zombie = new JLabel(); |
238 |
< |
JLabel _processes_stopped = new JLabel(); |
235 |
> |
/** |
236 |
> |
* Displays information about the data link |
237 |
> |
*/ |
238 |
> |
static JLabel _dataStatus = new JLabel("Data Link: Disconnected", JLabel.LEFT); |
239 |
> |
{ |
240 |
> |
_dataStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED)); |
241 |
> |
} |
242 |
|
|
243 |
< |
JLabel _cpu_idle = new JLabel(); |
244 |
< |
JLabel _cpu_user = new JLabel(); |
245 |
< |
JLabel _cpu_kernel = new JLabel(); |
246 |
< |
JLabel _cpu_iowait = new JLabel(); |
247 |
< |
JLabel _cpu_swap = new JLabel(); |
243 |
> |
/** |
244 |
> |
* Displays information about the inbound data queue. |
245 |
> |
*/ |
246 |
> |
static JLabel _queueStatus = new JLabel(" ", JLabel.LEFT); |
247 |
> |
{ |
248 |
> |
_queueStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED)); |
249 |
> |
} |
250 |
|
|
251 |
< |
JLabel _memory_real = new JLabel(); |
252 |
< |
JLabel _memory_free = new JLabel(); |
253 |
< |
JLabel _memory_swapinuse = new JLabel(); |
254 |
< |
JLabel _memory_swapfree = new JLabel(); |
255 |
< |
DataReader _data; |
251 |
> |
/** |
252 |
> |
* The place where system messages are written. |
253 |
> |
*/ |
254 |
> |
static JTextArea _messages = new JTextArea(); |
255 |
> |
{ |
256 |
> |
_messages.setLineWrap(true); |
257 |
> |
} |
258 |
|
|
259 |
< |
//---STATIC ATTRIBUTES--- |
259 |
> |
/** |
260 |
> |
* Holds a reference to the root frame for Conient |
261 |
> |
* This is only used by dialogs (specifically the configurationn |
262 |
> |
* dialog) so that it can be modal, please use the accessor. |
263 |
> |
*/ |
264 |
> |
private static Frame conientFrame; |
265 |
|
|
266 |
< |
} |
266 |
> |
//---INNER CLASSES---- |
267 |
> |
|
268 |
> |
/** |
269 |
> |
* An inner class to display a splash screen |
270 |
> |
*/ |
271 |
> |
private class Splash extends JWindow { |
272 |
> |
|
273 |
> |
/** |
274 |
> |
* Constructs a new splash screen |
275 |
> |
*/ |
276 |
> |
public Splash() { |
277 |
> |
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); |
278 |
> |
JPanel splash = new JPanel(); |
279 |
> |
splash.setBackground(Color.black); |
280 |
> |
JLabel image = new JLabel((new ImageIcon("./resources/i-scream-splash.gif"))); |
281 |
> |
splash.add(image); |
282 |
> |
setContentPane(splash); |
283 |
> |
Dimension screen = getToolkit().getScreenSize(); |
284 |
> |
pack(); |
285 |
> |
setLocation((screen.width - getSize().width) / 2, |
286 |
> |
(screen.height - getSize().height) / 2); |
287 |
> |
|
288 |
> |
|
289 |
> |
} |
290 |
> |
} |
291 |
> |
} |