source: trunk/cluster_status.php@ 14

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

fix to skip all processing where task/job devel/prod do not match

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