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.8 by ajm, Sat Jan 20 16:06:53 2001 UTC

# Line 4 | Line 4
4   import javax.swing.*;
5   import javax.swing.border.*;
6   import java.awt.Color;
7 + import uk.ac.ukc.iscream.util.*;
8  
9   import java.awt.*;
10   import java.awt.event.*;
# Line 12 | Line 13 | import java.io.*;
13   import java.util.Date;
14   import java.text.DateFormat;
15   import java.util.Locale;
16 + import java.util.HashMap;
17 + import javax.swing.border.*;
18  
19   /**
20   * NASTY AND BASIC, PLEASE DON'T COMPLAIN
# Line 28 | Line 31 | public class SwingClient extends JFrame implements Run
31       */
32      public final String REVISION = "$Revision$";
33      
34 <    private final int width = 300;
34 >    private final int width = 400;
35      private final int height = 700;
36      
37   //---STATIC METHODS---
38  
39      public static void main(String[] args) {
40          try {
41 <            String host = args[0];
41 >            String host = null;
42 >            if (args.length != 1) {
43 >                Object response = null;
44 >                while(!(response instanceof String)) {
45 >                    response = JOptionPane.showInputDialog(null, "Please enter the name of a server running the I-Scream client interface:", "I-Scream Server", JOptionPane.INFORMATION_MESSAGE);
46 >                }
47 >                host = (String) response;
48 >            } else {
49 >                host = args[0];
50 >            }
51 >
52              int port = 4510;
53              Socket socket = new Socket(host, port);
54              BufferedReader inBound = new BufferedReader(new InputStreamReader(socket.getInputStream()));
55              PrintWriter outBound = new PrintWriter(socket.getOutputStream());
56 <            DataReader data = new DataReader(inBound);
56 >
57 >            Queue dataQueue = new Queue();
58 >            DataReader data = new DataReader(inBound, dataQueue);
59          
60 <            SwingClient cli = new SwingClient(data);
61 <            Thread cliThread = new Thread(cli);
62 <            cliThread.start();
60 >            SwingClient client = new SwingClient(dataQueue);
61 >            Thread clientThread = new Thread(client);
62 >            
63 >            clientThread.start();
64 >            data.start();
65 >
66          } catch (Exception e) {
67 <            System.err.println("ERROR: " + e);
67 >            System.err.println("ERROR START: " + e);
68 >            System.exit(1);
69          }  
70      }
71      
# Line 55 | Line 74 | public class SwingClient extends JFrame implements Run
74      /**
75       * Creates a new Swing Client.
76       */
77 <    public SwingClient(DataReader data) {
78 <        _data = data;
77 >    public SwingClient(Queue dataQueue) {
78 >        
79 >        _dataQueue = dataQueue;
80 >        _myQueue = _dataQueue.getQueue();
81          // set up the Frame
82          setTitle("I-Scream Client");
83 <        setSize(width, height);
83 >        //setSize(width, height);
84          setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
85          Box box = Box.createVerticalBox();
86  
87          // create the i-scream logo at the top
88          JLabel iscream = new JLabel(new ImageIcon("i-scream.gif"));
89 <        JLabel comment = new JLabel("   I-Scream Client");
90 <        comment.setForeground( new Color(0, 0, 102));
89 >        _serverCountLabel = new JLabel("   Monitoring 0 hosts...");
90 >        _serverCountLabel.setForeground( new Color(0, 0, 102));
91          Box header = Box.createHorizontalBox();
92 <        header.add(comment);
92 >        header.add(_serverCountLabel);
93          header.add(Box.createHorizontalGlue());
94          header.add(iscream);
95 +        Box main = Box.createHorizontalBox();
96 +        JButton
97   utton = new JButton("Connect");
98          
99 <        ImageIcon icon = new ImageIcon("server.gif");
100 <        JTabbedPane tabbedPane = new JTabbedPane();
101 <        JPanel mainPanel = new JPanel();
102 <        mainPanel.setLayout(new GridLayout(21, 1));
80 <
81 <        JPanel panel1 = makeTextPanel("Machine Name : ", _machine_name);
82 <        JPanel panel2 = makeTextPanel("IP : ", _ip);
83 <        JPanel panel3 = makeTextPanel("Date : ", _date);
84 <        JPanel panel4 = makeTextPanel("Sequence Number : ", _seq_no);
85 <        JPanel panel5 = makeTextPanel("Host Time : ", _sTime);
86 <        JPanel panel6 = makeTextPanel("Load Average (1 min) : ", _load_load1);
87 <        JPanel panel7 = makeTextPanel("Load Average (5 min) : ", _load_load5);
88 <        JPanel panel8 = makeTextPanel("Load Average (15 min) : ", _load_load15);
89 <        JPanel panel9 = makeTextPanel("Processes Total : ", _processes_total);
90 <        JPanel panel10 = makeTextPanel("Processes Sleeping : ", _processes_sleeping);
91 <        JPanel panel11 = makeTextPanel("Processes Zombie : ", _processes_zombie);
92 <        JPanel panel12 = makeTextPanel("Processes Stopped : ", _processes_stopped);
93 <        JPanel panel13 = makeTextPanel("CPU % idle : ", _cpu_idle);
94 <        JPanel panel14 = makeTextPanel("CPU % user : ", _cpu_user);
95 <        JPanel panel15 = makeTextPanel("CPU % kernel : ", _cpu_kernel);
96 <        JPanel panel16 = makeTextPanel("CPU % i/o wait : ", _cpu_iowait);
97 <        JPanel panel17 = makeTextPanel("CPU % swapping : ", _cpu_swap);
98 <        JPanel panel18 = makeTextPanel("Real Memory : ", _memory_real);
99 <        JPanel panel19 = makeTextPanel("Real Free : ", _memory_free);
100 <        JPanel panel20 = makeTextPanel("Swap in use : ", _memory_swapinuse);
101 <        JPanel panel21 = makeTextPanel("Swap free : ", _memory_swapfree);
102 <        mainPanel.add(panel1);
103 <        mainPanel.add(panel2);
104 <        mainPanel.add(panel3);
105 <        mainPanel.add(panel4);
106 <        mainPanel.add(panel5);
107 <        mainPanel.add(panel6);
108 <        mainPanel.add(panel7);
109 <        mainPanel.add(panel8);
110 <        mainPanel.add(panel9);
111 <        mainPanel.add(panel10);
112 <        mainPanel.add(panel11);
113 <        mainPanel.add(panel12);
114 <        mainPanel.add(panel13);
115 <        mainPanel.add(panel14);
116 <        mainPanel.add(panel15);
117 <        mainPanel.add(panel16);
118 <        mainPanel.add(panel17);
119 <        mainPanel.add(panel18);
120 <        mainPanel.add(panel19);
121 <        mainPanel.add(panel20);
122 <        mainPanel.add(panel21);
99 >        // set up the text area
100 >        _status.setEditable(false);
101 >        JScrollPane statusPane = new JScrollPane(_status);
102 >        statusPane.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Messages "));
103          
104 <        tabbedPane.addTab("Raptor", icon, mainPanel, "Monitor raptor.ukc.ac.uk");
105 <        
106 <        tabbedPane.setSelectedIndex(0);
104 >        Box controlPane = Box.createVerticalBox();
105 >        controlPane.add(button);
106 >        //controlPane.add(Box.createVerticalGlue());
107 >        controlPane.add(statusPane);
108 >        main.add(controlPane);
109 >        main.add(_tabbedPane);
110  
111 +        //_tabbedPane.setSelectedIndex(0);
112 +        
113          // build the frame
114          box.add(header);
115 <        box.add(tabbedPane);
115 >        box.add(main);
116 >        
117          getContentPane().add(box);
118  
119          // show the window
120          show();
121 +        _status.insert("Running...\n",0);
122      }
123  
124   //---PUBLIC METHODS---
125  
126      public void run() {
127 <        _data.start();
128 <        while(true) {
129 <            String xml = _data.getXML();
130 <            if (xml == null) {
131 <                // nothing
132 <            } else {
133 <            
134 <            // Get a string without any null characters in it.
135 <            //  -- maybe String.trim() would be better here ?
136 <            if (xml.indexOf(0) != -1) {
137 <                xml = xml.substring(0, xml.indexOf(0));
127 >        HashMap hostList = new HashMap();
128 >        try {
129 >            while(true) {
130 >                
131 >                String xml = (String) _dataQueue.get(_myQueue);
132 >                if (xml == null) {
133 >                    // shouldn't really happen...but not sure
134 >                    _status.insert("No XML to update...",0);
135 >                } else {
136 >                    
137 >                    // Get a string without any null characters in it.
138 >                    //  -- maybe String.trim() would be better ?
139 >                    if (xml.indexOf(0) != -1) {
140 >                        xml = xml.substring(0, xml.indexOf(0));
141 >                    }
142 >                    else {
143 >                        xml = xml.substring(0, xml.length());
144 >                    }
145 >                    
146 >                    // Use XMLPacketMaker to make an XMLPacket object.
147 >                    XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml);
148 >                    XMLPacket packet = xmlPacketMaker.createXMLPacket();
149 >                    String hostName = packet.getParam("packet.attributes.machine_name");
150 >                    if(!hostList.containsKey(hostName)) {
151 >                        _serverCount++;
152 >                        _serverCountLabel.setText("   Monitoring " + _serverCount + " hosts...");
153 >                        host = new HostDisplayPanel();      
154 >                        _tabbedPane.addTab(hostName, _serverIcon, host, "Monitor " + hostName);
155 >                        hostList.put(hostName, host);
156 >                        _status.insert("New Host added: " + hostName + "\n", 0);
157 >                    }
158 >                    ((HostDisplayPanel) hostList.get(hostName)).updateHost(packet);
159 >                }
160              }
161 <            else {
162 <                xml = xml.substring(0, xml.length());
154 <            }
155 <            
156 <            // Use XMLPacketMaker to make an XMLPacket object.
157 <            XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml);
158 <            XMLPacket packet = xmlPacketMaker.createXMLPacket();
159 <            
160 <            _machine_name.setText(packet.getParam("packet.attributes.machine_name"));
161 <            _ip.setText(packet.getParam("packet.attributes.ip"));
162 <            _date.setText(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date(Long.parseLong(packet.getParam("packet.attributes.date")))));
163 <            _seq_no.setText(packet.getParam("packet.attributes.seq_no"));
164 <            
165 <            _sTime.setText(packet.getParam("packet.sTime"));
166 <            
167 <            _load_load1.setText(packet.getParam("packet.load.load1"));
168 <            _load_load5.setText(packet.getParam("packet.load.load5"));
169 <            _load_load15.setText(packet.getParam("packet.load.load15"));
170 <            
171 <            _processes_total.setText(packet.getParam("packet.processes.total"));
172 <            _processes_sleeping.setText(packet.getParam("packet.processes.sleeping"));
173 <            _processes_zombie.setText(packet.getParam("packet.processes.zombie"));
174 <            _processes_stopped.setText(packet.getParam("packet.processes.stopped"));
175 <            
176 <            _cpu_idle.setString(packet.getParam("packet.cpu.idle") + "%");
177 <            _cpu_idle.setValue(new Double(packet.getParam("packet.cpu.idle")).intValue());
178 <            _cpu_user.setString(packet.getParam("packet.cpu.user") + "%");
179 <            _cpu_user.setValue(new Double(packet.getParam("packet.cpu.user")).intValue());
180 <            _cpu_kernel.setString(packet.getParam("packet.cpu.kernel") + "%");
181 <            _cpu_kernel.setValue(new Double(packet.getParam("packet.cpu.kernel")).intValue());
182 <            _cpu_iowait.setString(packet.getParam("packet.cpu.iowait") + "%");
183 <            _cpu_iowait.setValue(new Double(packet.getParam("packet.cpu.iowait")).intValue());
184 <            _cpu_swap.setString(packet.getParam("packet.cpu.swap") + "%");
185 <            _cpu_swap.setValue(new Double(packet.getParam("packet.cpu.swap")).intValue());
186 <            
187 <            _memory_real.setText(packet.getParam("packet.memory.real"));
188 <            _memory_free.setText(packet.getParam("packet.memory.free"));
189 <            _memory_swapinuse.setText(packet.getParam("packet.memory.swapinuse"));
190 <            _memory_swapfree.setText(packet.getParam("packet.memory.swapfree"));
191 <            }
161 >        } catch (Exception e) {
162 >            System.err.println("ERROR RUN: " + e);
163          }
164      }
165  
166   //---PRIVATE METHODS---
167      
168 <    protected JPanel makeTextPanel(String text, Component item) {
168 >    protected JPanel makeTextPanel(String text, java.awt.Component item) {
169          JPanel panel = new JPanel(false);
170          JLabel label = new JLabel(text);
171          label.setHorizontalAlignment(JLabel.RIGHT);
# Line 209 | Line 180 | public class SwingClient extends JFrame implements Run
180  
181   //---ATTRIBUTES---
182  
183 <    JLabel _machine_name = new JLabel();
184 <    JLabel _ip = new JLabel();
185 <    JLabel _date = new JLabel();
186 <    JLabel _seq_no = new JLabel();
183 >    HostDisplayPanel host;
184 >    JTabbedPane _tabbedPane = new JTabbedPane();
185 >    Queue _dataQueue;
186 >    int _myQueue;
187 >    JTextArea _status = new JTextArea();
188 >    ImageIcon _serverIcon = new ImageIcon("server.gif");
189 >    JLabel _serverCountLabel;
190 >    int _serverCount = 0;
191      
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();
255    DataReader _data;
192      
193   //---STATIC ATTRIBUTES---
194      
195 < }
195 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines