ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/conient/uk/org/iscream/cms/conient/Conient.java
(Generate patch)

Comparing projects/cms/source/conient/uk/org/iscream/cms/conient/Conient.java (file contents):
Revision 1.2 by ajm, Sun Jan 14 22:37:24 2001 UTC vs.
Revision 1.5 by ajm, Mon Jan 15 03:01:37 2001 UTC

# Line 12 | Line 12 | import java.io.*;
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
# Line 28 | Line 29 | public class SwingClient extends JFrame implements Run
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      
# Line 72 | Line 84 | public class SwingClient extends JFrame implements Run
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();
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.
# Line 155 | Line 124 | public class SwingClient extends JFrame implements Run
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 <            
166 <            _load_load1.setText(packet.getParam("packet.load.load1"));
167 <            _load_load5.setText(packet.getParam("packet.load.load5"));
168 <            _load_load15.setText(packet.getParam("packet.load.load15"));
169 <            
170 <            _processes_total.setText(packet.getParam("packet.processes.total"));
171 <            _processes_sleeping.setText(packet.getParam("packet.processes.sleeping"));
172 <            _processes_zombie.setText(packet.getParam("packet.processes.zombie"));
173 <            _processes_stopped.setText(packet.getParam("packet.processes.stopped"));
174 <            
175 <            _cpu_idle.setString(packet.getParam("packet.cpu.idle") + "%");
176 <            _cpu_idle.setValue(new Double(packet.getParam("packet.cpu.idle")).intValue());
177 <            _cpu_user.setString(packet.getParam("packet.cpu.user") + "%");
178 <            _cpu_user.setValue(new Double(packet.getParam("packet.cpu.user")).intValue());
179 <            _cpu_kernel.setString(packet.getParam("packet.cpu.kernel") + "%");
180 <            _cpu_kernel.setValue(new Double(packet.getParam("packet.cpu.kernel")).intValue());
181 <            _cpu_iowait.setString(packet.getParam("packet.cpu.iowait") + "%");
182 <            _cpu_iowait.setValue(new Double(packet.getParam("packet.cpu.iowait")).intValue());
183 <            _cpu_swap.setString(packet.getParam("packet.cpu.swap") + "%");
184 <            _cpu_swap.setValue(new Double(packet.getParam("packet.cpu.swap")).intValue());
185 <            
186 <            _memory_real.setText(packet.getParam("packet.memory.real"));
187 <            _memory_free.setText(packet.getParam("packet.memory.free"));
188 <            _memory_swapinuse.setText(packet.getParam("packet.memory.swapinuse"));
189 <            _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 RUN: " + e);
139 +        }
140      }
141  
142   //---PRIVATE METHODS---
# Line 209 | Line 157 | public class SwingClient extends JFrame implements Run
157  
158   //---ATTRIBUTES---
159  
160 <    JLabel _machine_name = new JLabel();
161 <    JLabel _ip = new JLabel();
214 <    JLabel _date = new JLabel();
215 <    JLabel _seq_no = new JLabel();
216 <    
217 <    JLabel _sTime = new JLabel();
218 <    
219 <    JLabel _load_load1 = new JLabel();
220 <    JLabel _load_load5 = new JLabel();
221 <    JLabel _load_load15 = new JLabel();
222 <    
223 <    JLabel _processes_total = new JLabel();
224 <    JLabel _processes_sleeping = new JLabel();
225 <    JLabel _processes_zombie = new JLabel();
226 <    JLabel _processes_stopped = new JLabel();
227 <    
228 <    int min = 0;
229 <    int max = 100;
230 <    JProgressBar _cpu_idle = new JProgressBar(JProgressBar.HORIZONTAL, min, max);
231 <    {
232 <        _cpu_idle.setStringPainted(true);
233 <    }
234 <    JProgressBar _cpu_user = new JProgressBar(JProgressBar.HORIZONTAL, min, max);
235 <    {
236 <        _cpu_user.setStringPainted(true);
237 <    }
238 <    JProgressBar _cpu_kernel = new JProgressBar(JProgressBar.HORIZONTAL, min, max);
239 <    {
240 <        _cpu_kernel.setStringPainted(true);
241 <    }
242 <    JProgressBar _cpu_iowait = new JProgressBar(JProgressBar.HORIZONTAL, min, max);
243 <    {
244 <        _cpu_iowait.setStringPainted(true);
245 <    }
246 <    JProgressBar _cpu_swap = new JProgressBar(JProgressBar.HORIZONTAL, min, max);
247 <    {
248 <        _cpu_swap.setStringPainted(true);
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();
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      

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines