[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 |
|
---|
[17] | 167 | // $clusters = array( "alamo", "lonestar", "lonestar5", "stampede",
|
---|
| 168 | // "comet", "gordon" );
|
---|
| 169 | $clusters = array( "alamo", "lonestar", "lonestar5", "stampede",
|
---|
| 170 | "comet", "gordon", "jureca", "jacinto" );
|
---|
[6] | 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 | }
|
---|
[17] | 190 | case 'jacinto':
|
---|
| 191 | {
|
---|
| 192 | $host = "us3@jacinto.uthscsa.edu";
|
---|
| 193 | $qstat = `ssh $host '/opt/torque/bin/qstat -B 2>&1|tail -1'`;
|
---|
| 194 | $sparts = preg_split( '/\s+/', $qstat );
|
---|
| 195 | $que = $sparts[ 3 ];
|
---|
| 196 | $run = $sparts[ 4 ];
|
---|
| 197 | $sta = $sparts[ 9 ];
|
---|
| 198 | if ( $sta == "Active" )
|
---|
| 199 | $sta = "up";
|
---|
| 200 | else
|
---|
| 201 | $sta = "down";
|
---|
| 202 | break;
|
---|
| 203 | }
|
---|
[11] | 204 | case 'stampede':
|
---|
| 205 | {
|
---|
| 206 | $host = "us3@stampede.tacc.utexas.edu";
|
---|
| 207 | $qstat = `ssh $host '/usr/local/bin/showq 2>&1|tail -1'`;
|
---|
| 208 | $sparts = preg_split( '/\s+/', $qstat );
|
---|
| 209 | $tot = $sparts[ 2 ];
|
---|
| 210 | $run = $sparts[ 5 ];
|
---|
| 211 | $que = $sparts[ 8 ];
|
---|
| 212 | $sta = "up";
|
---|
| 213 | if ( $tot == '' || $tot == '0' )
|
---|
| 214 | $sta = "down";
|
---|
| 215 | break;
|
---|
| 216 | }
|
---|
| 217 | case 'lonestar':
|
---|
| 218 | {
|
---|
| 219 | $host = "us3@lonestar.tacc.utexas.edu";
|
---|
| 220 | $qstat = `ssh $host 'showq 2>&1|tail -1'`;
|
---|
| 221 | $sparts = preg_split( '/\s+/', $qstat );
|
---|
| 222 | $tot = $sparts[ 2 ];
|
---|
| 223 | $run = '0';
|
---|
| 224 | $que = '0';
|
---|
| 225 | $sta = "up";
|
---|
| 226 | if ( $tot == '' || $tot == '0' )
|
---|
| 227 | {
|
---|
| 228 | $sta = "down";
|
---|
| 229 | }
|
---|
| 230 | else
|
---|
| 231 | {
|
---|
| 232 | $run = $sparts[ 5 ];
|
---|
| 233 | $que = $sparts[ 8 ];
|
---|
| 234 | }
|
---|
| 235 | break;
|
---|
| 236 | }
|
---|
[17] | 237 | case 'lonestar5':
|
---|
| 238 | {
|
---|
| 239 | $host = "us3@ls5.tacc.utexas.edu";
|
---|
| 240 | $qstat = `ssh $host '/usr/local/bin/showq 2>&1|tail -1'`;
|
---|
| 241 | $sparts = preg_split( '/\s+/', $qstat );
|
---|
| 242 | $tot = $sparts[ 2 ];
|
---|
| 243 | $run = '0';
|
---|
| 244 | $que = '0';
|
---|
| 245 | $sta = "up";
|
---|
| 246 | if ( $tot == '' || $tot == '0' )
|
---|
| 247 | {
|
---|
| 248 | $sta = "down";
|
---|
| 249 | }
|
---|
| 250 | else
|
---|
| 251 | {
|
---|
| 252 | $run = $sparts[ 5 ];
|
---|
| 253 | $que = $sparts[ 8 ];
|
---|
| 254 | }
|
---|
| 255 | break;
|
---|
| 256 | }
|
---|
[11] | 257 | case 'comet':
|
---|
| 258 | {
|
---|
| 259 | $host = "us3@comet.sdsc.edu";
|
---|
[15] | 260 | $qstat = `ssh $host '/usr/bin/sinfo -s -p compute -o "%a %F" |tail -1'`;
|
---|
[11] | 261 | $sparts = preg_split( '/\s+/', $qstat );
|
---|
| 262 | $sta = $sparts[ 0 ];
|
---|
| 263 | $knts = $sparts[ 1 ];
|
---|
| 264 | $sparts = preg_split( '/\//', $knts );
|
---|
| 265 | $run = $sparts[ 0 ];
|
---|
| 266 | $que = $sparts[ 1 ];
|
---|
[15] | 267 | if ( $sta == "" )
|
---|
| 268 | $sta = "down";
|
---|
[11] | 269 | break;
|
---|
| 270 | }
|
---|
| 271 | case 'gordon':
|
---|
| 272 | {
|
---|
| 273 | $host = "us3@gordon.sdsc.edu";
|
---|
| 274 | $qstat = `ssh $host '/opt/torque/bin/qstat -B 2>&1|tail -1'`;
|
---|
| 275 | $sparts = preg_split( '/\s+/', $qstat );
|
---|
| 276 | $que = $sparts[ 3 ];
|
---|
| 277 | $run = $sparts[ 4 ];
|
---|
| 278 | $sta = $sparts[ 10 ];
|
---|
| 279 | if ( $sta == "Active" )
|
---|
| 280 | $sta = "up";
|
---|
| 281 | else
|
---|
| 282 | $sta = "down";
|
---|
| 283 | break;
|
---|
| 284 | }
|
---|
| 285 | case 'jureca':
|
---|
| 286 | {
|
---|
[15] | 287 | $host = "swus1@jureca.fz-juelich.de";
|
---|
[17] | 288 | $qstat = `ssh $host '~swus1/scripts/qstat-jureca 2>&1'`;
|
---|
[11] | 289 | $sparts = preg_split( '/\s+/', $qstat );
|
---|
| 290 | $sta = $sparts[ 0 ];
|
---|
[17] | 291 | $run = $sparts[ 1 ];
|
---|
| 292 | $que = $sparts[ 2 ];
|
---|
[11] | 293 | break;
|
---|
| 294 | }
|
---|
| 295 | }
|
---|
[6] | 296 |
|
---|
[17] | 297 | if ( $sta == "" )
|
---|
| 298 | $sta = "down";
|
---|
| 299 |
|
---|
[11] | 300 | if ( $sta == "down" )
|
---|
| 301 | {
|
---|
| 302 | $que = "0";
|
---|
| 303 | $run = "0";
|
---|
| 304 | }
|
---|
| 305 |
|
---|
[6] | 306 | $a[ 'cluster' ] = $clname;
|
---|
| 307 | $a[ 'queued' ] = $que;
|
---|
| 308 | $a[ 'running' ] = $run;
|
---|
| 309 | $a[ 'status' ] = $sta;
|
---|
| 310 |
|
---|
| 311 | $data[] = $a;
|
---|
[11] | 312 |
|
---|
[17] | 313 | if ( $clname == 'alamo' || $clname == 'jacinto' )
|
---|
[11] | 314 | {
|
---|
| 315 | $a[ 'cluster' ] = $clname . "-local";
|
---|
| 316 | $data[] = $a;
|
---|
| 317 | }
|
---|
[6] | 318 | }
|
---|
| 319 | }
|
---|
| 320 |
|
---|
[1] | 321 | class XML_Array
|
---|
| 322 | {
|
---|
| 323 | var $_data = Array();
|
---|
| 324 | var $_name = Array();
|
---|
| 325 | var $_rep = Array();
|
---|
| 326 | var $_parser = 0;
|
---|
| 327 | var $_level = 0;
|
---|
| 328 | var $_index = 0;
|
---|
| 329 |
|
---|
| 330 | function XML_Array( &$data )
|
---|
| 331 | {
|
---|
| 332 | $this->_parser = xml_parser_create();
|
---|
| 333 |
|
---|
| 334 | xml_set_object ( $this->_parser, $this );
|
---|
| 335 | xml_parser_set_option ( $this->_parser, XML_OPTION_CASE_FOLDING, false );
|
---|
| 336 | xml_set_element_handler ( $this->_parser, "_startElement", "_endElement" );
|
---|
| 337 | xml_set_character_data_handler( $this->_parser, "_cdata" );
|
---|
| 338 |
|
---|
| 339 | $this->_data = array();
|
---|
| 340 | $this->_level = 0;
|
---|
| 341 |
|
---|
| 342 | if ( ! xml_parse( $this->_parser, $data, true ) )
|
---|
| 343 | return false;
|
---|
| 344 |
|
---|
| 345 | xml_parser_free( $this->_parser );
|
---|
| 346 | }
|
---|
| 347 |
|
---|
| 348 | function & ReturnArray()
|
---|
| 349 | {
|
---|
| 350 | return $this->_data[ 0 ];
|
---|
| 351 | }
|
---|
| 352 |
|
---|
| 353 | function _startElement( $parser, $name, $attrs )
|
---|
| 354 | {
|
---|
| 355 | if ( $name == "resourceHealth" )
|
---|
| 356 | {
|
---|
[6] | 357 | ## $name .= $this->_index;
|
---|
[1] | 358 | $this->_index++;
|
---|
| 359 | }
|
---|
| 360 |
|
---|
| 361 | if ( ! isset( $this->_rep[ $name ] ) ) $this->_rep[ $name ] = 0;
|
---|
| 362 |
|
---|
| 363 | $this->_addElement( $name, $this->_data[ $this->_level ], $attrs );
|
---|
| 364 | $this->_name[ $this->_level ] = $name;
|
---|
| 365 | $this->_level++;
|
---|
| 366 | }
|
---|
| 367 |
|
---|
| 368 | function _endElement( $parser, $name )
|
---|
| 369 | {
|
---|
| 370 | if ( isset( $this->_data[ $this->_level ] ) )
|
---|
| 371 | {
|
---|
| 372 | $this->_addElement( $this->_name[ $this->_level - 1 ],
|
---|
| 373 | $this->_data[ $this->_level - 1 ],
|
---|
| 374 | $this->_data[ $this->_level ]
|
---|
| 375 | );
|
---|
| 376 | }
|
---|
| 377 |
|
---|
| 378 | unset( $this->_data[ $this->_level ] );
|
---|
| 379 | $this->_level--;
|
---|
| 380 | $this->_rep[ $name ]++;
|
---|
| 381 | }
|
---|
| 382 |
|
---|
| 383 | function _cdata( $parser, $data )
|
---|
| 384 | {
|
---|
| 385 | if ( $this->_name[ $this->_level - 1 ] )
|
---|
| 386 | {
|
---|
| 387 | $this->_addElement( $this->_name[ $this->_level - 1 ],
|
---|
| 388 | $this->_data[ $this->_level - 1 ],
|
---|
| 389 | str_replace( array( ">", "<",""", "&" ),
|
---|
| 390 | array( ">" , "<" , '"' , "&" ),
|
---|
| 391 | $data
|
---|
| 392 | )
|
---|
| 393 | );
|
---|
| 394 | }
|
---|
| 395 | }
|
---|
| 396 |
|
---|
| 397 | function _addElement( &$name, &$start, $add = array() )
|
---|
| 398 | {
|
---|
| 399 | if ( ( sizeof( $add ) == 0 && is_array( $add ) ) || ! $add )
|
---|
| 400 | {
|
---|
| 401 | if ( ! isset( $start[ $name ] ) ) $start[ $name ] = '';
|
---|
| 402 | $add = '';
|
---|
| 403 | }
|
---|
| 404 |
|
---|
| 405 | $update = &$start[ $name ];
|
---|
| 406 |
|
---|
| 407 | if ( is_array( $add) &&
|
---|
| 408 | is_array( $update ) ) $update += $add;
|
---|
| 409 | elseif ( is_array( $update ) ) return;
|
---|
| 410 | elseif ( is_array( $add ) ) $update = $add;
|
---|
| 411 | elseif ( $add ) $update .= $add;
|
---|
| 412 | }
|
---|
| 413 | }
|
---|
| 414 | ?>
|
---|