| 1 |
ajm |
1.1 |
//---PACKAGE DECLARATION--- |
| 2 |
|
|
|
| 3 |
|
|
//---IMPORTS--- |
| 4 |
|
|
import javax.swing.*; |
| 5 |
|
|
import javax.swing.border.*; |
| 6 |
|
|
import java.awt.Color; |
| 7 |
|
|
|
| 8 |
|
|
import java.awt.*; |
| 9 |
|
|
import java.awt.event.*; |
| 10 |
|
|
import java.net.*; |
| 11 |
|
|
import java.io.*; |
| 12 |
|
|
|
| 13 |
|
|
/** |
| 14 |
|
|
* NASTY AND BASIC, PLEASE DON'T COMPLAIN |
| 15 |
|
|
* |
| 16 |
|
|
* @author $Author: ajm4 $ |
| 17 |
|
|
* @version $Id: SimpleSwingLogger.java,v 1.5 2000/12/12 18:28:54 ajm4 Exp $ |
| 18 |
|
|
*/ |
| 19 |
|
|
public class SwingClient extends JFrame implements Runnable { |
| 20 |
|
|
|
| 21 |
|
|
//---FINAL ATTRIBUTES--- |
| 22 |
|
|
|
| 23 |
|
|
/** |
| 24 |
|
|
* The current CVS revision of this class |
| 25 |
|
|
*/ |
| 26 |
|
|
public final String REVISION = "$Revision: 1.5 $"; |
| 27 |
|
|
|
| 28 |
|
|
private final int width = 300; |
| 29 |
|
|
private final int height = 700; |
| 30 |
|
|
|
| 31 |
|
|
//---STATIC METHODS--- |
| 32 |
|
|
|
| 33 |
|
|
public static void main(String[] args) { |
| 34 |
|
|
try { |
| 35 |
|
|
String host = args[0]; |
| 36 |
|
|
int port = 4510; |
| 37 |
|
|
Socket socket = new Socket(host, port); |
| 38 |
|
|
BufferedReader inBound = new BufferedReader(new InputStreamReader(socket.getInputStream())); |
| 39 |
|
|
PrintWriter outBound = new PrintWriter(socket.getOutputStream()); |
| 40 |
|
|
DataReader data = new DataReader(inBound); |
| 41 |
|
|
|
| 42 |
|
|
SwingClient cli = new SwingClient(data); |
| 43 |
|
|
Thread cliThread = new Thread(cli); |
| 44 |
|
|
cliThread.start(); |
| 45 |
|
|
} catch (Exception e) { |
| 46 |
|
|
System.err.println("ERROR: " + e); |
| 47 |
|
|
} |
| 48 |
|
|
} |
| 49 |
|
|
|
| 50 |
|
|
//---CONSTRUCTORS--- |
| 51 |
|
|
|
| 52 |
|
|
/** |
| 53 |
|
|
* Creates a new Swing Client. |
| 54 |
|
|
*/ |
| 55 |
|
|
public SwingClient(DataReader data) { |
| 56 |
|
|
_data = data; |
| 57 |
|
|
// set up the Frame |
| 58 |
|
|
setTitle("I-Scream Client"); |
| 59 |
|
|
setSize(width, height); |
| 60 |
|
|
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); |
| 71 |
|
|
|
| 72 |
|
|
ImageIcon icon = new ImageIcon("server.gif"); |
| 73 |
|
|
JTabbedPane tabbedPane = new JTabbedPane(); |
| 74 |
|
|
JPanel mainPanel = new JPanel(); |
| 75 |
|
|
mainPanel.setLayout(new GridLayout(21, 1)); |
| 76 |
|
|
|
| 77 |
|
|
JPanel panel1 = makeTextPanel("Machine Name : ", _machine_name); |
| 78 |
|
|
JPanel panel2 = makeTextPanel("IP : ", _ip); |
| 79 |
|
|
JPanel panel3 = makeTextPanel("Date : ", _date); |
| 80 |
|
|
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); |
| 123 |
|
|
|
| 124 |
|
|
// build the frame |
| 125 |
|
|
box.add(header); |
| 126 |
|
|
box.add(tabbedPane); |
| 127 |
|
|
getContentPane().add(box); |
| 128 |
|
|
|
| 129 |
|
|
// show the window |
| 130 |
|
|
show(); |
| 131 |
|
|
} |
| 132 |
|
|
|
| 133 |
|
|
//---PUBLIC METHODS--- |
| 134 |
|
|
|
| 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 |
|
|
|
| 186 |
|
|
//---PRIVATE METHODS--- |
| 187 |
|
|
|
| 188 |
|
|
protected JPanel makeTextPanel(String text, JLabel item) { |
| 189 |
|
|
JPanel panel = new JPanel(false); |
| 190 |
|
|
JLabel label = new JLabel(text); |
| 191 |
|
|
label.setHorizontalAlignment(JLabel.RIGHT); |
| 192 |
|
|
item.setHorizontalAlignment(JLabel.LEFT); |
| 193 |
|
|
panel.setLayout(new GridLayout(1, 2)); |
| 194 |
|
|
panel.add(label); |
| 195 |
|
|
panel.add(item); |
| 196 |
|
|
return panel; |
| 197 |
|
|
} |
| 198 |
|
|
|
| 199 |
|
|
|
| 200 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
| 201 |
|
|
|
| 202 |
|
|
//---ATTRIBUTES--- |
| 203 |
|
|
|
| 204 |
|
|
JLabel _machine_name = new JLabel(); |
| 205 |
|
|
JLabel _ip = new JLabel(); |
| 206 |
|
|
JLabel _date = new JLabel(); |
| 207 |
|
|
JLabel _seq_no = new JLabel(); |
| 208 |
|
|
|
| 209 |
|
|
JLabel _sTime = new JLabel(); |
| 210 |
|
|
|
| 211 |
|
|
JLabel _load_load1 = new JLabel(); |
| 212 |
|
|
JLabel _load_load5 = new JLabel(); |
| 213 |
|
|
JLabel _load_load15 = new JLabel(); |
| 214 |
|
|
|
| 215 |
|
|
JLabel _processes_total = new JLabel(); |
| 216 |
|
|
JLabel _processes_sleeping = new JLabel(); |
| 217 |
|
|
JLabel _processes_zombie = new JLabel(); |
| 218 |
|
|
JLabel _processes_stopped = new JLabel(); |
| 219 |
|
|
|
| 220 |
|
|
JLabel _cpu_idle = new JLabel(); |
| 221 |
|
|
JLabel _cpu_user = new JLabel(); |
| 222 |
|
|
JLabel _cpu_kernel = new JLabel(); |
| 223 |
|
|
JLabel _cpu_iowait = new JLabel(); |
| 224 |
|
|
JLabel _cpu_swap = new JLabel(); |
| 225 |
|
|
|
| 226 |
|
|
JLabel _memory_real = new JLabel(); |
| 227 |
|
|
JLabel _memory_free = new JLabel(); |
| 228 |
|
|
JLabel _memory_swapinuse = new JLabel(); |
| 229 |
|
|
JLabel _memory_swapfree = new JLabel(); |
| 230 |
|
|
DataReader _data; |
| 231 |
|
|
|
| 232 |
|
|
//---STATIC ATTRIBUTES--- |
| 233 |
|
|
|
| 234 |
|
|
} |