source: trunk/cluster_status.php@ 11

Last change on this file since 11 was 11, checked in by gegorbet, 9 years ago

mods to cluster_status to use ssh commands to obtain queued/running counts

File size: 11.1 KB
Line 
1<?php
2
3$us3bin = exec( "ls -d ~us3/bin" );
4include "$us3bin/listen-config.php";
5
6$xml = get_data();
7
8if ( $xml != "" )
9 parse( $xml );
10
11$data = array();
12
13local_status();
14
15foreach ( $data as $item )
16{
17 update( $item[ 'cluster' ], $item[ 'queued' ], $item[ 'status' ], $item[ 'running' ] );
18}
19
20exit();
21
22// Get the cluster status
23
24function 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
46function 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
104function 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
162function local_status()
163{
164 global $self;
165 global $data;
166
167// $clusters = array( "alamo", "jacinto" );
168 $clusters = array( "alamo", "lonestar", "stampede", "comet", "gordon", "juropa" );
169 //$clusters = array( "alamo", "lonestar", "stampede", "comet", "gordon", "jureca" );
170// $clusters = array( "alamo" );
171 foreach ( $clusters as $clname )
172 {
173 $a = Array();
174/**
175 if ( $clname == "alamo" )
176 {
177 $qstat = `ssh $clname '/usr/bin/qstat -B 2>&1|tail -1'`;
178
179 $sparts = preg_split( '/\s+/', $qstat );
180 $que = $sparts[ 3 ];
181 $run = $sparts[ 4 ];
182 $sta = $sparts[ 10 ];
183 }
184 else
185 {
186 $qstat = `ssh $clname '/opt/torque/bin/qstat -B 2>&1|tail -1'`;
187
188 $sparts = preg_split( '/\s+/', $qstat );
189 $que = $sparts[ 3 ];
190 $run = $sparts[ 4 ];
191 $sta = $sparts[ 9 ];
192 }
193
194//echo "$self: cln que run sta $clname $que $run $sta \n";
195
196 if ( $sta == "Active" )
197 {
198 $sta = "up";
199 }
200 else
201 {
202 $sta = "down";
203 $que = "0";
204 $run = "0";
205 }
206 *a*/
207 switch( $clname )
208 {
209 case 'alamo':
210 {
211 $host = "us3@alamo.uthscsa.edu";
212 $qstat = `ssh $host '/usr/bin/qstat -B 2>&1|tail -1'`;
213 $sparts = preg_split( '/\s+/', $qstat );
214 $que = $sparts[ 3 ];
215 $run = $sparts[ 4 ];
216 $sta = $sparts[ 10 ];
217 if ( $sta == "Active" )
218 $sta = "up";
219 else
220 $sta = "down";
221 break;
222 }
223 case 'stampede':
224 {
225 $host = "us3@stampede.tacc.utexas.edu";
226 $qstat = `ssh $host '/usr/local/bin/showq 2>&1|tail -1'`;
227 $sparts = preg_split( '/\s+/', $qstat );
228 $tot = $sparts[ 2 ];
229 $run = $sparts[ 5 ];
230 $que = $sparts[ 8 ];
231 $sta = "up";
232 if ( $tot == '' || $tot == '0' )
233 $sta = "down";
234 break;
235 }
236 case 'lonestar':
237 {
238 $host = "us3@lonestar.tacc.utexas.edu";
239 $qstat = `ssh $host 'showq 2>&1|tail -1'`;
240 $sparts = preg_split( '/\s+/', $qstat );
241 $tot = $sparts[ 2 ];
242 $run = '0';
243 $que = '0';
244 $sta = "up";
245 if ( $tot == '' || $tot == '0' )
246 {
247 $sta = "down";
248 }
249 else
250 {
251 $run = $sparts[ 5 ];
252 $que = $sparts[ 8 ];
253 }
254 break;
255 }
256 case 'comet':
257 {
258 $host = "us3@comet.sdsc.edu";
259 $qstat = `ssh $host '/usr/bin/sinfo -s -p compute -o "%a %F" 2>&1|tail -1'`;
260 $sparts = preg_split( '/\s+/', $qstat );
261 $sta = $sparts[ 0 ];
262 $knts = $sparts[ 1 ];
263 $sparts = preg_split( '/\//', $knts );
264 $run = $sparts[ 0 ];
265 $que = $sparts[ 1 ];
266 break;
267 }
268 case 'gordon':
269 {
270 $host = "us3@gordon.sdsc.edu";
271 $qstat = `ssh $host '/opt/torque/bin/qstat -B 2>&1|tail -1'`;
272 $sparts = preg_split( '/\s+/', $qstat );
273 $que = $sparts[ 3 ];
274 $run = $sparts[ 4 ];
275 $sta = $sparts[ 10 ];
276 if ( $sta == "Active" )
277 $sta = "up";
278 else
279 $sta = "down";
280 break;
281 }
282 case 'juropa':
283 {
284 $host = "zdv575@juropa.fz-juelich.de";
285 $qstat = `ssh $host '/usr/bin/qstat -B 2>&1|tail -1'`;
286 $sparts = preg_split( '/\s+/', $qstat );
287 $que = $sparts[ 3 ];
288 $run = $sparts[ 4 ];
289 $sta = $sparts[ 9 ];
290 if ( $sta == "Scheduling" )
291 $sta = "up";
292 else
293 $sta = "down";
294 break;
295 }
296 case 'jureca':
297 {
298 $host = "swus1@jureca.fz-juelich.de";
299 $qstat = `ssh $host '/usr/bin/sinfo -s -p batch -o "%a %F" 2>&1|tail -1'`;
300 $sparts = preg_split( '/\s+/', $qstat );
301 $sta = $sparts[ 0 ];
302 $knts = $sparts[ 1 ];
303 $sparts = preg_split( '/\//', $knts );
304 $run = $sparts[ 0 ];
305 $que = $sparts[ 1 ];
306 break;
307 }
308 }
309
310 if ( $sta == "down" )
311 {
312 $que = "0";
313 $run = "0";
314 }
315
316 $a[ 'cluster' ] = $clname;
317 $a[ 'queued' ] = $que;
318 $a[ 'running' ] = $run;
319 $a[ 'status' ] = $sta;
320
321 $data[] = $a;
322
323 if ( $clname == 'alamo' )
324 {
325 $a[ 'cluster' ] = $clname . "-local";
326 $data[] = $a;
327 }
328 }
329}
330
331class XML_Array
332{
333 var $_data = Array();
334 var $_name = Array();
335 var $_rep = Array();
336 var $_parser = 0;
337 var $_level = 0;
338 var $_index = 0;
339
340 function XML_Array( &$data )
341 {
342 $this->_parser = xml_parser_create();
343
344 xml_set_object ( $this->_parser, $this );
345 xml_parser_set_option ( $this->_parser, XML_OPTION_CASE_FOLDING, false );
346 xml_set_element_handler ( $this->_parser, "_startElement", "_endElement" );
347 xml_set_character_data_handler( $this->_parser, "_cdata" );
348
349 $this->_data = array();
350 $this->_level = 0;
351
352 if ( ! xml_parse( $this->_parser, $data, true ) )
353 return false;
354
355 xml_parser_free( $this->_parser );
356 }
357
358 function & ReturnArray()
359 {
360 return $this->_data[ 0 ];
361 }
362
363 function _startElement( $parser, $name, $attrs )
364 {
365 if ( $name == "resourceHealth" )
366 {
367## $name .= $this->_index;
368 $this->_index++;
369 }
370
371 if ( ! isset( $this->_rep[ $name ] ) ) $this->_rep[ $name ] = 0;
372
373 $this->_addElement( $name, $this->_data[ $this->_level ], $attrs );
374 $this->_name[ $this->_level ] = $name;
375 $this->_level++;
376 }
377
378 function _endElement( $parser, $name )
379 {
380 if ( isset( $this->_data[ $this->_level ] ) )
381 {
382 $this->_addElement( $this->_name[ $this->_level - 1 ],
383 $this->_data[ $this->_level - 1 ],
384 $this->_data[ $this->_level ]
385 );
386 }
387
388 unset( $this->_data[ $this->_level ] );
389 $this->_level--;
390 $this->_rep[ $name ]++;
391 }
392
393 function _cdata( $parser, $data )
394 {
395 if ( $this->_name[ $this->_level - 1 ] )
396 {
397 $this->_addElement( $this->_name[ $this->_level - 1 ],
398 $this->_data[ $this->_level - 1 ],
399 str_replace( array( "&gt;", "&lt;","&quot;", "&amp;" ),
400 array( ">" , "<" , '"' , "&" ),
401 $data
402 )
403 );
404 }
405 }
406
407 function _addElement( &$name, &$start, $add = array() )
408 {
409 if ( ( sizeof( $add ) == 0 && is_array( $add ) ) || ! $add )
410 {
411 if ( ! isset( $start[ $name ] ) ) $start[ $name ] = '';
412 $add = '';
413 }
414
415 $update = &$start[ $name ];
416
417 if ( is_array( $add) &&
418 is_array( $update ) ) $update += $add;
419 elseif ( is_array( $update ) ) return;
420 elseif ( is_array( $add ) ) $update = $add;
421 elseif ( $add ) $update .= $add;
422 }
423}
424?>
Note: See TracBrowser for help on using the repository browser.