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