1
2
3
4
5 package org.astrogrid.monitor;
6
7 import java.io.IOException;
8 import java.io.InputStream;
9 import java.io.OutputStreamWriter;
10 import java.io.PrintWriter;
11 import java.net.MalformedURLException;
12 import java.net.URL;
13 import java.rmi.RemoteException;
14 import java.util.Enumeration;
15 import java.util.Vector;
16 import javax.xml.rpc.ServiceException;
17 import javax.xml.rpc.encoding.XMLType;
18 import org.apache.axis.client.Call;
19 import org.apache.axis.client.Service;
20 import org.astrogrid.status.ServiceStatus;
21 import org.astrogrid.util.TimeStamp;
22
23 /***
24 * Servlet for monitoring the statuses of other services and displaying them
25 * in HTML
26 *
27 * @author mch
28 */
29 public class Monitor {
30
31 Vector datacenters = null;
32 Vector ceaServices = null;
33
34 final static String ERR_COLOUR = "#FF0000";
35 final static String OK_COLOUR = "#00FF00";
36 final static String WARN_COLOUR = "#FFFF00";
37
38 /*** Set up with default list of datacenters */
39 protected void initialise() {
40 datacenters = new Vector();
41 datacenters.add("http://grendel12.roe.ac.uk:8080/pal-6df");
42 datacenters.add("http://grendel12.roe.ac.uk:8080/pal-sec");
43 datacenters.add("http://grendel12.roe.ac.uk:8080/pal-vizier");
44 datacenters.add("http://astrogrid.roe.ac.uk:8080/pal-ssa");
45 datacenters.add("http://astrogrid.roe.ac.uk:8080/pal-usnob");
46 datacenters.add("http://astrogrid.roe.ac.uk:8080/pal-twomass");
47 datacenters.add("http://zhumulangma.star.le.ac.uk:8080/astrogrid-pal-SNAPSHOT");
48 datacenters.add("http://msslxy.mssl.ucl.ac.uk:8080/astrogrid-pal-fits-SNAPSHOT");
49 datacenters.add("http://ag01.ast.cam.ac.uk:8080/astrogrid-pal-Itn05_release");
50 datacenters.add("http://twmbarlwm.star.le.ac.uk:8888/astrogrid-pal-SNAPSHOT");
51 datacenters.add("http://twmbarlwm.star.le.ac.uk:8888/astrogrid-pal-fits-SNAPSHOT");
52 datacenters.add("http://twmbarlwm.star.le.ac.uk:8888/astrogrid-pal-cds-SNAPSHOT");
53 datacenters.add("http://twmbarlwm.star.le.ac.uk:8888/astrogrid-pal-sec-SNAPSHOT");
54
55 ceaServices = new Vector();
56 ceaServices.add("http://grendel12.roe.ac.uk:8080/pal-6df");
57 ceaServices.add("http://grendel12.roe.ac.uk:8080/pal-sec");
58 ceaServices.add("http://grendel12.roe.ac.uk:8080/pal-vizier");
59 ceaServices.add("http://astrogrid.roe.ac.uk:8080/pal-ssa");
60 ceaServices.add("http://astrogrid.roe.ac.uk:8080/pal-usnob");
61 ceaServices.add("http://astrogrid.roe.ac.uk:8080/pal-twomass");
62 ceaServices.add("http://zhumulangma.star.le.ac.uk:8080/astrogrid-pal-SNAPSHOT");
63 }
64
65 public Monitor() {
66 initialise();
67 }
68
69 /***
70 * Finds out statuses of all services and makes an Html table to the given
71 * Writer. Does it this way so we can flush as we write, in case some servers
72 * timeout, etc
73 */
74 public void writeHtmlTables(PrintWriter out) throws IOException {
75
76 out.print("<h3>Datacenters</h3>");
77 out.print("<table>"+
78 "<tr>"+
79 "<th>Endpoint</th><th>JSP</th><th>SOAP</th>"+
80 "</tr>");
81
82 Enumeration datacenter = datacenters.elements();
83 while (datacenter.hasMoreElements()) {
84 out.flush();
85 String endpoint = (String) datacenter.nextElement();
86 writeDatacenterStatusRow(endpoint, out);
87 }
88 out.print("</table>");
89 out.flush();
90 }
91
92
93
94 protected void writeDatacenterStatusRow(String endpoint, PrintWriter out) {
95 out.println("<tr>");
96 out.println("<td><a href='"+endpoint+"'>"+endpoint+"</a></td>");
97 try {
98
99 TimeStamp timestamp = new TimeStamp();
100 URL url = new URL(endpoint+"/serverStatus.jsp");
101 InputStream in = url.openStream();
102 String bgcolor=OK_COLOUR;
103 if (timestamp.getSecsSince()>5) { bgcolor=WARN_COLOUR; }
104 out.println("<td bgcolor='"+bgcolor+"'>"+timestamp.getSecsSince()+"s</td>");
105 }
106 catch (MalformedURLException mue) {
107 out.println("<td bgcolor='"+ERR_COLOUR+"'>"+mue.getMessage()+"</td>");
108 }
109 catch (IOException ioe) {
110 out.println("<td bgcolor='"+ERR_COLOUR+"'>"+ioe.getMessage()+"</td>");
111 }
112
113
114 try {
115 TimeStamp timestamp = new TimeStamp();
116 ServiceStatus status = getDatacenterStatus(endpoint);
117 out.println("<td bgcolor='"+OK_COLOUR+"'>"+timestamp.getSecsSince()+"s</td>");
118 }
119 catch (ServiceException e) {
120 out.println("<td bgcolor='"+ERR_COLOUR+"'>"+e+"</td>");
121 }
122 catch (RemoteException e) {
123 out.println("<td bgcolor='"+ERR_COLOUR+"'>"+e+"</td>");
124 }
125
126 out.println("</tr>\n");
127
128 }
129
130 public static ServiceStatus getDatacenterStatus(String endpoint) throws ServiceException, RemoteException {
131 Service service = new Service();
132 Call call = (Call) service.createCall();
133
134 call.setTargetEndpointAddress( endpoint+"/services/AxisDataService06");
135 call.setOperationName("getServiceStatus");
136
137
138
139 Object response = call.invoke( new Object[] { } );
140
141 return null;
142 }
143
144 public static String getSimpleDatacenterStatus(String endpoint) throws ServiceException, RemoteException {
145 Service service = new Service();
146 Call call = (Call) service.createCall();
147
148 call.setTargetEndpointAddress( endpoint+"/services/AxisDataService06");
149 call.setOperationName("getSimpleServiceStatus");
150
151 call.setReturnType( XMLType.XSD_STRING );
152
153 return (String) call.invoke( new Object[] { } );
154 }
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197 /***
198 *
199 */
200 public static void main(String[] args) throws IOException {
201 Monitor m = new Monitor();
202 PrintWriter out =new PrintWriter(new OutputStreamWriter(System.out));
203 out.write("<html><body>");
204 m.writeHtmlTables(out);
205 out.write("</body></html>");
206 }
207 }
208