12 |
|
import java.util.Date; |
13 |
|
import java.text.DateFormat; |
14 |
|
import java.util.Locale; |
15 |
+ |
import java.util.HashMap; |
16 |
|
|
17 |
|
/** |
18 |
|
* NASTY AND BASIC, PLEASE DON'T COMPLAIN |
29 |
|
*/ |
30 |
|
public final String REVISION = "$Revision$"; |
31 |
|
|
32 |
< |
private final int width = 300; |
32 |
> |
private final int width = 400; |
33 |
|
private final int height = 700; |
34 |
|
|
35 |
|
//---STATIC METHODS--- |
36 |
|
|
37 |
|
public static void main(String[] args) { |
38 |
|
try { |
39 |
< |
String host = args[0]; |
39 |
> |
String host = null; |
40 |
> |
if (args.length != 1) { |
41 |
> |
Object response = null; |
42 |
> |
while(!(response instanceof String)) { |
43 |
> |
response = JOptionPane.showInputDialog(null, "Please enter the name of a server running the I-Scream client interface:", "I-Scream Server", JOptionPane.INFORMATION_MESSAGE); |
44 |
> |
} |
45 |
> |
host = (String) response; |
46 |
> |
} else { |
47 |
> |
host = args[0]; |
48 |
> |
} |
49 |
> |
|
50 |
|
int port = 4510; |
51 |
|
Socket socket = new Socket(host, port); |
52 |
|
BufferedReader inBound = new BufferedReader(new InputStreamReader(socket.getInputStream())); |
53 |
|
PrintWriter outBound = new PrintWriter(socket.getOutputStream()); |
54 |
|
DataReader data = new DataReader(inBound); |
55 |
|
|
56 |
< |
SwingClient cli = new SwingClient(data); |
57 |
< |
Thread cliThread = new Thread(cli); |
58 |
< |
cliThread.start(); |
56 |
> |
SwingClient client = new SwingClient(data); |
57 |
> |
Thread clientThread = new Thread(client); |
58 |
> |
clientThread.start(); |
59 |
|
} catch (Exception e) { |
60 |
< |
System.err.println("ERROR: " + e); |
60 |
> |
System.err.println("ERROR START: " + e); |
61 |
> |
System.exit(1); |
62 |
|
} |
63 |
|
} |
64 |
|
|
84 |
|
header.add(Box.createHorizontalGlue()); |
85 |
|
header.add(iscream); |
86 |
|
|
87 |
< |
ImageIcon icon = new ImageIcon("server.gif"); |
76 |
< |
JTabbedPane tabbedPane = new JTabbedPane(); |
77 |
< |
JPanel mainPanel = new JPanel(); |
78 |
< |
mainPanel.setLayout(new GridLayout(21, 1)); |
79 |
< |
|
80 |
< |
JPanel panel1 = makeTextPanel("Machine Name : ", _machine_name); |
81 |
< |
JPanel panel2 = makeTextPanel("IP : ", _ip); |
82 |
< |
JPanel panel3 = makeTextPanel("Date : ", _date); |
83 |
< |
JPanel panel4 = makeTextPanel("Sequence Number : ", _seq_no); |
84 |
< |
JPanel panel5 = makeTextPanel("Host Time : ", _sTime); |
85 |
< |
JPanel panel6 = makeTextPanel("Load Average (1 min) : ", _load_load1); |
86 |
< |
JPanel panel7 = makeTextPanel("Load Average (5 min) : ", _load_load5); |
87 |
< |
JPanel panel8 = makeTextPanel("Load Average (15 min) : ", _load_load15); |
88 |
< |
JPanel panel9 = makeTextPanel("Processes Total : ", _processes_total); |
89 |
< |
JPanel panel10 = makeTextPanel("Processes Sleeping : ", _processes_sleeping); |
90 |
< |
JPanel panel11 = makeTextPanel("Processes Zombie : ", _processes_zombie); |
91 |
< |
JPanel panel12 = makeTextPanel("Processes Stopped : ", _processes_stopped); |
92 |
< |
JPanel panel13 = makeTextPanel("CPU % idle : ", _cpu_idle); |
93 |
< |
JPanel panel14 = makeTextPanel("CPU % user : ", _cpu_user); |
94 |
< |
JPanel panel15 = makeTextPanel("CPU % kernel : ", _cpu_kernel); |
95 |
< |
JPanel panel16 = makeTextPanel("CPU % i/o wait : ", _cpu_iowait); |
96 |
< |
JPanel panel17 = makeTextPanel("CPU % swapping : ", _cpu_swap); |
97 |
< |
JPanel panel18 = makeTextPanel("Real Memory : ", _memory_real); |
98 |
< |
JPanel panel19 = makeTextPanel("Real Free : ", _memory_free); |
99 |
< |
JPanel panel20 = makeTextPanel("Swap in use : ", _memory_swapinuse); |
100 |
< |
JPanel panel21 = makeTextPanel("Swap free : ", _memory_swapfree); |
101 |
< |
mainPanel.add(panel1); |
102 |
< |
mainPanel.add(panel2); |
103 |
< |
mainPanel.add(panel3); |
104 |
< |
mainPanel.add(panel4); |
105 |
< |
mainPanel.add(panel5); |
106 |
< |
mainPanel.add(panel6); |
107 |
< |
mainPanel.add(panel7); |
108 |
< |
mainPanel.add(panel8); |
109 |
< |
mainPanel.add(panel9); |
110 |
< |
mainPanel.add(panel10); |
111 |
< |
mainPanel.add(panel11); |
112 |
< |
mainPanel.add(panel12); |
113 |
< |
mainPanel.add(panel13); |
114 |
< |
mainPanel.add(panel14); |
115 |
< |
mainPanel.add(panel15); |
116 |
< |
mainPanel.add(panel16); |
117 |
< |
mainPanel.add(panel17); |
118 |
< |
mainPanel.add(panel18); |
119 |
< |
mainPanel.add(panel19); |
120 |
< |
mainPanel.add(panel20); |
121 |
< |
mainPanel.add(panel21); |
87 |
> |
//_tabbedPane.setSelectedIndex(0); |
88 |
|
|
123 |
– |
tabbedPane.addTab("Raptor", icon, mainPanel, "Monitor raptor.ukc.ac.uk"); |
124 |
– |
|
125 |
– |
tabbedPane.setSelectedIndex(0); |
126 |
– |
|
89 |
|
// build the frame |
90 |
|
box.add(header); |
91 |
< |
box.add(tabbedPane); |
91 |
> |
box.add(_tabbedPane); |
92 |
> |
box.add(_status); |
93 |
|
getContentPane().add(box); |
94 |
|
|
95 |
|
// show the window |
96 |
|
show(); |
97 |
+ |
_status.setText("Running..."); |
98 |
|
} |
99 |
|
|
100 |
|
//---PUBLIC METHODS--- |
101 |
|
|
102 |
|
public void run() { |
103 |
+ |
HashMap hostList = new HashMap(); |
104 |
|
try { |
105 |
|
_data.start(); |
106 |
|
while(true) { |
109 |
|
} |
110 |
|
String xml = _data.getXML(); |
111 |
|
if (xml == null) { |
112 |
< |
// nothing |
112 |
> |
_status.setText("No XML to update..."); |
113 |
|
} else { |
114 |
|
|
115 |
|
// Get a string without any null characters in it. |
124 |
|
// Use XMLPacketMaker to make an XMLPacket object. |
125 |
|
XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml); |
126 |
|
XMLPacket packet = xmlPacketMaker.createXMLPacket(); |
127 |
< |
|
128 |
< |
_machine_name.setText(packet.getParam("packet.attributes.machine_name")); |
129 |
< |
_ip.setText(packet.getParam("packet.attributes.ip")); |
130 |
< |
_date.setText(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date(Long.parseLong(packet.getParam("packet.attributes.date"))))); |
131 |
< |
_seq_no.setText(packet.getParam("packet.attributes.seq_no")); |
132 |
< |
|
133 |
< |
_sTime.setText(packet.getParam("packet.sTime")); |
134 |
< |
|
170 |
< |
_load_load1.setText(packet.getParam("packet.load.load1")); |
171 |
< |
_load_load5.setText(packet.getParam("packet.load.load5")); |
172 |
< |
_load_load15.setText(packet.getParam("packet.load.load15")); |
173 |
< |
|
174 |
< |
_processes_total.setText(packet.getParam("packet.processes.total")); |
175 |
< |
_processes_sleeping.setText(packet.getParam("packet.processes.sleeping")); |
176 |
< |
_processes_zombie.setText(packet.getParam("packet.processes.zombie")); |
177 |
< |
_processes_stopped.setText(packet.getParam("packet.processes.stopped")); |
178 |
< |
|
179 |
< |
_cpu_idle.setString(packet.getParam("packet.cpu.idle") + "%"); |
180 |
< |
_cpu_idle.setValue(new Double(packet.getParam("packet.cpu.idle")).intValue()); |
181 |
< |
_cpu_user.setString(packet.getParam("packet.cpu.user") + "%"); |
182 |
< |
_cpu_user.setValue(new Double(packet.getParam("packet.cpu.user")).intValue()); |
183 |
< |
_cpu_kernel.setString(packet.getParam("packet.cpu.kernel") + "%"); |
184 |
< |
_cpu_kernel.setValue(new Double(packet.getParam("packet.cpu.kernel")).intValue()); |
185 |
< |
_cpu_iowait.setString(packet.getParam("packet.cpu.iowait") + "%"); |
186 |
< |
_cpu_iowait.setValue(new Double(packet.getParam("packet.cpu.iowait")).intValue()); |
187 |
< |
_cpu_swap.setString(packet.getParam("packet.cpu.swap") + "%"); |
188 |
< |
_cpu_swap.setValue(new Double(packet.getParam("packet.cpu.swap")).intValue()); |
189 |
< |
|
190 |
< |
_memory_real.setText(packet.getParam("packet.memory.real")); |
191 |
< |
_memory_free.setText(packet.getParam("packet.memory.free")); |
192 |
< |
_memory_swapinuse.setText(packet.getParam("packet.memory.swapinuse")); |
193 |
< |
_memory_swapfree.setText(packet.getParam("packet.memory.swapfree")); |
127 |
> |
String hostName = packet.getParam("packet.attributes.machine_name"); |
128 |
> |
if(!hostList.containsKey(hostName)) { |
129 |
> |
host = new HostDisplayPanel(); |
130 |
> |
_tabbedPane.addTab(hostName, _serverIcon, host, "Monitor " + hostName); |
131 |
> |
hostList.put(hostName, host); |
132 |
> |
_status.setText("New Host added: " + hostName); |
133 |
> |
} |
134 |
> |
((HostDisplayPanel) hostList.get(hostName)).updateHost(packet); |
135 |
|
} |
136 |
|
} |
137 |
|
} catch (Exception e) { |
138 |
< |
System.err.println("ERROR: " + e); |
138 |
> |
System.err.println("ERROR RUN: " + e); |
139 |
|
} |
140 |
|
} |
141 |
|
|
157 |
|
|
158 |
|
//---ATTRIBUTES--- |
159 |
|
|
160 |
< |
JLabel _machine_name = new JLabel(); |
161 |
< |
JLabel _ip = new JLabel(); |
221 |
< |
JLabel _date = new JLabel(); |
222 |
< |
JLabel _seq_no = new JLabel(); |
223 |
< |
|
224 |
< |
JLabel _sTime = new JLabel(); |
225 |
< |
|
226 |
< |
JLabel _load_load1 = new JLabel(); |
227 |
< |
JLabel _load_load5 = new JLabel(); |
228 |
< |
JLabel _load_load15 = new JLabel(); |
229 |
< |
|
230 |
< |
JLabel _processes_total = new JLabel(); |
231 |
< |
JLabel _processes_sleeping = new JLabel(); |
232 |
< |
JLabel _processes_zombie = new JLabel(); |
233 |
< |
JLabel _processes_stopped = new JLabel(); |
234 |
< |
|
235 |
< |
int min = 0; |
236 |
< |
int max = 100; |
237 |
< |
JProgressBar _cpu_idle = new JProgressBar(JProgressBar.HORIZONTAL, min, max); |
238 |
< |
{ |
239 |
< |
_cpu_idle.setStringPainted(true); |
240 |
< |
} |
241 |
< |
JProgressBar _cpu_user = new JProgressBar(JProgressBar.HORIZONTAL, min, max); |
242 |
< |
{ |
243 |
< |
_cpu_user.setStringPainted(true); |
244 |
< |
} |
245 |
< |
JProgressBar _cpu_kernel = new JProgressBar(JProgressBar.HORIZONTAL, min, max); |
246 |
< |
{ |
247 |
< |
_cpu_kernel.setStringPainted(true); |
248 |
< |
} |
249 |
< |
JProgressBar _cpu_iowait = new JProgressBar(JProgressBar.HORIZONTAL, min, max); |
250 |
< |
{ |
251 |
< |
_cpu_iowait.setStringPainted(true); |
252 |
< |
} |
253 |
< |
JProgressBar _cpu_swap = new JProgressBar(JProgressBar.HORIZONTAL, min, max); |
254 |
< |
{ |
255 |
< |
_cpu_swap.setStringPainted(true); |
256 |
< |
} |
257 |
< |
|
258 |
< |
JLabel _memory_real = new JLabel(); |
259 |
< |
JLabel _memory_free = new JLabel(); |
260 |
< |
JLabel _memory_swapinuse = new JLabel(); |
261 |
< |
JLabel _memory_swapfree = new JLabel(); |
160 |
> |
HostDisplayPanel host; |
161 |
> |
JTabbedPane _tabbedPane = new JTabbedPane(); |
162 |
|
DataReader _data; |
163 |
+ |
JLabel _status = new JLabel(); |
164 |
+ |
ImageIcon _serverIcon = new ImageIcon("server.gif"); |
165 |
|
|
166 |
|
//---STATIC ATTRIBUTES--- |
167 |
|
|