[1] | 1 | <?php
|
---|
| 2 |
|
---|
[6] | 3 | $us3bin = exec( "ls -d ~us3/bin" );
|
---|
| 4 | include "$us3bin/listen-config.php";
|
---|
[1] | 5 |
|
---|
| 6 | $xml = get_data();
|
---|
| 7 |
|
---|
[6] | 8 | if ( $xml != "" )
|
---|
| 9 | parse( $xml );
|
---|
[1] | 10 |
|
---|
| 11 | $data = array();
|
---|
| 12 |
|
---|
[6] | 13 | local_status();
|
---|
| 14 |
|
---|
[1] | 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 | {
|
---|
[6] | 37 | // write_log( "$self: Cluster Status not available" );
|
---|
[1] | 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 |
|
---|
[6] | 160 | // Get local cluster status
|
---|
| 161 |
|
---|
| 162 | function 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 | /**
|
---|
[6] | 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 | }
|
---|
[11] | 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 ];
|
---|
[12] | 290 | if ( $sta == "Active" )
|
---|
[11] | 291 | $sta = "up";
|
---|
[12] | 292 | else if ( $sta == "Scheduling" )
|
---|
| 293 | $sta = "up";
|
---|
[11] | 294 | else
|
---|
| 295 | $sta = "down";
|
---|
| 296 | break;
|
---|
| 297 | }
|
---|
| 298 | case 'jureca':
|
---|
| 299 | {
|
---|
| 300 | $host = "swus1@jureca.fz-juelich.de";
|
---|
| 301 | $qstat = `ssh $host '/usr/bin/sinfo -s -p batch -o "%a %F" 2>&1|tail -1'`;
|
---|
| 302 | $sparts = preg_split( '/\s+/', $qstat );
|
---|
| 303 | $sta = $sparts[ 0 ];
|
---|
| 304 | $knts = $sparts[ 1 ];
|
---|
| 305 | $sparts = preg_split( '/\//', $knts );
|
---|
| 306 | $run = $sparts[ 0 ];
|
---|
| 307 | $que = $sparts[ 1 ];
|
---|
| 308 | break;
|
---|
| 309 | }
|
---|
| 310 | }
|
---|
[6] | 311 |
|
---|
[11] | 312 | if ( $sta == "down" )
|
---|
| 313 | {
|
---|
| 314 | $que = "0";
|
---|
| 315 | $run = "0";
|
---|
| 316 | }
|
---|
| 317 |
|
---|
[6] | 318 | $a[ 'cluster' ] = $clname;
|
---|
| 319 | $a[ 'queued' ] = $que;
|
---|
| 320 | $a[ 'running' ] = $run;
|
---|
| 321 | $a[ 'status' ] = $sta;
|
---|
| 322 |
|
---|
| 323 | $data[] = $a;
|
---|
[11] | 324 |
|
---|
| 325 | if ( $clname == 'alamo' )
|
---|
| 326 | {
|
---|
| 327 | $a[ 'cluster' ] = $clname . "-local";
|
---|
| 328 | $data[] = $a;
|
---|
| 329 | }
|
---|
[6] | 330 | }
|
---|
| 331 | }
|
---|
| 332 |
|
---|
[1] | 333 | class XML_Array
|
---|
| 334 | {
|
---|
| 335 | var $_data = Array();
|
---|
| 336 | var $_name = Array();
|
---|
| 337 | var $_rep = Array();
|
---|
| 338 | var $_parser = 0;
|
---|
| 339 | var $_level = 0;
|
---|
| 340 | var $_index = 0;
|
---|
| 341 |
|
---|
| 342 | function XML_Array( &$data )
|
---|
| 343 | {
|
---|
| 344 | $this->_parser = xml_parser_create();
|
---|
| 345 |
|
---|
| 346 | xml_set_object ( $this->_parser, $this );
|
---|
| 347 | xml_parser_set_option ( $this->_parser, XML_OPTION_CASE_FOLDING, false );
|
---|
| 348 | xml_set_element_handler ( $this->_parser, "_startElement", "_endElement" );
|
---|
| 349 | xml_set_character_data_handler( $this->_parser, "_cdata" );
|
---|
| 350 |
|
---|
| 351 | $this->_data = array();
|
---|
| 352 | $this->_level = 0;
|
---|
| 353 |
|
---|
| 354 | if ( ! xml_parse( $this->_parser, $data, true ) )
|
---|
| 355 | return false;
|
---|
| 356 |
|
---|
| 357 | xml_parser_free( $this->_parser );
|
---|
| 358 | }
|
---|
| 359 |
|
---|
| 360 | function & ReturnArray()
|
---|
| 361 | {
|
---|
| 362 | return $this->_data[ 0 ];
|
---|
| 363 | }
|
---|
| 364 |
|
---|
| 365 | function _startElement( $parser, $name, $attrs )
|
---|
| 366 | {
|
---|
| 367 | if ( $name == "resourceHealth" )
|
---|
| 368 | {
|
---|
[6] | 369 | ## $name .= $this->_index;
|
---|
[1] | 370 | $this->_index++;
|
---|
| 371 | }
|
---|
| 372 |
|
---|
| 373 | if ( ! isset( $this->_rep[ $name ] ) ) $this->_rep[ $name ] = 0;
|
---|
| 374 |
|
---|
| 375 | $this->_addElement( $name, $this->_data[ $this->_level ], $attrs );
|
---|
| 376 | $this->_name[ $this->_level ] = $name;
|
---|
| 377 | $this->_level++;
|
---|
| 378 | }
|
---|
| 379 |
|
---|
| 380 | function _endElement( $parser, $name )
|
---|
| 381 | {
|
---|
| 382 | if ( isset( $this->_data[ $this->_level ] ) )
|
---|
| 383 | {
|
---|
| 384 | $this->_addElement( $this->_name[ $this->_level - 1 ],
|
---|
| 385 | $this->_data[ $this->_level - 1 ],
|
---|
| 386 | $this->_data[ $this->_level ]
|
---|
| 387 | );
|
---|
| 388 | }
|
---|
| 389 |
|
---|
| 390 | unset( $this->_data[ $this->_level ] );
|
---|
| 391 | $this->_level--;
|
---|
| 392 | $this->_rep[ $name ]++;
|
---|
| 393 | }
|
---|
| 394 |
|
---|
| 395 | function _cdata( $parser, $data )
|
---|
| 396 | {
|
---|
| 397 | if ( $this->_name[ $this->_level - 1 ] )
|
---|
| 398 | {
|
---|
| 399 | $this->_addElement( $this->_name[ $this->_level - 1 ],
|
---|
| 400 | $this->_data[ $this->_level - 1 ],
|
---|
| 401 | str_replace( array( ">", "<",""", "&" ),
|
---|
| 402 | array( ">" , "<" , '"' , "&" ),
|
---|
| 403 | $data
|
---|
| 404 | )
|
---|
| 405 | );
|
---|
| 406 | }
|
---|
| 407 | }
|
---|
| 408 |
|
---|
| 409 | function _addElement( &$name, &$start, $add = array() )
|
---|
| 410 | {
|
---|
| 411 | if ( ( sizeof( $add ) == 0 && is_array( $add ) ) || ! $add )
|
---|
| 412 | {
|
---|
| 413 | if ( ! isset( $start[ $name ] ) ) $start[ $name ] = '';
|
---|
| 414 | $add = '';
|
---|
| 415 | }
|
---|
| 416 |
|
---|
| 417 | $update = &$start[ $name ];
|
---|
| 418 |
|
---|
| 419 | if ( is_array( $add) &&
|
---|
| 420 | is_array( $update ) ) $update += $add;
|
---|
| 421 | elseif ( is_array( $update ) ) return;
|
---|
| 422 | elseif ( is_array( $add ) ) $update = $add;
|
---|
| 423 | elseif ( $add ) $update .= $add;
|
---|
| 424 | }
|
---|
| 425 | }
|
---|
| 426 | ?>
|
---|