[102] | 1 | <?php |
---|
[117] | 2 | // If php is compiled without globals |
---|
| 3 | // |
---|
[145] | 4 | //if ( !empty( $_GET ) ) { |
---|
| 5 | // extract( $_GET ); |
---|
| 6 | //} |
---|
[117] | 7 | |
---|
[103] | 8 | class HTTPVariables { |
---|
| 9 | |
---|
| 10 | var $clustername, $metricname; |
---|
[112] | 11 | var $restvars, $httpvars; |
---|
[103] | 12 | |
---|
[117] | 13 | function HTTPVariables( $httpvars, $getvars ) { |
---|
[103] | 14 | |
---|
[110] | 15 | $this->restvars = array(); |
---|
| 16 | |
---|
[117] | 17 | $this->clustername = $httpvars["c"] ? $httpvars["c"] : null; |
---|
| 18 | $this->metricname = $httpvars["m"] ? $httpvars["m"] : null; |
---|
[103] | 19 | |
---|
[117] | 20 | foreach( $httpvars as $httpvar => $httpval ) { |
---|
[110] | 21 | |
---|
| 22 | if( $httpval ) { |
---|
| 23 | $this->restvars[$httpvar] = $httpval; |
---|
| 24 | } |
---|
| 25 | } |
---|
[117] | 26 | |
---|
| 27 | foreach( $getvars as $getvar => $getval ) { |
---|
| 28 | |
---|
| 29 | if( $getval ) { |
---|
| 30 | $this->restvars[$getvar] = $getval; |
---|
| 31 | } |
---|
| 32 | } |
---|
[103] | 33 | } |
---|
| 34 | |
---|
| 35 | function getClusterName() { |
---|
| 36 | return $this->clustername; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | function getMetricName() { |
---|
| 40 | return $this->metricname; |
---|
| 41 | } |
---|
[110] | 42 | |
---|
| 43 | function getHttpVar( $var ) { |
---|
| 44 | if( isset( $this->restvars[$var] ) ) |
---|
[112] | 45 | return $this->restvars[$var]; |
---|
[110] | 46 | else |
---|
| 47 | return null; |
---|
| 48 | } |
---|
[103] | 49 | } |
---|
| 50 | |
---|
[112] | 51 | // Toga's conf |
---|
| 52 | // |
---|
| 53 | include_once "./conf.php"; |
---|
[195] | 54 | include_once "./version.php"; |
---|
[112] | 55 | |
---|
[117] | 56 | global $GANGLIA_PATH; |
---|
[206] | 57 | global $RRDTOOL; |
---|
| 58 | global $JOB_ARCHIVE_DIR; |
---|
[112] | 59 | |
---|
[117] | 60 | $my_dir = getcwd(); |
---|
[112] | 61 | |
---|
[117] | 62 | // Load Ganglia's PHP |
---|
| 63 | chdir( $GANGLIA_PATH ); |
---|
[112] | 64 | |
---|
[117] | 65 | include_once "./conf.php"; |
---|
| 66 | include_once "./functions.php"; |
---|
| 67 | include_once "./ganglia.php"; |
---|
[145] | 68 | include_once "./get_context.php"; |
---|
| 69 | unset( $start ); |
---|
| 70 | $context = 'cluster'; |
---|
[117] | 71 | include_once "./get_ganglia.php"; |
---|
| 72 | |
---|
| 73 | // Back to our PHP |
---|
| 74 | chdir( $my_dir ); |
---|
| 75 | |
---|
| 76 | global $SMALL_CLUSTERIMAGE_MAXWIDTH, $SMALL_CLUSTERIMAGE_NODEWIDTH, $DATA_SOURCE, $HTTP_GET_VARS, $_GET; |
---|
| 77 | $httpvars = new HTTPVariables( $HTTP_GET_VARS, $_GET ); |
---|
| 78 | |
---|
[112] | 79 | // Set cluster context so that Ganglia will |
---|
| 80 | // provide us with the correct metrics array |
---|
| 81 | // |
---|
[126] | 82 | global $context, $clustername, $reports; |
---|
[129] | 83 | |
---|
[117] | 84 | //$clustername = $httpvars->getClusterName(); |
---|
[112] | 85 | |
---|
[126] | 86 | global $default_metric; |
---|
| 87 | |
---|
[112] | 88 | // Ganglia's array of host metrics |
---|
| 89 | // |
---|
[126] | 90 | global $metrics, $hosts_up; |
---|
[112] | 91 | |
---|
[130] | 92 | class TarchDbase { |
---|
| 93 | |
---|
[138] | 94 | var $ip, $dbase, $conn; |
---|
[130] | 95 | |
---|
[204] | 96 | function TarchDbase( $ip = null, $dbase = 'jobarch' ) { |
---|
[130] | 97 | $this->ip = $ip; |
---|
| 98 | $this->dbase = $dbase; |
---|
[138] | 99 | $this->conn = null; |
---|
[130] | 100 | } |
---|
| 101 | |
---|
| 102 | function connect() { |
---|
| 103 | |
---|
| 104 | if( $this->ip == null and $this->dbase == 'toga' ) |
---|
[138] | 105 | $this->conn = pg_connect( "dbname=".$this->dbase ); |
---|
[130] | 106 | else |
---|
[204] | 107 | $this->conn = pg_connect( "host=".$this->ip." dbname=".$this->dbase ); |
---|
[130] | 108 | } |
---|
[138] | 109 | |
---|
| 110 | function searchDbase( $id = null, $queue = null, $user = null, $name = null, $start_from_time = null, $start_to_time = null, $end_from_time = null, $end_to_time = null ) { |
---|
| 111 | |
---|
| 112 | if( $id ) |
---|
[152] | 113 | $query = "SELECT job_id FROM jobs WHERE job_id = '$id' AND job_status = 'F'"; |
---|
[138] | 114 | else { |
---|
| 115 | $query_args = array(); |
---|
| 116 | |
---|
| 117 | if( $queue ) |
---|
| 118 | $query_args[] = "job_queue ='$queue'"; |
---|
| 119 | if( $user ) |
---|
| 120 | $query_args[] = "job_owner ='$user'"; |
---|
| 121 | if( $name ) |
---|
| 122 | $query_args[] = "job_name = '$name'"; |
---|
| 123 | if( $start_from_time ) |
---|
| 124 | $query_args[] = "job_start_timestamp >= $start_from_time"; |
---|
[142] | 125 | if( $start_to_time ) |
---|
[138] | 126 | $query_args[] = "job_start_timestamp <= $start_to_time"; |
---|
| 127 | if( $end_from_time ) |
---|
| 128 | $query_args[] = "job_stop_timestamp >= $end_from_time"; |
---|
| 129 | if( $end_to_time ) |
---|
| 130 | $query_args[] = "job_stop_timestamp <= $end_to_time"; |
---|
| 131 | |
---|
[152] | 132 | $query = "SELECT job_id FROM jobs WHERE job_status = 'F' AND "; |
---|
[138] | 133 | $extra_query_args = ''; |
---|
| 134 | |
---|
| 135 | foreach( $query_args as $myquery ) { |
---|
| 136 | |
---|
| 137 | if( $extra_query_args == '' ) |
---|
| 138 | $extra_query_args = $myquery; |
---|
| 139 | else |
---|
| 140 | $extra_query_args .= " AND ".$myquery; |
---|
| 141 | } |
---|
| 142 | $query .= $extra_query_args; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | $ids = $this->queryDbase( $query ); |
---|
[140] | 146 | |
---|
| 147 | $ret = array(); |
---|
| 148 | |
---|
| 149 | foreach( $ids as $crow) |
---|
| 150 | $ret[] = $crow[job_id]; |
---|
| 151 | |
---|
| 152 | return $ret; |
---|
[138] | 153 | } |
---|
| 154 | |
---|
| 155 | function getNodesForJob( $jobid ) { |
---|
| 156 | |
---|
| 157 | $result = $this->queryDbase( "SELECT node_id FROM job_nodes WHERE job_id = '$jobid'" ); |
---|
| 158 | |
---|
| 159 | $nodes = array(); |
---|
| 160 | |
---|
| 161 | foreach( $result as $result_row ) |
---|
| 162 | |
---|
[141] | 163 | $nodes[] = $this->getNodeArray( $result_row[node_id] ); |
---|
[138] | 164 | |
---|
| 165 | return $nodes; |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | function getJobsForNode( $nodeid ) { |
---|
| 169 | |
---|
| 170 | $result = $this->queryDbase( "SELECT job_id FROM job_nodes WHERE node_id = '$nodeid'" ); |
---|
| 171 | |
---|
| 172 | $jobs = array(); |
---|
| 173 | |
---|
| 174 | foreach( $result as $result_row ) |
---|
| 175 | |
---|
[141] | 176 | $jobs[] = $this->getJobArray( $result_row[job_id] ); |
---|
[138] | 177 | |
---|
| 178 | return $jobs; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | function getJobArray( $id ) { |
---|
| 182 | $result = $this->queryDbase( "SELECT * FROM jobs WHERE job_id = '$id'" ); |
---|
| 183 | |
---|
| 184 | return ( $this->makeArray( $result[0] ) ); |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | function getNodeArray( $id ) { |
---|
| 188 | |
---|
| 189 | $result = $this->queryDbase( "SELECT * FROM nodes WHERE node_id = '$id'" ); |
---|
| 190 | |
---|
| 191 | return ( $this->makeArray( $result[0] ) ); |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | function makeArray( $result_row ) { |
---|
| 195 | |
---|
| 196 | $myar = array(); |
---|
| 197 | |
---|
| 198 | foreach( $result_row as $mykey => $myval ) { |
---|
| 199 | |
---|
| 200 | $map_key = explode( '_', $mykey ); |
---|
| 201 | |
---|
[141] | 202 | $rmap_key = array_reverse( $map_key ); |
---|
| 203 | array_pop( $rmap_key ); |
---|
| 204 | $map_key = array_reverse( $rmap_key ); |
---|
[138] | 205 | |
---|
[141] | 206 | $newkey = implode( '_', $map_key ); |
---|
| 207 | |
---|
[138] | 208 | $myar[$newkey] = $result_row[$mykey]; |
---|
| 209 | } |
---|
| 210 | |
---|
| 211 | return $myar; |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | function queryDbase( $query ) { |
---|
| 215 | |
---|
| 216 | $result_rows = array(); |
---|
| 217 | |
---|
| 218 | if( !$this->conn ) |
---|
| 219 | $this->connect(); |
---|
| 220 | |
---|
[143] | 221 | //printf( "query = [%s]\n", $query ); |
---|
[138] | 222 | $result = pg_query( $this->conn, $query ); |
---|
| 223 | |
---|
| 224 | while ($row = pg_fetch_assoc($result)) |
---|
| 225 | $result_rows[] = $row; |
---|
| 226 | |
---|
| 227 | return $result_rows; |
---|
| 228 | } |
---|
[130] | 229 | } |
---|
| 230 | |
---|
[138] | 231 | class TarchRrdGraph { |
---|
[130] | 232 | var $rrdbin, $rrdvalues, $clustername, $hostname, $tempdir, $tarchdir, $metrics; |
---|
| 233 | |
---|
[206] | 234 | function TarchRrdGraph( $clustername, $hostname ) { |
---|
| 235 | |
---|
| 236 | global $RRDTOOL; |
---|
| 237 | global $JOB_ARCHIVE_DIR; |
---|
| 238 | |
---|
| 239 | $this->rrdbin = $RRDTOOL; |
---|
[130] | 240 | $this->rrdvalues = array(); |
---|
[206] | 241 | $this->tarchdir = $JOB_ARCHIVE_DIR; |
---|
[145] | 242 | $this->clustername = $clustername; |
---|
| 243 | $this->hostname = $hostname; |
---|
[130] | 244 | } |
---|
| 245 | |
---|
| 246 | function doCmd( $command ) { |
---|
| 247 | |
---|
| 248 | printf( "command = %s\n", $command ); |
---|
| 249 | $pipe = popen( $command . ' 2>&1', 'r' ); |
---|
| 250 | |
---|
| 251 | if (!$pipe) { |
---|
| 252 | print "pipe failed."; |
---|
| 253 | return ""; |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | $output = ''; |
---|
| 257 | while(!feof($pipe)) |
---|
| 258 | $output .= fread($pipe, 1024); |
---|
| 259 | |
---|
| 260 | pclose($pipe); |
---|
| 261 | |
---|
| 262 | $output = explode( "\n", $output ); |
---|
[135] | 263 | //print_r( $output ); |
---|
[130] | 264 | return $output; |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | function dirList( $dir ) { |
---|
| 268 | |
---|
| 269 | $dirlist = array(); |
---|
| 270 | |
---|
| 271 | if ($handle = opendir( $dir )) { |
---|
| 272 | while (false !== ($file = readdir($handle))) { |
---|
| 273 | if ($file != "." && $file != "..") { |
---|
| 274 | $dirlist[] = $file; |
---|
| 275 | } |
---|
| 276 | } |
---|
| 277 | closedir($handle); |
---|
| 278 | } |
---|
| 279 | |
---|
| 280 | return $dirlist; |
---|
| 281 | } |
---|
| 282 | |
---|
| 283 | function getTimePeriods( $start, $end ) { |
---|
| 284 | |
---|
[145] | 285 | //printf("start = %s end = %s\n", $start, $end ); |
---|
[130] | 286 | $times = array(); |
---|
| 287 | $dirlist = $this->dirList( $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname ); |
---|
[145] | 288 | |
---|
| 289 | //print_r( $dirlist ); |
---|
| 290 | |
---|
[130] | 291 | $first = 0; |
---|
| 292 | $last = 9999999999999; |
---|
| 293 | |
---|
| 294 | foreach( $dirlist as $dir ) { |
---|
| 295 | |
---|
| 296 | if( $dir > $first and $dir <= $start ) |
---|
| 297 | $first = $dir; |
---|
| 298 | if( $dir < $last and $dir >= $end ) |
---|
| 299 | $last = $dir; |
---|
| 300 | } |
---|
| 301 | |
---|
[145] | 302 | //printf( "first = %s last = %s\n", $first, $last ); |
---|
| 303 | |
---|
[130] | 304 | foreach( $dirlist as $dir ) { |
---|
| 305 | |
---|
[145] | 306 | //printf( "dir %s ", $dir ); |
---|
| 307 | |
---|
| 308 | if( $dir >= $first and $dir <= $last and !array_key_exists( $dir, $times ) ) { |
---|
| 309 | |
---|
[130] | 310 | $times[] = $dir; |
---|
[145] | 311 | //printf("newtime %s ", $dir ); |
---|
| 312 | |
---|
| 313 | } |
---|
[130] | 314 | } |
---|
| 315 | |
---|
[145] | 316 | //print_r( $times ); |
---|
| 317 | |
---|
[130] | 318 | sort( $times ); |
---|
| 319 | |
---|
[145] | 320 | //print_r( $times ); |
---|
| 321 | |
---|
[130] | 322 | return $times; |
---|
| 323 | } |
---|
| 324 | |
---|
[145] | 325 | function getRrdDirs( $start, $stop ) { |
---|
| 326 | |
---|
| 327 | //printf( "tarchdir = %s\n", $this->tarchdir ); |
---|
| 328 | $timess = $this->getTimePeriods( $start, $stop ); |
---|
| 329 | //print_r( $timess ); |
---|
| 330 | |
---|
| 331 | $rrd_files = array(); |
---|
| 332 | |
---|
| 333 | foreach( $timess as $time ) { |
---|
| 334 | |
---|
| 335 | $rrd_files[] = $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname. '/'.$time; |
---|
| 336 | } |
---|
| 337 | |
---|
| 338 | return $rrd_files; |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | function getRrdFiles( $metric, $start, $stop ) { |
---|
| 342 | |
---|
| 343 | $times = $this->getTimePeriods( $start, $stop ); |
---|
| 344 | |
---|
| 345 | $rrd_files = array(); |
---|
| 346 | |
---|
| 347 | foreach( $times as $time ) { |
---|
| 348 | |
---|
| 349 | $rrd_files[] = $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname . '/' .$time. '/' . $metric. '.rrd'; |
---|
| 350 | } |
---|
| 351 | |
---|
| 352 | return $rrd_files; |
---|
| 353 | } |
---|
| 354 | |
---|
[130] | 355 | function graph( $descr ) { |
---|
[141] | 356 | // monitor2:/data/toga/rrds/LISA Cluster/gb-r15n11.irc.sara.nl# rrdtool graph /var/www/ganglia/test1.png --start 1118683231 --end 1118750431 --width 300 --height 400 DEF:'1'='./1118647515/load_one.rrd':'sum':AVERAGE DEF:'2'='./1118690723/load_one.rrd':'sum':AVERAGE DEF:'3'='./1118733925/load_one.rrd':'sum':AVERAGE AREA:1#555555:"load_one" AREA:2#555555 AREA:3#555555 |
---|
| 357 | // 380x461 |
---|
| 358 | // monitor2:/data/toga/rrds/LISA Cluster/gb-r15n11.irc.sara.nl# |
---|
[130] | 359 | //$command = $this->rrdbin . " graph - --start $start --end $end ". |
---|
| 360 | "--width $width --height $height $upper_limit $lower_limit ". |
---|
| 361 | "--title '$title' $vertical_label $extras $background ". $series; |
---|
| 362 | |
---|
| 363 | //$graph = $this->doCmd( $command ); |
---|
| 364 | |
---|
| 365 | //return $graph; |
---|
[145] | 366 | return 0; |
---|
[130] | 367 | } |
---|
| 368 | } |
---|
| 369 | |
---|
[103] | 370 | class DataSource { |
---|
| 371 | |
---|
| 372 | var $data, $ip, $port; |
---|
| 373 | |
---|
| 374 | function DataSource( $ip = '127.0.0.1', $port = 8649 ) { |
---|
| 375 | $this->ip = $ip; |
---|
| 376 | $this->port = $port; |
---|
| 377 | } |
---|
| 378 | |
---|
| 379 | function getData() { |
---|
| 380 | |
---|
| 381 | $errstr; |
---|
| 382 | $errno = 0; |
---|
| 383 | $timeout = 3; |
---|
| 384 | |
---|
| 385 | $fp = fsockopen( $this->ip, $this->port, &$errno, &$errstr, $timeout ); |
---|
| 386 | |
---|
[106] | 387 | if( !$fp ) { |
---|
[103] | 388 | echo 'Unable to connect to '.$this->ip.':'.$this->port; // printf( 'Unable to connect to [%s:%.0f]', $this->ip, $this->port ); |
---|
| 389 | return; |
---|
| 390 | } |
---|
| 391 | |
---|
[177] | 392 | stream_set_timeout( $fp, 30 ); |
---|
| 393 | |
---|
[103] | 394 | while ( !feof( $fp ) ) { |
---|
| 395 | |
---|
| 396 | $data .= fread( $fp, 16384 ); |
---|
| 397 | } |
---|
| 398 | |
---|
| 399 | fclose( $fp ); |
---|
| 400 | |
---|
| 401 | return $data; |
---|
| 402 | } |
---|
| 403 | } |
---|
| 404 | |
---|
| 405 | class DataGatherer { |
---|
| 406 | |
---|
[105] | 407 | var $xmlhandler, $data, $httpvars; |
---|
[103] | 408 | |
---|
[163] | 409 | function DataGatherer( $cluster ) { |
---|
[103] | 410 | |
---|
[110] | 411 | global $DATA_SOURCE; |
---|
[163] | 412 | |
---|
| 413 | //printf("dg cluster = %s\n", $cluster ); |
---|
[110] | 414 | $ds_fields = explode( ':', $DATA_SOURCE ); |
---|
| 415 | $ds_ip = $ds_fields[0]; |
---|
| 416 | $ds_port = $ds_fields[1]; |
---|
| 417 | |
---|
| 418 | $this->source = new DataSource( $ds_ip, $ds_port ); |
---|
| 419 | |
---|
[103] | 420 | $this->parser = xml_parser_create(); |
---|
[112] | 421 | $this->httpvars = $httpvars; |
---|
[163] | 422 | $this->xmlhandler = new TorqueXMLHandler( $cluster ); |
---|
[103] | 423 | xml_set_element_handler( $this->parser, array( &$this->xmlhandler, 'startElement' ), array( &$this->xmlhandler, 'stopElement' ) ); |
---|
| 424 | } |
---|
| 425 | |
---|
| 426 | function parseXML() { |
---|
| 427 | |
---|
| 428 | $src = &$this->source; |
---|
| 429 | $this->data = $src->getData(); |
---|
| 430 | |
---|
[112] | 431 | if ( !xml_parse( &$this->parser, $this->data ) ) |
---|
[103] | 432 | $error = sprintf( 'XML error: %s at %d', xml_error_string( xml_get_error_code( &$this->parser ) ), xml_get_current_line_number( &$this->parser ) ); |
---|
| 433 | } |
---|
| 434 | |
---|
[105] | 435 | function printInfo() { |
---|
| 436 | $handler = $this->xmlhandler; |
---|
| 437 | $handler->printInfo(); |
---|
| 438 | } |
---|
| 439 | |
---|
[106] | 440 | function getNodes() { |
---|
| 441 | $handler = $this->xmlhandler; |
---|
| 442 | return $handler->getNodes(); |
---|
| 443 | } |
---|
| 444 | |
---|
[124] | 445 | function getCpus() { |
---|
| 446 | $handler = $this->xmlhandler; |
---|
| 447 | return $handler->getCpus(); |
---|
| 448 | } |
---|
| 449 | |
---|
[106] | 450 | function getJobs() { |
---|
| 451 | $handler = $this->xmlhandler; |
---|
| 452 | return $handler->getJobs(); |
---|
| 453 | } |
---|
| 454 | |
---|
[114] | 455 | function getHeartbeat() { |
---|
| 456 | $handler = $this->xmlhandler; |
---|
| 457 | return $handler->getHeartbeat(); |
---|
| 458 | } |
---|
[103] | 459 | } |
---|
| 460 | |
---|
| 461 | class TorqueXMLHandler { |
---|
| 462 | |
---|
[163] | 463 | var $clusters, $heartbeat, $nodes, $jobs, $clustername, $proc_cluster; |
---|
[104] | 464 | |
---|
[163] | 465 | function TorqueXMLHandler( $clustername ) { |
---|
[105] | 466 | $jobs = array(); |
---|
[104] | 467 | $clusters = array(); |
---|
[163] | 468 | $this->nodes = array(); |
---|
[104] | 469 | $heartbeat = array(); |
---|
[163] | 470 | $this->clustername = $clustername; |
---|
| 471 | //printf(" cluster set to %s \n", $this->clustername ); |
---|
[103] | 472 | } |
---|
| 473 | |
---|
[124] | 474 | function getCpus() { |
---|
| 475 | |
---|
| 476 | $cpus = 0; |
---|
| 477 | |
---|
| 478 | foreach( $this->jobs as $jobid=>$jobattrs ) { |
---|
| 479 | |
---|
| 480 | $nodes = count( $jobattrs[nodes] ); |
---|
| 481 | $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1; |
---|
| 482 | $mycpus = $nodes * $ppn; |
---|
| 483 | |
---|
| 484 | $cpus = $cpus + $mycpus; |
---|
| 485 | } |
---|
| 486 | } |
---|
| 487 | |
---|
[103] | 488 | function startElement( $parser, $name, $attrs ) { |
---|
| 489 | |
---|
[105] | 490 | $jobs = &$this->jobs; |
---|
[111] | 491 | $nodes = &$this->nodes; |
---|
[105] | 492 | |
---|
[103] | 493 | if ( $attrs[TN] ) { |
---|
| 494 | |
---|
| 495 | // Ignore dead metrics. Detect and mask failures. |
---|
| 496 | if ( $attrs[TN] > $attrs[TMAX] * 4 ) |
---|
| 497 | return; |
---|
| 498 | } |
---|
| 499 | |
---|
| 500 | $jobid = null; |
---|
| 501 | |
---|
[163] | 502 | //printf( '%s=%s', $attrs[NAME], $attrs[VAL] ); |
---|
[103] | 503 | |
---|
[163] | 504 | //printf( "clustername = %s proc_cluster = %s\n", $this->clustername, $this->proc_cluster ); |
---|
| 505 | |
---|
[104] | 506 | if( $name == 'CLUSTER' ) { |
---|
[103] | 507 | |
---|
[163] | 508 | $this->proc_cluster = $attrs[NAME]; |
---|
| 509 | //printf( "Found cluster %s\n", $attrs[NAME] ); |
---|
| 510 | //print_r( $attrs ); |
---|
[103] | 511 | |
---|
[163] | 512 | //if( !isset( $clusters[$clustername] ) ) |
---|
| 513 | // $clusters[$clustername] = array(); |
---|
[103] | 514 | |
---|
[163] | 515 | } else if( $name == 'HOST' and $this->proc_cluster == $this->clustername) { |
---|
[105] | 516 | |
---|
| 517 | $hostname = $attrs[NAME]; |
---|
| 518 | $location = $attrs[LOCATION]; |
---|
[163] | 519 | //printf( "Found node %s\n", $hostname ); |
---|
[105] | 520 | |
---|
[200] | 521 | if( !isset( $nodes[$hostname] ) ) |
---|
[163] | 522 | $nodes[$hostname] = new NodeImage( $hostname ); |
---|
[105] | 523 | |
---|
[163] | 524 | } else if( $name == 'METRIC' and strstr( $attrs[NAME], 'TOGA' ) and $this->proc_cluster == $this->clustername ) { |
---|
[103] | 525 | |
---|
[104] | 526 | if( strstr( $attrs[NAME], 'TOGA-HEARTBEAT' ) ) { |
---|
[103] | 527 | |
---|
[114] | 528 | $this->heartbeat['time'] = $attrs[VAL]; |
---|
[106] | 529 | //printf( "heartbeat %s\n", $heartbeat['time'] ); |
---|
[104] | 530 | |
---|
| 531 | } else if( strstr( $attrs[NAME], 'TOGA-JOB' ) ) { |
---|
| 532 | |
---|
| 533 | sscanf( $attrs[NAME], 'TOGA-JOB-%d', $jobid ); |
---|
| 534 | |
---|
[106] | 535 | //printf( "jobid %s\n", $jobid ); |
---|
[104] | 536 | |
---|
| 537 | if( !isset( $jobs[$jobid] ) ) |
---|
| 538 | $jobs[$jobid] = array(); |
---|
| 539 | |
---|
| 540 | $fields = explode( ' ', $attrs[VAL] ); |
---|
| 541 | |
---|
| 542 | foreach( $fields as $f ) { |
---|
| 543 | $togavalues = explode( '=', $f ); |
---|
| 544 | |
---|
| 545 | $toganame = $togavalues[0]; |
---|
| 546 | $togavalue = $togavalues[1]; |
---|
| 547 | |
---|
[106] | 548 | //printf( "\t%s\t= %s\n", $toganame, $togavalue ); |
---|
[104] | 549 | |
---|
[103] | 550 | if( $toganame == 'nodes' ) { |
---|
| 551 | |
---|
[135] | 552 | if( $jobs[$jobid][status] == 'R' ) { |
---|
| 553 | |
---|
| 554 | if( !isset( $jobs[$jobid][$toganame] ) ) |
---|
| 555 | $jobs[$jobid][$toganame] = array(); |
---|
[104] | 556 | |
---|
[135] | 557 | $mynodes = explode( ';', $togavalue ); |
---|
[103] | 558 | |
---|
[135] | 559 | foreach( $mynodes as $node ) |
---|
[103] | 560 | |
---|
[135] | 561 | $jobs[$jobid][$toganame][] = $node; |
---|
| 562 | |
---|
| 563 | } else if( $jobs[$jobid][status] == 'Q' ) { |
---|
| 564 | |
---|
| 565 | $jobs[$jobid][$toganame] = $togavalue; |
---|
| 566 | } |
---|
| 567 | |
---|
[104] | 568 | } else { |
---|
[103] | 569 | |
---|
[105] | 570 | $jobs[$jobid][$toganame] = $togavalue; |
---|
[104] | 571 | } |
---|
[103] | 572 | } |
---|
[111] | 573 | |
---|
| 574 | if( isset( $jobs[$jobid][domain] ) and isset( $jobs[$jobid][nodes] ) ) { |
---|
[112] | 575 | |
---|
| 576 | $nr_nodes = count( $jobs[$jobid][nodes] ); |
---|
| 577 | |
---|
[111] | 578 | foreach( $jobs[$jobid][nodes] as $node ) { |
---|
| 579 | |
---|
[200] | 580 | $domain = $jobs[$jobid][domain]; |
---|
| 581 | $domain_len = 0 - strlen( $domain ); |
---|
| 582 | |
---|
| 583 | if( substr( $node, $domain_len ) != $domain ) { |
---|
| 584 | $host = $node. '.'.$domain; |
---|
| 585 | } else { |
---|
| 586 | $host = $node; |
---|
| 587 | } |
---|
| 588 | |
---|
| 589 | //$host = $node.'.'.$jobs[$jobid][domain]; |
---|
[111] | 590 | |
---|
[200] | 591 | if( !isset( $nodes[$host] ) ) |
---|
[111] | 592 | $my_node = new NodeImage( $host ); |
---|
| 593 | else |
---|
[200] | 594 | $my_node = $nodes[$host]; |
---|
[111] | 595 | |
---|
| 596 | if( !$my_node->hasJob( $jobid ) ) |
---|
| 597 | |
---|
| 598 | if( isset( $jobs[$jobid][ppn] ) ) |
---|
| 599 | $my_node->addJob( $jobid, ((int) $jobs[$jobid][ppn]) ); |
---|
| 600 | else |
---|
| 601 | $my_node->addJob( $jobid, 1 ); |
---|
| 602 | |
---|
[163] | 603 | $nodes[$host] = $my_node; |
---|
[111] | 604 | } |
---|
| 605 | } |
---|
[103] | 606 | } |
---|
| 607 | } |
---|
[114] | 608 | $this->jobs = $jobs; |
---|
[163] | 609 | //print_r( $nodes ); |
---|
| 610 | $this->nodes = $nodes; |
---|
[200] | 611 | //print_r( $this->nodes ); |
---|
[103] | 612 | } |
---|
| 613 | |
---|
| 614 | function stopElement( $parser, $name ) { |
---|
| 615 | } |
---|
[105] | 616 | |
---|
| 617 | function printInfo() { |
---|
| 618 | |
---|
| 619 | $jobs = &$this->jobs; |
---|
| 620 | |
---|
| 621 | printf( "---jobs---\n" ); |
---|
| 622 | |
---|
| 623 | foreach( $jobs as $jobid => $job ) { |
---|
| 624 | |
---|
| 625 | printf( "job %s\n", $jobid ); |
---|
| 626 | |
---|
| 627 | if( isset( $job[nodes] ) ) { |
---|
| 628 | |
---|
| 629 | foreach( $job[nodes] as $node ) { |
---|
| 630 | |
---|
| 631 | $mynode = $this->nodes[$node]; |
---|
| 632 | $hostname = $mynode->getHostname(); |
---|
| 633 | $location = $mynode->getLocation(); |
---|
| 634 | |
---|
| 635 | printf( "\t- node %s\tlocation %s\n", $hostname, $location ); |
---|
| 636 | //$this->nodes[$hostname]->setLocation( "hier draait job ".$jobid ); |
---|
| 637 | } |
---|
| 638 | } |
---|
| 639 | } |
---|
| 640 | |
---|
| 641 | printf( "---nodes---\n" ); |
---|
| 642 | |
---|
| 643 | $nodes = &$this->nodes; |
---|
| 644 | |
---|
| 645 | foreach( $nodes as $node ) { |
---|
| 646 | |
---|
| 647 | $hostname = $node->getHostname(); |
---|
| 648 | $location = $node->getLocation(); |
---|
| 649 | $jobs = implode( ' ', $node->getJobs() ); |
---|
| 650 | printf( "* node %s\tlocation %s\tjobs %s\n", $hostname, $location, $jobs ); |
---|
| 651 | } |
---|
| 652 | } |
---|
[106] | 653 | |
---|
| 654 | function getNodes() { |
---|
[163] | 655 | //print_r( $this->nodes ); |
---|
[106] | 656 | return $this->nodes; |
---|
| 657 | } |
---|
| 658 | |
---|
| 659 | function getJobs() { |
---|
| 660 | return $this->jobs; |
---|
| 661 | } |
---|
[114] | 662 | |
---|
| 663 | function getHeartbeat() { |
---|
| 664 | return $this->heartbeat['time']; |
---|
| 665 | } |
---|
[103] | 666 | } |
---|
| 667 | |
---|
[107] | 668 | class NodeImage { |
---|
[102] | 669 | |
---|
[122] | 670 | var $image, $x, $y, $hostname, $jobs, $tasks, $showinfo; |
---|
[102] | 671 | |
---|
[111] | 672 | function NodeImage( $hostname ) { |
---|
[102] | 673 | |
---|
[111] | 674 | $this->jobs = array(); |
---|
| 675 | //$this->image = $image; |
---|
| 676 | //$this->x = $x; |
---|
| 677 | //$this->y = $y; |
---|
| 678 | $this->tasks = 0; |
---|
[110] | 679 | $this->hostname = $hostname; |
---|
[111] | 680 | $this->cpus = $this->determineCpus(); |
---|
[122] | 681 | $this->showinfo = 1; |
---|
[102] | 682 | } |
---|
| 683 | |
---|
[111] | 684 | function addJob( $jobid, $cpus ) { |
---|
| 685 | $jobs = &$this->jobs; |
---|
| 686 | |
---|
| 687 | $jobs[] = $jobid; |
---|
| 688 | $this->jobs = $jobs; |
---|
| 689 | |
---|
| 690 | $this->addTask( $cpus ); |
---|
| 691 | } |
---|
| 692 | |
---|
| 693 | function hasJob( $jobid ) { |
---|
| 694 | |
---|
| 695 | $jobfound = 0; |
---|
| 696 | |
---|
| 697 | if( count( $this->jobs ) > 0 ) |
---|
| 698 | foreach( $this->jobs as $job ) |
---|
| 699 | |
---|
| 700 | if( $job == $jobid ) |
---|
| 701 | $jobfound = 1; |
---|
| 702 | |
---|
| 703 | return $jobfound; |
---|
| 704 | } |
---|
| 705 | |
---|
| 706 | function addTask( $cpus ) { |
---|
| 707 | |
---|
| 708 | $this->tasks = $this->tasks + $cpus; |
---|
| 709 | } |
---|
| 710 | |
---|
| 711 | function setImage( $image ) { |
---|
| 712 | |
---|
| 713 | $this->image = $image; |
---|
| 714 | } |
---|
| 715 | |
---|
[106] | 716 | function setCoords( $x, $y ) { |
---|
[107] | 717 | |
---|
[106] | 718 | $this->x = $x; |
---|
| 719 | $this->y = $y; |
---|
| 720 | } |
---|
| 721 | |
---|
[102] | 722 | function colorHex( $color ) { |
---|
| 723 | |
---|
[109] | 724 | $my_color = imageColorAllocate( $this->image, hexdec( substr( $color, 0, 2 )), hexdec( substr( $color, 2, 2 )), hexdec( substr( $color, 4, 2 )) ); |
---|
[102] | 725 | |
---|
| 726 | return $my_color; |
---|
| 727 | } |
---|
| 728 | |
---|
[106] | 729 | function setLoad( $load ) { |
---|
| 730 | $this->load = $load; |
---|
| 731 | } |
---|
| 732 | |
---|
[108] | 733 | function setHostname( $hostname ) { |
---|
| 734 | $this->hostname = $hostname; |
---|
| 735 | } |
---|
| 736 | |
---|
[122] | 737 | function getHostname() { |
---|
| 738 | return $this->hostname; |
---|
| 739 | } |
---|
| 740 | |
---|
[114] | 741 | function getJobs() { |
---|
| 742 | return $this->jobs; |
---|
| 743 | } |
---|
| 744 | |
---|
[122] | 745 | function setShowinfo( $showinfo ) { |
---|
| 746 | $this->showinfo = $showinfo; |
---|
| 747 | } |
---|
| 748 | |
---|
[111] | 749 | function draw() { |
---|
[106] | 750 | |
---|
[122] | 751 | $this->drawSmall(); |
---|
| 752 | } |
---|
[110] | 753 | |
---|
[122] | 754 | function drawBig() { |
---|
[111] | 755 | |
---|
[122] | 756 | } |
---|
[106] | 757 | |
---|
[122] | 758 | function drawSmall() { |
---|
[106] | 759 | |
---|
[122] | 760 | global $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
| 761 | global $JOB_NODE_MARKING; |
---|
[102] | 762 | |
---|
[122] | 763 | $black_color = imageColorAllocate( $this->image, 0, 0, 0 ); |
---|
[110] | 764 | $size = $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
[107] | 765 | |
---|
[110] | 766 | imageFilledRectangle( $this->image, $this->x, $this->y, $this->x+($size), $this->y+($size), $black_color ); |
---|
| 767 | |
---|
[122] | 768 | if( $this->showinfo) { |
---|
| 769 | |
---|
| 770 | $this->load = $this->determineLoad(); |
---|
[111] | 771 | |
---|
[122] | 772 | if( !isset( $this->image ) or !isset( $this->x ) or !isset( $this->y ) ) { |
---|
| 773 | printf( "aborting\n" ); |
---|
| 774 | printf( "x %d y %d load %f\n", $this->x, $this->y, $load ); |
---|
| 775 | return; |
---|
| 776 | } |
---|
[111] | 777 | |
---|
| 778 | |
---|
[122] | 779 | // Convert Ganglias Hexadecimal load color to a Decimal one |
---|
| 780 | // |
---|
| 781 | $load = $this->determineLoad(); |
---|
| 782 | $usecolor = $this->colorHex( load_color($load) ); |
---|
| 783 | imageFilledRectangle( $this->image, $this->x+1, $this->y+1, $this->x+($size-1), $this->y+($size-1), $usecolor ); |
---|
| 784 | if( count( $this->jobs ) > 0 ) |
---|
| 785 | imageString( $this->image, 1, $this->x+(($size/2)-2), $this->y+(($size/2)-3), $JOB_NODE_MARKING, $black_color ); |
---|
[111] | 786 | |
---|
[122] | 787 | } else { |
---|
[111] | 788 | |
---|
[122] | 789 | // White |
---|
| 790 | $usecolor = imageColorAllocate( $this->image, 255, 255, 255 ); |
---|
| 791 | imageFilledRectangle( $this->image, $this->x+1, $this->y+1, $this->x+($size-1), $this->y+($size-1), $usecolor ); |
---|
| 792 | } |
---|
| 793 | |
---|
| 794 | |
---|
[102] | 795 | } |
---|
| 796 | |
---|
[111] | 797 | function determineCpus() { |
---|
[102] | 798 | |
---|
[108] | 799 | global $metrics; |
---|
| 800 | |
---|
| 801 | $cpus = $metrics[$this->hostname][cpu_num][VAL]; |
---|
[107] | 802 | if (!$cpus) $cpus=1; |
---|
[111] | 803 | |
---|
| 804 | return $cpus; |
---|
| 805 | } |
---|
| 806 | |
---|
| 807 | function determineLoad() { |
---|
| 808 | |
---|
| 809 | global $metrics; |
---|
| 810 | |
---|
[108] | 811 | $load_one = $metrics[$this->hostname][load_one][VAL]; |
---|
[111] | 812 | $load = ((float) $load_one)/$this->cpus; |
---|
[102] | 813 | |
---|
[111] | 814 | return $load; |
---|
[106] | 815 | } |
---|
| 816 | } |
---|
| 817 | |
---|
[107] | 818 | class ClusterImage { |
---|
[106] | 819 | |
---|
[111] | 820 | var $dataget, $image, $clustername; |
---|
[124] | 821 | var $filtername, $filters; |
---|
[106] | 822 | |
---|
[122] | 823 | function ClusterImage( $clustername ) { |
---|
[114] | 824 | |
---|
[163] | 825 | //printf( "image cluster = %s\n", $clustername ); |
---|
| 826 | $this->dataget = new DataGatherer( $clustername ); |
---|
[111] | 827 | $this->clustername = $clustername; |
---|
[124] | 828 | $this->filters = array(); |
---|
[106] | 829 | } |
---|
| 830 | |
---|
[122] | 831 | function setFilter( $filtername, $filtervalue ) { |
---|
| 832 | |
---|
[124] | 833 | //printf("filter %s = %s\n", $filtername, $filtervalue ); |
---|
[122] | 834 | //printf( "filter set to %s = %s\n", $filtername, $filtervalue ); |
---|
[124] | 835 | $this->filters[$filtername] = $filtervalue; |
---|
| 836 | //print_r($this->filters); |
---|
[122] | 837 | } |
---|
| 838 | |
---|
| 839 | function filterNodes( $jobs, $nodes ) { |
---|
| 840 | |
---|
| 841 | $filtered_nodes = array(); |
---|
| 842 | |
---|
| 843 | foreach( $nodes as $node ) { |
---|
| 844 | |
---|
| 845 | $hostname = $node->getHostname(); |
---|
| 846 | |
---|
[124] | 847 | $addhost = 1; |
---|
[122] | 848 | |
---|
[124] | 849 | if( count( $this->filters ) > 0 ) { |
---|
| 850 | |
---|
| 851 | $mynjobs = $node->getJobs(); |
---|
| 852 | |
---|
| 853 | if( count( $mynjobs ) > 0 ) { |
---|
| 854 | |
---|
| 855 | foreach( $mynjobs as $myjob ) { |
---|
| 856 | |
---|
| 857 | foreach( $this->filters as $filtername => $filtervalue ) { |
---|
| 858 | |
---|
| 859 | //printf("filter bla %s = %s\n", $filtername,$filtervalue ); |
---|
| 860 | |
---|
| 861 | if( $filtername!=null && $filtername!='' ) { |
---|
| 862 | |
---|
| 863 | if( $filtername == 'jobid' && !$node->hasJob( $filtervalue) ) { |
---|
| 864 | $addhost = 0; |
---|
| 865 | //printf("host %s has no job %s\n", $hostname, $filtervalue); |
---|
| 866 | } else if( $filtername != 'jobid' ) { |
---|
| 867 | //printf("myjob is %s\n", $myjob ); |
---|
| 868 | if( $jobs[$myjob][$filtername] != $filtervalue ) { |
---|
| 869 | //printf("host %s has no job with %s=%s\n", $hostname, $filtername, $filtervalue); |
---|
| 870 | $addhost = 0; |
---|
| 871 | } |
---|
| 872 | } |
---|
| 873 | } |
---|
| 874 | } |
---|
| 875 | } |
---|
| 876 | } else |
---|
| 877 | $addhost = 0; |
---|
| 878 | } |
---|
| 879 | |
---|
| 880 | if( $addhost ) |
---|
[122] | 881 | $filtered_nodes[] = $hostname; |
---|
| 882 | } |
---|
| 883 | |
---|
| 884 | return $filtered_nodes; |
---|
| 885 | } |
---|
| 886 | |
---|
[106] | 887 | function draw() { |
---|
[110] | 888 | |
---|
[124] | 889 | //printf("stopt met uitvoer"); |
---|
| 890 | //return; |
---|
| 891 | |
---|
[110] | 892 | global $SMALL_CLUSTERIMAGE_MAXWIDTH, $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
| 893 | |
---|
[107] | 894 | $mydatag = $this->dataget; |
---|
[106] | 895 | $mydatag->parseXML(); |
---|
| 896 | |
---|
[110] | 897 | //$max_width = 250; |
---|
| 898 | //$node_width = 11; |
---|
[106] | 899 | |
---|
[110] | 900 | $max_width = $SMALL_CLUSTERIMAGE_MAXWIDTH; |
---|
| 901 | $node_width = $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
| 902 | |
---|
| 903 | //printf( "cmaxw %s nmaxw %s", $SMALL_CLUSTERIMAGE_MAXWIDTH, $SMALL_CLUSTERIMAGE_NODEWIDTH ); |
---|
| 904 | |
---|
[106] | 905 | $nodes = $mydatag->getNodes(); |
---|
[111] | 906 | $nodes_hosts = array_keys( $nodes ); |
---|
[106] | 907 | |
---|
| 908 | $nodes_nr = count( $nodes ); |
---|
| 909 | |
---|
| 910 | $nodes_size = $nodes_nr*$node_width; |
---|
| 911 | $node_rows = 0; |
---|
| 912 | |
---|
| 913 | if( $nodes_size > $max_width ) { |
---|
[107] | 914 | $nodes_per_row = ( (int) ($max_width/$node_width) ); |
---|
[106] | 915 | } else { |
---|
| 916 | $nodes_per_row = $nodes_size; |
---|
| 917 | $node_rows = 1; |
---|
| 918 | } |
---|
| 919 | |
---|
| 920 | if( $nodes_per_row < $nodes_nr ) { |
---|
[107] | 921 | $node_rows = ( (int) ($nodes_nr/$nodes_per_row) ); |
---|
| 922 | $node_rest = fmod( $nodes_nr, $nodes_per_row ); |
---|
| 923 | //printf( "nodesnr %d noderest %f\n", $nodes_nr, $node_rest ); |
---|
| 924 | if( $node_rest > 0 ) { |
---|
[106] | 925 | $node_rows++; |
---|
[107] | 926 | //printf( "noderows %d\n", $node_rows ); |
---|
[106] | 927 | } |
---|
| 928 | } |
---|
| 929 | |
---|
[107] | 930 | //printf( "imagecreate: %dx%d", ($nodes_per_row*$node_width), ($node_rows*$node_width) ); |
---|
[171] | 931 | //$image = imageCreateTrueColor( ($nodes_per_row*$node_width)+1, ($node_rows*$node_width)+1 ); |
---|
| 932 | $image = imageCreateTrueColor( $max_width, ($node_rows*$node_width)+1 ); |
---|
[107] | 933 | $colorwhite = imageColorAllocate( $image, 255, 255, 255 ); |
---|
| 934 | imageFill( $image, 0, 0, $colorwhite ); |
---|
[106] | 935 | |
---|
[122] | 936 | $jobs = $mydatag->getJobs(); |
---|
| 937 | //printf("filtername = %s\n", $filtername ); |
---|
| 938 | $filtered_nodes = $this->filterNodes( $jobs, $nodes ); |
---|
| 939 | |
---|
| 940 | //print_r($filtered_nodes); |
---|
| 941 | |
---|
[106] | 942 | for( $n = 0; $n < $node_rows; $n++ ) { |
---|
| 943 | |
---|
| 944 | for( $m = 0; $m < $nodes_per_row; $m++ ) { |
---|
[107] | 945 | |
---|
| 946 | $x = ($m * $node_width); |
---|
| 947 | $y = ($n * $node_width); |
---|
| 948 | |
---|
[109] | 949 | $cur_node = ($n * $nodes_per_row) + ($m); |
---|
[111] | 950 | $host = $nodes_hosts[$cur_node]; |
---|
[107] | 951 | |
---|
[122] | 952 | |
---|
[111] | 953 | if( isset( $nodes[$host] ) ) { |
---|
| 954 | |
---|
| 955 | $nodes[$host]->setCoords( $x, $y ); |
---|
| 956 | $nodes[$host]->setImage( $image ); |
---|
[122] | 957 | |
---|
| 958 | if( !in_array( $host, $filtered_nodes ) ) |
---|
| 959 | $nodes[$host]->setShowinfo( 0 ); |
---|
| 960 | |
---|
[111] | 961 | $nodes[$host]->draw(); |
---|
| 962 | } |
---|
[106] | 963 | } |
---|
| 964 | } |
---|
| 965 | |
---|
[103] | 966 | header( 'Content-type: image/png' ); |
---|
[106] | 967 | imagePNG( $image ); |
---|
| 968 | imageDestroy( $image ); |
---|
[102] | 969 | } |
---|
| 970 | } |
---|
| 971 | |
---|
[106] | 972 | //$my_data = new DataGatherer(); |
---|
| 973 | //$my_data->parseXML(); |
---|
| 974 | //$my_data->printInfo(); |
---|
| 975 | |
---|
[112] | 976 | //$ic = new ClusterImage( "LISA Cluster" ); |
---|
| 977 | //$ic->draw(); |
---|
[102] | 978 | ?> |
---|