| 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 |
|
|
| 77 |
|
|
| 78 |
|
// create the i-scream logo at the top |
| 79 |
|
JLabel iscream = new JLabel(new ImageIcon("i-scream.gif")); |
| 80 |
< |
JLabel comment = new JLabel(" I-Scream Client"); |
| 81 |
< |
comment.setForeground( new Color(0, 0, 102)); |
| 80 |
> |
_serverCountLabel = new JLabel(" Monitoring 0 hosts..."); |
| 81 |
> |
_serverCountLabel.setForeground( new Color(0, 0, 102)); |
| 82 |
|
Box header = Box.createHorizontalBox(); |
| 83 |
< |
header.add(comment); |
| 83 |
> |
header.add(_serverCountLabel); |
| 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) { |
| 107 |
< |
synchronized (_data) { |
| 108 |
< |
_data.wait(); |
| 105 |
> |
_data.start(); |
| 106 |
> |
while(true) { |
| 107 |
> |
synchronized (_data) { |
| 108 |
> |
_data.wait(); |
| 109 |
> |
} |
| 110 |
> |
String xml = _data.getXML(); |
| 111 |
> |
if (xml == null) { |
| 112 |
> |
// shouldn't really happen...but not sure |
| 113 |
> |
_status.setText("No XML to update..."); |
| 114 |
> |
} else { |
| 115 |
> |
_status.setText("Got inbound data...handling"); |
| 116 |
> |
// Get a string without any null characters in it. |
| 117 |
> |
// -- maybe String.trim() would be better ? |
| 118 |
> |
if (xml.indexOf(0) != -1) { |
| 119 |
> |
xml = xml.substring(0, xml.indexOf(0)); |
| 120 |
> |
} |
| 121 |
> |
else { |
| 122 |
> |
xml = xml.substring(0, xml.length()); |
| 123 |
> |
} |
| 124 |
> |
|
| 125 |
> |
// Use XMLPacketMaker to make an XMLPacket object. |
| 126 |
> |
XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml); |
| 127 |
> |
XMLPacket packet = xmlPacketMaker.createXMLPacket(); |
| 128 |
> |
String hostName = packet.getParam("packet.attributes.machine_name"); |
| 129 |
> |
if(!hostList.containsKey(hostName)) { |
| 130 |
> |
_serverCount++; |
| 131 |
> |
_serverCountLabel.setText(" Monitoring " + _serverCount + " hosts..."); |
| 132 |
> |
host = new HostDisplayPanel(); |
| 133 |
> |
_tabbedPane.addTab(hostName, _serverIcon, host, "Monitor " + hostName); |
| 134 |
> |
hostList.put(hostName, host); |
| 135 |
> |
_status.setText("New Host added: " + hostName); |
| 136 |
> |
} |
| 137 |
> |
((HostDisplayPanel) hostList.get(hostName)).updateHost(packet); |
| 138 |
> |
} |
| 139 |
|
} |
| 145 |
– |
String xml = _data.getXML(); |
| 146 |
– |
if (xml == null) { |
| 147 |
– |
// nothing |
| 148 |
– |
} else { |
| 149 |
– |
|
| 150 |
– |
// Get a string without any null characters in it. |
| 151 |
– |
// -- maybe String.trim() would be better here ? |
| 152 |
– |
if (xml.indexOf(0) != -1) { |
| 153 |
– |
xml = xml.substring(0, xml.indexOf(0)); |
| 154 |
– |
} |
| 155 |
– |
else { |
| 156 |
– |
xml = xml.substring(0, xml.length()); |
| 157 |
– |
} |
| 158 |
– |
|
| 159 |
– |
// Use XMLPacketMaker to make an XMLPacket object. |
| 160 |
– |
XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml); |
| 161 |
– |
XMLPacket packet = xmlPacketMaker.createXMLPacket(); |
| 162 |
– |
|
| 163 |
– |
_machine_name.setText(packet.getParam("packet.attributes.machine_name")); |
| 164 |
– |
_ip.setText(packet.getParam("packet.attributes.ip")); |
| 165 |
– |
_date.setText(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date(Long.parseLong(packet.getParam("packet.attributes.date"))))); |
| 166 |
– |
_seq_no.setText(packet.getParam("packet.attributes.seq_no")); |
| 167 |
– |
|
| 168 |
– |
_sTime.setText(packet.getParam("packet.sTime")); |
| 169 |
– |
|
| 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")); |
| 194 |
– |
} |
| 195 |
– |
} |
| 140 |
|
} catch (Exception e) { |
| 141 |
< |
System.err.println("ERROR: " + e); |
| 141 |
> |
System.err.println("ERROR RUN: " + e); |
| 142 |
|
} |
| 143 |
|
} |
| 144 |
|
|
| 160 |
|
|
| 161 |
|
//---ATTRIBUTES--- |
| 162 |
|
|
| 163 |
< |
JLabel _machine_name = new JLabel(); |
| 164 |
< |
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(); |
| 163 |
> |
HostDisplayPanel host; |
| 164 |
> |
JTabbedPane _tabbedPane = new JTabbedPane(); |
| 165 |
|
DataReader _data; |
| 166 |
+ |
JLabel _status = new JLabel(); |
| 167 |
+ |
ImageIcon _serverIcon = new ImageIcon("server.gif"); |
| 168 |
+ |
JLabel _serverCountLabel; |
| 169 |
+ |
int _serverCount = 0; |
| 170 |
|
|
| 171 |
|
//---STATIC ATTRIBUTES--- |
| 172 |
|
|