1 | <?php
|
---|
2 |
|
---|
3 | $us3bin = exec( "ls -d ~us3/bin" );
|
---|
4 | include "$us3bin/listen-config.php";
|
---|
5 |
|
---|
6 | $xml = get_data();
|
---|
7 |
|
---|
8 | if ( $xml != "" )
|
---|
9 | parse( $xml );
|
---|
10 |
|
---|
11 | $data = array();
|
---|
12 |
|
---|
13 | local_status();
|
---|
14 |
|
---|
15 | foreach ( $data as $item )
|
---|
16 | {
|
---|
17 | update( $item[ 'cluster' ], $item[ 'queued' ], $item[ 'status' ], $item[ 'running' ] );
|
---|
18 | }
|
---|
19 |
|
---|
20 | exit();
|
---|
21 |
|
---|
22 | // Get the cluster status
|
---|
23 |
|
---|
24 | function get_data()
|
---|
25 | {
|
---|
26 | global $self;
|
---|
27 | $url = "http://community.ucs.indiana.edu:19444/orps-service/XML/gateway/ultrascan";
|
---|
28 |
|
---|
29 | try
|
---|
30 | {
|
---|
31 | $post = new HttpRequest( $url, HttpRequest::METH_GET );
|
---|
32 | $http = $post->send();
|
---|
33 | $xml = $post->getResponseBody();
|
---|
34 | }
|
---|
35 | catch ( HttpException $e )
|
---|
36 | {
|
---|
37 | // write_log( "$self: Cluster Status not available" );
|
---|
38 | return "";
|
---|
39 | }
|
---|
40 |
|
---|
41 | return $xml;
|
---|
42 | }
|
---|
43 |
|
---|
44 | // Parse the xml
|
---|
45 |
|
---|
46 | function parse( $xml )
|
---|
47 | {
|
---|
48 | global $data;
|
---|
49 |
|
---|
50 | $data = array();
|
---|
51 |
|
---|
52 | $x = new XML_Array( $xml );
|
---|
53 | $d = $x->ReturnArray();
|
---|
54 |
|
---|
55 | if ( ! isset( $d[ 'summaries' ] ) ) exit(); // Bad input
|
---|
56 |
|
---|
57 | foreach ( $d[ 'summaries' ] as $item )
|
---|
58 | {
|
---|
59 | $a = Array();
|
---|
60 |
|
---|
61 |
|
---|
62 | $a[ 'queued' ] = $item[ 'waitingJobs' ];
|
---|
63 | $a[ 'running' ] = $item[ 'runningJobs' ];
|
---|
64 |
|
---|
65 | if ( $a[ 'queued' ] == "" || $a[ 'queued' ] < 0 ) $a[ 'queued' ] = 0;
|
---|
66 | if ( $a[ 'running' ] == "" || $a[ 'running' ] < 0 ) $a[ 'running' ] = 0;
|
---|
67 |
|
---|
68 | $clusterParts = explode( ".", $item[ 'resourceId' ] );
|
---|
69 | $cluster = preg_replace( '/\d+$/', "", $clusterParts[ 0 ] );
|
---|
70 |
|
---|
71 | if ( $cluster == 'uthscsa-bcf' ) $cluster = 'bcf';
|
---|
72 | if ( $cluster == 'uthscsa-alamo' ) $cluster = 'alamo';
|
---|
73 |
|
---|
74 | $a[ 'cluster' ] = $cluster;
|
---|
75 |
|
---|
76 | switch ( $item[ 'resourceStatus' ] )
|
---|
77 | {
|
---|
78 | case 'UP' :
|
---|
79 | $status = "up";
|
---|
80 | break;
|
---|
81 |
|
---|
82 | case 'DOWN' :
|
---|
83 | $status = "down";
|
---|
84 | break;
|
---|
85 |
|
---|
86 | case 'WARN' :
|
---|
87 | $status = "warn";
|
---|
88 | break;
|
---|
89 |
|
---|
90 | case 'FAILED' :
|
---|
91 | default :
|
---|
92 | $status = "unknown";
|
---|
93 | break;
|
---|
94 | }
|
---|
95 |
|
---|
96 | $a[ 'status' ] = $status;
|
---|
97 |
|
---|
98 | $data[] = $a;
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | // Put it in the DB
|
---|
103 |
|
---|
104 | function update( $cluster, $queued, $status, $running )
|
---|
105 | {
|
---|
106 | global $dbhost;
|
---|
107 | global $guser;
|
---|
108 | global $gpasswd;
|
---|
109 | global $gDB;
|
---|
110 | global $self;
|
---|
111 |
|
---|
112 | $gfac_link = mysql_connect( $dbhost, $guser, $gpasswd );
|
---|
113 | $result = mysql_select_db( $gDB, $gfac_link );
|
---|
114 |
|
---|
115 | if ( ! $result )
|
---|
116 | {
|
---|
117 | write_log( "$self: Could not connect to DB $gDB" );
|
---|
118 | echo "Could not connect to DB $gDB.\n";
|
---|
119 | exit();
|
---|
120 | }
|
---|
121 |
|
---|
122 | $query = "SELECT * FROM cluster_status WHERE cluster='$cluster'";
|
---|
123 | $result = mysql_query( $query, $gfac_link );
|
---|
124 |
|
---|
125 | if ( ! $result )
|
---|
126 | {
|
---|
127 | write_log( "$self: Query failed $query - " . mysql_error( $gfac_link ) );
|
---|
128 | echo "$self: Query failed $query - " . mysql_error( $gfac_link ) . "\n";
|
---|
129 | exit();
|
---|
130 | }
|
---|
131 |
|
---|
132 | $rows = mysql_num_rows( $result );
|
---|
133 |
|
---|
134 | if ( $rows == 0 ) // INSERT
|
---|
135 | {
|
---|
136 | $query = "INSERT INTO cluster_status SET " .
|
---|
137 | "cluster='$cluster', " .
|
---|
138 | "queued=$queued, " .
|
---|
139 | "running=$running, " .
|
---|
140 | "status='$status'";
|
---|
141 | }
|
---|
142 | else // UPDATE
|
---|
143 | {
|
---|
144 | $query = "UPDATE cluster_status SET " .
|
---|
145 | "queued=$queued, " .
|
---|
146 | "running=$running, " .
|
---|
147 | "status='$status' " .
|
---|
148 | "WHERE cluster='$cluster'";
|
---|
149 | }
|
---|
150 |
|
---|
151 | $result = mysql_query( $query, $gfac_link );
|
---|
152 |
|
---|
153 | if ( ! $result )
|
---|
154 | {
|
---|
155 | write_log( "$self: Query failed $query - " . mysql_error( $gfac_link ) );
|
---|
156 | echo "$self: Query failed $query - " . mysql_error( $gfac_link ) . "\n";
|
---|
157 | }
|
---|
158 | }
|
---|
159 |
|
---|
160 | // Get local cluster status
|
---|
161 |
|
---|
162 | function local_status()
|
---|
163 | {
|
---|
164 | global $self;
|
---|
165 | global $data;
|
---|
166 |
|
---|
167 | $clusters = array( "alamo", "lonestar5", "stampede",
|
---|
168 | "comet", "gordon", "jureca", "jacinto" );
|
---|
169 | foreach ( $clusters as $clname )
|
---|
170 | {
|
---|
171 | $a = Array();
|
---|
172 | switch( $clname )
|
---|
173 | {
|
---|
174 | case 'alamo':
|
---|
175 | {
|
---|
176 | $host = "us3@alamo.uthscsa.edu";
|
---|
177 | $qstat = `ssh $host '/usr/bin/qstat -B 2>&1|tail -1'`;
|
---|
178 | $sparts = preg_split( '/\s+/', $qstat );
|
---|
179 | $que = $sparts[ 3 ];
|
---|
180 | $run = $sparts[ 4 ];
|
---|
181 | $sta = $sparts[ 10 ];
|
---|
182 | if ( $sta == "Active" )
|
---|
183 | $sta = "up";
|
---|
184 | else
|
---|
185 | $sta = "down";
|
---|
186 | break;
|
---|
187 | }
|
---|
188 | case 'jacinto':
|
---|
189 | {
|
---|
190 | $host = "us3@jacinto.uthscsa.edu";
|
---|
191 | $qstat = `ssh $host '/opt/torque/bin/qstat -B 2>&1|tail -1'`;
|
---|
192 | $sparts = preg_split( '/\s+/', $qstat );
|
---|
193 | $que = $sparts[ 3 ];
|
---|
194 | $run = $sparts[ 4 ];
|
---|
195 | $sta = $sparts[ 9 ];
|
---|
196 | if ( $sta == "Active" )
|
---|
197 | $sta = "up";
|
---|
198 | else
|
---|
199 | $sta = "down";
|
---|
200 | break;
|
---|
201 | }
|
---|
202 | case 'stampede':
|
---|
203 | {
|
---|
204 | $host = "us3@stampede.tacc.utexas.edu";
|
---|
205 | $qstat = `ssh $host '/usr/local/bin/showq 2>&1|tail -1'`;
|
---|
206 | $sparts = preg_split( '/\s+/', $qstat );
|
---|
207 | $tot = $sparts[ 2 ];
|
---|
208 | $run = $sparts[ 5 ];
|
---|
209 | $que = $sparts[ 8 ];
|
---|
210 | $sta = "up";
|
---|
211 | if ( $tot == '' || $tot == '0' )
|
---|
212 | $sta = "down";
|
---|
213 | break;
|
---|
214 | }
|
---|
215 | case 'lonestar':
|
---|
216 | {
|
---|
217 | $host = "us3@lonestar.tacc.utexas.edu";
|
---|
218 | $qstat = `ssh $host 'showq 2>&1|tail -1'`;
|
---|
219 | $sparts = preg_split( '/\s+/', $qstat );
|
---|
220 | $tot = $sparts[ 2 ];
|
---|
221 | $run = '0';
|
---|
222 | $que = '0';
|
---|
223 | $sta = "up";
|
---|
224 | if ( $tot == '' || $tot == '0' )
|
---|
225 | {
|
---|
226 | $sta = "down";
|
---|
227 | }
|
---|
228 | else
|
---|
229 | {
|
---|
230 | $run = $sparts[ 5 ];
|
---|
231 | $que = $sparts[ 8 ];
|
---|
232 | }
|
---|
233 | break;
|
---|
234 | }
|
---|
235 | case 'lonestar5':
|
---|
236 | {
|
---|
237 | $host = "us3@ls5.tacc.utexas.edu";
|
---|
238 | $qstat = `ssh $host '/usr/local/bin/showq 2>&1|tail -1'`;
|
---|
239 | $sparts = preg_split( '/\s+/', $qstat );
|
---|
240 | $tot = $sparts[ 2 ];
|
---|
241 | $run = '0';
|
---|
242 | $que = '0';
|
---|
243 | $sta = "up";
|
---|
244 | if ( $tot == '' || $tot == '0' )
|
---|
245 | {
|
---|
246 | $sta = "down";
|
---|
247 | }
|
---|
248 | else
|
---|
249 | {
|
---|
250 | $run = $sparts[ 5 ];
|
---|
251 | $que = $sparts[ 8 ];
|
---|
252 | }
|
---|
253 | break;
|
---|
254 | }
|
---|
255 | case 'comet':
|
---|
256 | {
|
---|
257 | $host = "us3@comet.sdsc.edu";
|
---|
258 | $qstat = `ssh $host '/usr/bin/sinfo -s -p compute -o "%a %F" |tail -1'`;
|
---|
259 | $sparts = preg_split( '/\s+/', $qstat );
|
---|
260 | $sta = $sparts[ 0 ];
|
---|
261 | $knts = $sparts[ 1 ];
|
---|
262 | $sparts = preg_split( '/\//', $knts );
|
---|
263 | $run = $sparts[ 0 ];
|
---|
264 | $que = $sparts[ 1 ];
|
---|
265 | if ( $sta == "" )
|
---|
266 | $sta = "down";
|
---|
267 | break;
|
---|
268 | }
|
---|
269 | case 'gordon':
|
---|
270 | {
|
---|
271 | $host = "us3@gordon.sdsc.edu";
|
---|
272 | $qstat = `ssh $host '/opt/torque/bin/qstat -B 2>&1|tail -1'`;
|
---|
273 | $sparts = preg_split( '/\s+/', $qstat );
|
---|
274 | $que = $sparts[ 3 ];
|
---|
275 | $run = $sparts[ 4 ];
|
---|
276 | $sta = $sparts[ 10 ];
|
---|
277 | if ( $sta == "Active" )
|
---|
278 | $sta = "up";
|
---|
279 | else
|
---|
280 | $sta = "down";
|
---|
281 | break;
|
---|
282 | }
|
---|
283 | case 'jureca':
|
---|
284 | {
|
---|
285 | $host = "swus1@jureca.fz-juelich.de";
|
---|
286 | $qstat = `ssh $host '~swus1/scripts/qstat-jureca 2>&1'`;
|
---|
287 | $sparts = preg_split( '/\s+/', $qstat );
|
---|
288 | $sta = $sparts[ 0 ];
|
---|
289 | $run = $sparts[ 1 ];
|
---|
290 | $que = $sparts[ 2 ];
|
---|
291 | break;
|
---|
292 | }
|
---|
293 | }
|
---|
294 |
|
---|
295 | if ( $sta == "" )
|
---|
296 | $sta = "down";
|
---|
297 |
|
---|
298 | if ( $sta == "down" )
|
---|
299 | {
|
---|
300 | $que = "0";
|
---|
301 | $run = "0";
|
---|
302 | }
|
---|
303 |
|
---|
304 | $a[ 'cluster' ] = $clname;
|
---|
305 | $a[ 'queued' ] = $que;
|
---|
306 | $a[ 'running' ] = $run;
|
---|
307 | $a[ 'status' ] = $sta;
|
---|
308 |
|
---|
309 | $data[] = $a;
|
---|
310 |
|
---|
311 | if ( $clname == 'alamo' || $clname == 'jacinto' )
|
---|
312 | {
|
---|
313 | $a[ 'cluster' ] = $clname . "-local";
|
---|
314 | $data[] = $a;
|
---|
315 | }
|
---|
316 | }
|
---|
317 | }
|
---|
318 |
|
---|
319 | class XML_Array
|
---|
320 | {
|
---|
321 | var $_data = Array();
|
---|
322 | var $_name = Array();
|
---|
323 | var $_rep = Array();
|
---|
324 | var $_parser = 0;
|
---|
325 | var $_level = 0;
|
---|
326 | var $_index = 0;
|
---|
327 |
|
---|
328 | function XML_Array( &$data )
|
---|
329 | {
|
---|
330 | $this->_parser = xml_parser_create();
|
---|
331 |
|
---|
332 | xml_set_object ( $this->_parser, $this );
|
---|
333 | xml_parser_set_option ( $this->_parser, XML_OPTION_CASE_FOLDING, false );
|
---|
334 | xml_set_element_handler ( $this->_parser, "_startElement", "_endElement" );
|
---|
335 | xml_set_character_data_handler( $this->_parser, "_cdata" );
|
---|
336 |
|
---|
337 | $this->_data = array();
|
---|
338 | $this->_level = 0;
|
---|
339 |
|
---|
340 | if ( ! xml_parse( $this->_parser, $data, true ) )
|
---|
341 | return false;
|
---|
342 |
|
---|
343 | xml_parser_free( $this->_parser );
|
---|
344 | }
|
---|
345 |
|
---|
346 | function & ReturnArray()
|
---|
347 | {
|
---|
348 | return $this->_data[ 0 ];
|
---|
349 | }
|
---|
350 |
|
---|
351 | function _startElement( $parser, $name, $attrs )
|
---|
352 | {
|
---|
353 | if ( $name == "resourceHealth" )
|
---|
354 | {
|
---|
355 | ## $name .= $this->_index;
|
---|
356 | $this->_index++;
|
---|
357 | }
|
---|
358 |
|
---|
359 | if ( ! isset( $this->_rep[ $name ] ) ) $this->_rep[ $name ] = 0;
|
---|
360 |
|
---|
361 | $this->_addElement( $name, $this->_data[ $this->_level ], $attrs );
|
---|
362 | $this->_name[ $this->_level ] = $name;
|
---|
363 | $this->_level++;
|
---|
364 | }
|
---|
365 |
|
---|
366 | function _endElement( $parser, $name )
|
---|
367 | {
|
---|
368 | if ( isset( $this->_data[ $this->_level ] ) )
|
---|
369 | {
|
---|
370 | $this->_addElement( $this->_name[ $this->_level - 1 ],
|
---|
371 | $this->_data[ $this->_level - 1 ],
|
---|
372 | $this->_data[ $this->_level ]
|
---|
373 | );
|
---|
374 | }
|
---|
375 |
|
---|
376 | unset( $this->_data[ $this->_level ] );
|
---|
377 | $this->_level--;
|
---|
378 | $this->_rep[ $name ]++;
|
---|
379 | }
|
---|
380 |
|
---|
381 | function _cdata( $parser, $data )
|
---|
382 | {
|
---|
383 | if ( $this->_name[ $this->_level - 1 ] )
|
---|
384 | {
|
---|
385 | $this->_addElement( $this->_name[ $this->_level - 1 ],
|
---|
386 | $this->_data[ $this->_level - 1 ],
|
---|
387 | str_replace( array( ">", "<",""", "&" ),
|
---|
388 | array( ">" , "<" , '"' , "&" ),
|
---|
389 | $data
|
---|
390 | )
|
---|
391 | );
|
---|
392 | }
|
---|
393 | }
|
---|
394 |
|
---|
395 | function _addElement( &$name, &$start, $add = array() )
|
---|
396 | {
|
---|
397 | if ( ( sizeof( $add ) == 0 && is_array( $add ) ) || ! $add )
|
---|
398 | {
|
---|
399 | if ( ! isset( $start[ $name ] ) ) $start[ $name ] = '';
|
---|
400 | $add = '';
|
---|
401 | }
|
---|
402 |
|
---|
403 | $update = &$start[ $name ];
|
---|
404 |
|
---|
405 | if ( is_array( $add) &&
|
---|
406 | is_array( $update ) ) $update += $add;
|
---|
407 | elseif ( is_array( $update ) ) return;
|
---|
408 | elseif ( is_array( $add ) ) $update = $add;
|
---|
409 | elseif ( $add ) $update .= $add;
|
---|
410 | }
|
---|
411 | }
|
---|
412 | ?>
|
---|