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