[102] | 1 | <?php |
---|
[225] | 2 | /* |
---|
| 3 | * |
---|
| 4 | * This file is part of Jobmonarch |
---|
| 5 | * |
---|
| 6 | * Copyright (C) 2006 Ramon Bastiaans |
---|
| 7 | * |
---|
| 8 | * Jobmonarch is free software; you can redistribute it and/or modify |
---|
| 9 | * it under the terms of the GNU General Public License as published by |
---|
| 10 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 11 | * (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * Jobmonarch is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 21 | * |
---|
[231] | 22 | * SVN $Id: libtoga.php 514 2008-03-08 20:16:32Z bastiaans $ |
---|
| 23 | * |
---|
[225] | 24 | */ |
---|
| 25 | |
---|
| 26 | |
---|
[103] | 27 | class HTTPVariables { |
---|
| 28 | |
---|
| 29 | var $clustername, $metricname; |
---|
[112] | 30 | var $restvars, $httpvars; |
---|
[103] | 31 | |
---|
[117] | 32 | function HTTPVariables( $httpvars, $getvars ) { |
---|
[103] | 33 | |
---|
[110] | 34 | $this->restvars = array(); |
---|
| 35 | |
---|
[280] | 36 | $this->clustername = $httpvars["c"] ? $httpvars["c"] : $getvars["c"]; |
---|
| 37 | $this->metricname = $httpvars["m"] ? $httpvars["m"] : $getvars["m"]; |
---|
[103] | 38 | |
---|
[117] | 39 | foreach( $httpvars as $httpvar => $httpval ) { |
---|
[110] | 40 | |
---|
| 41 | if( $httpval ) { |
---|
| 42 | $this->restvars[$httpvar] = $httpval; |
---|
| 43 | } |
---|
| 44 | } |
---|
[117] | 45 | |
---|
| 46 | foreach( $getvars as $getvar => $getval ) { |
---|
| 47 | |
---|
| 48 | if( $getval ) { |
---|
| 49 | $this->restvars[$getvar] = $getval; |
---|
| 50 | } |
---|
| 51 | } |
---|
[103] | 52 | } |
---|
| 53 | |
---|
| 54 | function getClusterName() { |
---|
| 55 | return $this->clustername; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | function getMetricName() { |
---|
| 59 | return $this->metricname; |
---|
| 60 | } |
---|
[110] | 61 | |
---|
| 62 | function getHttpVar( $var ) { |
---|
| 63 | if( isset( $this->restvars[$var] ) ) |
---|
[112] | 64 | return $this->restvars[$var]; |
---|
[110] | 65 | else |
---|
| 66 | return null; |
---|
| 67 | } |
---|
[103] | 68 | } |
---|
| 69 | |
---|
[337] | 70 | $CLUSTER_CONFS = array(); |
---|
| 71 | |
---|
[112] | 72 | // Toga's conf |
---|
| 73 | // |
---|
| 74 | include_once "./conf.php"; |
---|
[195] | 75 | include_once "./version.php"; |
---|
[112] | 76 | |
---|
[117] | 77 | global $GANGLIA_PATH; |
---|
[206] | 78 | global $RRDTOOL; |
---|
| 79 | global $JOB_ARCHIVE_DIR; |
---|
[207] | 80 | global $JOB_ARCHIVE_DBASE; |
---|
[337] | 81 | //global $SORTBY_HOSTNAME; |
---|
| 82 | //global $SORT_ORDER; |
---|
[329] | 83 | global $skan_str; |
---|
| 84 | global $x_first, $y_first; |
---|
[337] | 85 | //global $SORT_XLABEL, $SORT_YLABEL; |
---|
| 86 | global $CLUSTER_CONFS; |
---|
[112] | 87 | |
---|
[117] | 88 | $my_dir = getcwd(); |
---|
[112] | 89 | |
---|
[117] | 90 | // Load Ganglia's PHP |
---|
| 91 | chdir( $GANGLIA_PATH ); |
---|
[112] | 92 | |
---|
[117] | 93 | include_once "./conf.php"; |
---|
| 94 | include_once "./functions.php"; |
---|
| 95 | include_once "./ganglia.php"; |
---|
[145] | 96 | include_once "./get_context.php"; |
---|
[409] | 97 | //unset( $start ); |
---|
[145] | 98 | $context = 'cluster'; |
---|
[117] | 99 | include_once "./get_ganglia.php"; |
---|
| 100 | |
---|
| 101 | // Back to our PHP |
---|
| 102 | chdir( $my_dir ); |
---|
| 103 | |
---|
| 104 | global $SMALL_CLUSTERIMAGE_MAXWIDTH, $SMALL_CLUSTERIMAGE_NODEWIDTH, $DATA_SOURCE, $HTTP_GET_VARS, $_GET; |
---|
| 105 | $httpvars = new HTTPVariables( $HTTP_GET_VARS, $_GET ); |
---|
| 106 | |
---|
[112] | 107 | // Set cluster context so that Ganglia will |
---|
| 108 | // provide us with the correct metrics array |
---|
| 109 | // |
---|
[126] | 110 | global $context, $clustername, $reports; |
---|
[129] | 111 | |
---|
[117] | 112 | //$clustername = $httpvars->getClusterName(); |
---|
[112] | 113 | |
---|
[126] | 114 | global $default_metric; |
---|
| 115 | |
---|
[112] | 116 | // Ganglia's array of host metrics |
---|
| 117 | // |
---|
[126] | 118 | global $metrics, $hosts_up; |
---|
[409] | 119 | global $range, $start; |
---|
[112] | 120 | |
---|
[246] | 121 | global $DATETIME_FORMAT; |
---|
| 122 | |
---|
| 123 | function makeDate( $time ) { |
---|
| 124 | global $DATETIME_FORMAT; |
---|
| 125 | return strftime( $DATETIME_FORMAT, $time ); |
---|
| 126 | } |
---|
| 127 | |
---|
[514] | 128 | |
---|
[130] | 129 | class TarchDbase { |
---|
| 130 | |
---|
[138] | 131 | var $ip, $dbase, $conn; |
---|
[130] | 132 | |
---|
[294] | 133 | function TarchDbase( $ip = null, $dbase = null ) { |
---|
[207] | 134 | |
---|
[454] | 135 | global $CLUSTER_CONFS, $clustername; |
---|
[207] | 136 | global $JOB_ARCHIVE_DBASE; |
---|
| 137 | |
---|
[454] | 138 | // Import cluster specific settings |
---|
| 139 | // |
---|
| 140 | foreach( $CLUSTER_CONFS as $confcluster => $conffile ) |
---|
| 141 | { |
---|
| 142 | if( strtolower( trim($this->clustername) ) == strtolower(trim($confcluster)) ) |
---|
| 143 | { |
---|
| 144 | include_once $conffile; |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | |
---|
[207] | 148 | $db_fields = explode( '/', $JOB_ARCHIVE_DBASE ); |
---|
| 149 | |
---|
[454] | 150 | $this->ip = $db_fields[0]; |
---|
| 151 | $this->dbase = $db_fields[1]; |
---|
| 152 | $this->conn = null; |
---|
[130] | 153 | } |
---|
| 154 | |
---|
| 155 | function connect() { |
---|
| 156 | |
---|
[294] | 157 | if( $this->ip == null ) |
---|
[138] | 158 | $this->conn = pg_connect( "dbname=".$this->dbase ); |
---|
[130] | 159 | else |
---|
[204] | 160 | $this->conn = pg_connect( "host=".$this->ip." dbname=".$this->dbase ); |
---|
[130] | 161 | } |
---|
[138] | 162 | |
---|
| 163 | 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 ) { |
---|
| 164 | |
---|
[248] | 165 | global $SEARCH_RESULT_LIMIT; |
---|
| 166 | |
---|
[251] | 167 | if( $id ) { |
---|
| 168 | $select_query = "SELECT job_id FROM jobs WHERE job_id = '$id' AND job_status = 'F'"; |
---|
| 169 | $this->resultcount = 1; |
---|
| 170 | } else { |
---|
[138] | 171 | $query_args = array(); |
---|
| 172 | |
---|
| 173 | if( $queue ) |
---|
| 174 | $query_args[] = "job_queue ='$queue'"; |
---|
| 175 | if( $user ) |
---|
| 176 | $query_args[] = "job_owner ='$user'"; |
---|
| 177 | if( $name ) |
---|
| 178 | $query_args[] = "job_name = '$name'"; |
---|
| 179 | if( $start_from_time ) |
---|
| 180 | $query_args[] = "job_start_timestamp >= $start_from_time"; |
---|
[142] | 181 | if( $start_to_time ) |
---|
[138] | 182 | $query_args[] = "job_start_timestamp <= $start_to_time"; |
---|
| 183 | if( $end_from_time ) |
---|
| 184 | $query_args[] = "job_stop_timestamp >= $end_from_time"; |
---|
| 185 | if( $end_to_time ) |
---|
| 186 | $query_args[] = "job_stop_timestamp <= $end_to_time"; |
---|
| 187 | |
---|
[248] | 188 | $query = "FROM jobs WHERE job_status = 'F' AND "; |
---|
[138] | 189 | $extra_query_args = ''; |
---|
| 190 | |
---|
| 191 | foreach( $query_args as $myquery ) { |
---|
| 192 | |
---|
| 193 | if( $extra_query_args == '' ) |
---|
| 194 | $extra_query_args = $myquery; |
---|
| 195 | else |
---|
| 196 | $extra_query_args .= " AND ".$myquery; |
---|
| 197 | } |
---|
| 198 | $query .= $extra_query_args; |
---|
| 199 | |
---|
[251] | 200 | $count_result_idname = "COUNT(job_id)"; |
---|
| 201 | $select_result_idname = "job_id"; |
---|
[140] | 202 | |
---|
[251] | 203 | $count_query = "SELECT " . $count_result_idname . " " . $query; |
---|
[248] | 204 | |
---|
[251] | 205 | $count_result = $this->queryDbase( $count_query ); |
---|
| 206 | $this->resultcount = (int) $count_result[0][count]; |
---|
[248] | 207 | |
---|
[454] | 208 | $select_query = "SELECT " . $select_result_idname . " " . $query . " ORDER BY job_id DESC LIMIT " . $SEARCH_RESULT_LIMIT; |
---|
[251] | 209 | } |
---|
| 210 | |
---|
[248] | 211 | $ids = $this->queryDbase( $select_query ); |
---|
| 212 | |
---|
[140] | 213 | $ret = array(); |
---|
| 214 | |
---|
| 215 | foreach( $ids as $crow) |
---|
| 216 | $ret[] = $crow[job_id]; |
---|
| 217 | |
---|
| 218 | return $ret; |
---|
[138] | 219 | } |
---|
| 220 | |
---|
| 221 | function getNodesForJob( $jobid ) { |
---|
| 222 | |
---|
| 223 | $result = $this->queryDbase( "SELECT node_id FROM job_nodes WHERE job_id = '$jobid'" ); |
---|
| 224 | |
---|
| 225 | $nodes = array(); |
---|
| 226 | |
---|
| 227 | foreach( $result as $result_row ) |
---|
| 228 | |
---|
[141] | 229 | $nodes[] = $this->getNodeArray( $result_row[node_id] ); |
---|
[138] | 230 | |
---|
| 231 | return $nodes; |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | function getJobsForNode( $nodeid ) { |
---|
| 235 | |
---|
| 236 | $result = $this->queryDbase( "SELECT job_id FROM job_nodes WHERE node_id = '$nodeid'" ); |
---|
| 237 | |
---|
| 238 | $jobs = array(); |
---|
| 239 | |
---|
| 240 | foreach( $result as $result_row ) |
---|
| 241 | |
---|
[141] | 242 | $jobs[] = $this->getJobArray( $result_row[job_id] ); |
---|
[138] | 243 | |
---|
| 244 | return $jobs; |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | function getJobArray( $id ) { |
---|
| 248 | $result = $this->queryDbase( "SELECT * FROM jobs WHERE job_id = '$id'" ); |
---|
| 249 | |
---|
| 250 | return ( $this->makeArray( $result[0] ) ); |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | function getNodeArray( $id ) { |
---|
| 254 | |
---|
| 255 | $result = $this->queryDbase( "SELECT * FROM nodes WHERE node_id = '$id'" ); |
---|
| 256 | |
---|
| 257 | return ( $this->makeArray( $result[0] ) ); |
---|
| 258 | } |
---|
| 259 | |
---|
| 260 | function makeArray( $result_row ) { |
---|
| 261 | |
---|
| 262 | $myar = array(); |
---|
| 263 | |
---|
| 264 | foreach( $result_row as $mykey => $myval ) { |
---|
| 265 | |
---|
| 266 | $map_key = explode( '_', $mykey ); |
---|
| 267 | |
---|
[141] | 268 | $rmap_key = array_reverse( $map_key ); |
---|
| 269 | array_pop( $rmap_key ); |
---|
| 270 | $map_key = array_reverse( $rmap_key ); |
---|
[138] | 271 | |
---|
[141] | 272 | $newkey = implode( '_', $map_key ); |
---|
| 273 | |
---|
[138] | 274 | $myar[$newkey] = $result_row[$mykey]; |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | return $myar; |
---|
| 278 | } |
---|
| 279 | |
---|
| 280 | function queryDbase( $query ) { |
---|
| 281 | |
---|
| 282 | $result_rows = array(); |
---|
| 283 | |
---|
| 284 | if( !$this->conn ) |
---|
| 285 | $this->connect(); |
---|
| 286 | |
---|
[143] | 287 | //printf( "query = [%s]\n", $query ); |
---|
[138] | 288 | $result = pg_query( $this->conn, $query ); |
---|
| 289 | |
---|
| 290 | while ($row = pg_fetch_assoc($result)) |
---|
| 291 | $result_rows[] = $row; |
---|
| 292 | |
---|
| 293 | return $result_rows; |
---|
| 294 | } |
---|
[130] | 295 | } |
---|
| 296 | |
---|
[138] | 297 | class TarchRrdGraph { |
---|
[130] | 298 | var $rrdbin, $rrdvalues, $clustername, $hostname, $tempdir, $tarchdir, $metrics; |
---|
| 299 | |
---|
[206] | 300 | function TarchRrdGraph( $clustername, $hostname ) { |
---|
| 301 | |
---|
| 302 | global $RRDTOOL; |
---|
| 303 | global $JOB_ARCHIVE_DIR; |
---|
| 304 | |
---|
| 305 | $this->rrdbin = $RRDTOOL; |
---|
[130] | 306 | $this->rrdvalues = array(); |
---|
[206] | 307 | $this->tarchdir = $JOB_ARCHIVE_DIR; |
---|
[145] | 308 | $this->clustername = $clustername; |
---|
| 309 | $this->hostname = $hostname; |
---|
[130] | 310 | } |
---|
| 311 | |
---|
| 312 | function doCmd( $command ) { |
---|
| 313 | |
---|
| 314 | printf( "command = %s\n", $command ); |
---|
| 315 | $pipe = popen( $command . ' 2>&1', 'r' ); |
---|
| 316 | |
---|
| 317 | if (!$pipe) { |
---|
| 318 | print "pipe failed."; |
---|
| 319 | return ""; |
---|
| 320 | } |
---|
| 321 | |
---|
| 322 | $output = ''; |
---|
| 323 | while(!feof($pipe)) |
---|
| 324 | $output .= fread($pipe, 1024); |
---|
| 325 | |
---|
| 326 | pclose($pipe); |
---|
| 327 | |
---|
| 328 | $output = explode( "\n", $output ); |
---|
[135] | 329 | //print_r( $output ); |
---|
[130] | 330 | return $output; |
---|
| 331 | } |
---|
| 332 | |
---|
| 333 | function dirList( $dir ) { |
---|
| 334 | |
---|
| 335 | $dirlist = array(); |
---|
| 336 | |
---|
| 337 | if ($handle = opendir( $dir )) { |
---|
| 338 | while (false !== ($file = readdir($handle))) { |
---|
| 339 | if ($file != "." && $file != "..") { |
---|
| 340 | $dirlist[] = $file; |
---|
| 341 | } |
---|
| 342 | } |
---|
| 343 | closedir($handle); |
---|
| 344 | } |
---|
| 345 | |
---|
| 346 | return $dirlist; |
---|
| 347 | } |
---|
| 348 | |
---|
| 349 | function getTimePeriods( $start, $end ) { |
---|
| 350 | |
---|
[145] | 351 | //printf("start = %s end = %s\n", $start, $end ); |
---|
[130] | 352 | $times = array(); |
---|
| 353 | $dirlist = $this->dirList( $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname ); |
---|
[145] | 354 | |
---|
| 355 | //print_r( $dirlist ); |
---|
| 356 | |
---|
[130] | 357 | $first = 0; |
---|
| 358 | $last = 9999999999999; |
---|
| 359 | |
---|
| 360 | foreach( $dirlist as $dir ) { |
---|
| 361 | |
---|
| 362 | if( $dir > $first and $dir <= $start ) |
---|
| 363 | $first = $dir; |
---|
| 364 | if( $dir < $last and $dir >= $end ) |
---|
| 365 | $last = $dir; |
---|
| 366 | } |
---|
| 367 | |
---|
[145] | 368 | //printf( "first = %s last = %s\n", $first, $last ); |
---|
| 369 | |
---|
[130] | 370 | foreach( $dirlist as $dir ) { |
---|
| 371 | |
---|
[145] | 372 | //printf( "dir %s ", $dir ); |
---|
| 373 | |
---|
| 374 | if( $dir >= $first and $dir <= $last and !array_key_exists( $dir, $times ) ) { |
---|
| 375 | |
---|
[130] | 376 | $times[] = $dir; |
---|
[145] | 377 | //printf("newtime %s ", $dir ); |
---|
| 378 | |
---|
| 379 | } |
---|
[130] | 380 | } |
---|
| 381 | |
---|
[145] | 382 | //print_r( $times ); |
---|
| 383 | |
---|
[130] | 384 | sort( $times ); |
---|
| 385 | |
---|
[145] | 386 | //print_r( $times ); |
---|
| 387 | |
---|
[130] | 388 | return $times; |
---|
| 389 | } |
---|
| 390 | |
---|
[145] | 391 | function getRrdDirs( $start, $stop ) { |
---|
| 392 | |
---|
| 393 | //printf( "tarchdir = %s\n", $this->tarchdir ); |
---|
| 394 | $timess = $this->getTimePeriods( $start, $stop ); |
---|
| 395 | //print_r( $timess ); |
---|
| 396 | |
---|
| 397 | $rrd_files = array(); |
---|
| 398 | |
---|
| 399 | foreach( $timess as $time ) { |
---|
| 400 | |
---|
| 401 | $rrd_files[] = $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname. '/'.$time; |
---|
| 402 | } |
---|
| 403 | |
---|
| 404 | return $rrd_files; |
---|
| 405 | } |
---|
| 406 | |
---|
| 407 | function getRrdFiles( $metric, $start, $stop ) { |
---|
| 408 | |
---|
| 409 | $times = $this->getTimePeriods( $start, $stop ); |
---|
| 410 | |
---|
| 411 | $rrd_files = array(); |
---|
| 412 | |
---|
| 413 | foreach( $times as $time ) { |
---|
| 414 | |
---|
| 415 | $rrd_files[] = $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname . '/' .$time. '/' . $metric. '.rrd'; |
---|
| 416 | } |
---|
| 417 | |
---|
| 418 | return $rrd_files; |
---|
| 419 | } |
---|
| 420 | |
---|
[130] | 421 | function graph( $descr ) { |
---|
[141] | 422 | // 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 |
---|
| 423 | // 380x461 |
---|
| 424 | // monitor2:/data/toga/rrds/LISA Cluster/gb-r15n11.irc.sara.nl# |
---|
[130] | 425 | //$command = $this->rrdbin . " graph - --start $start --end $end ". |
---|
| 426 | "--width $width --height $height $upper_limit $lower_limit ". |
---|
| 427 | "--title '$title' $vertical_label $extras $background ". $series; |
---|
| 428 | |
---|
| 429 | //$graph = $this->doCmd( $command ); |
---|
| 430 | |
---|
| 431 | //return $graph; |
---|
[145] | 432 | return 0; |
---|
[130] | 433 | } |
---|
| 434 | } |
---|
| 435 | |
---|
[103] | 436 | class DataSource { |
---|
| 437 | |
---|
| 438 | var $data, $ip, $port; |
---|
| 439 | |
---|
[326] | 440 | //function DataSource( $ip = '127.0.0.1', $port = 8649 ) { |
---|
| 441 | function DataSource() { |
---|
| 442 | |
---|
| 443 | global $DATA_SOURCE; |
---|
| 444 | |
---|
| 445 | $ds_fields = explode( ':', $DATA_SOURCE ); |
---|
| 446 | |
---|
| 447 | $ds_ip = $ds_fields[0]; |
---|
| 448 | $ds_port = $ds_fields[1]; |
---|
| 449 | |
---|
| 450 | $this->ip = $ds_ip; |
---|
| 451 | $this->port = $ds_port; |
---|
| 452 | |
---|
[103] | 453 | } |
---|
| 454 | |
---|
| 455 | function getData() { |
---|
| 456 | |
---|
| 457 | $errstr; |
---|
| 458 | $errno = 0; |
---|
| 459 | $timeout = 3; |
---|
| 460 | |
---|
[313] | 461 | $fp = fsockopen( $this->ip, $this->port, $errno, $errstr, $timeout ); |
---|
[103] | 462 | |
---|
[106] | 463 | if( !$fp ) { |
---|
[103] | 464 | echo 'Unable to connect to '.$this->ip.':'.$this->port; // printf( 'Unable to connect to [%s:%.0f]', $this->ip, $this->port ); |
---|
| 465 | return; |
---|
| 466 | } |
---|
| 467 | |
---|
[177] | 468 | stream_set_timeout( $fp, 30 ); |
---|
| 469 | |
---|
[103] | 470 | while ( !feof( $fp ) ) { |
---|
| 471 | |
---|
| 472 | $data .= fread( $fp, 16384 ); |
---|
| 473 | } |
---|
| 474 | |
---|
| 475 | fclose( $fp ); |
---|
| 476 | |
---|
| 477 | return $data; |
---|
| 478 | } |
---|
| 479 | } |
---|
| 480 | |
---|
| 481 | class DataGatherer { |
---|
| 482 | |
---|
[105] | 483 | var $xmlhandler, $data, $httpvars; |
---|
[103] | 484 | |
---|
[163] | 485 | function DataGatherer( $cluster ) { |
---|
[103] | 486 | |
---|
[326] | 487 | //global $DATA_SOURCE; |
---|
[163] | 488 | |
---|
| 489 | //printf("dg cluster = %s\n", $cluster ); |
---|
[326] | 490 | //$ds_fields = explode( ':', $DATA_SOURCE ); |
---|
| 491 | //$ds_ip = $ds_fields[0]; |
---|
| 492 | //$ds_port = $ds_fields[1]; |
---|
[110] | 493 | |
---|
[326] | 494 | //$this->source = new DataSource( $ds_ip, $ds_port ); |
---|
[110] | 495 | |
---|
[326] | 496 | $this->cluster = $cluster; |
---|
[112] | 497 | $this->httpvars = $httpvars; |
---|
[103] | 498 | } |
---|
| 499 | |
---|
[326] | 500 | function parseXML( $data ) { |
---|
[103] | 501 | |
---|
[326] | 502 | //$src = &$this->source; |
---|
| 503 | //$this->data = $src->getData(); |
---|
[103] | 504 | |
---|
[326] | 505 | $this->parser = xml_parser_create(); |
---|
| 506 | $this->xmlhandler = new TorqueXMLHandler( $this->cluster ); |
---|
| 507 | |
---|
| 508 | xml_set_element_handler( $this->parser, array( &$this->xmlhandler, 'startElement' ), array( &$this->xmlhandler, 'stopElement' ) ); |
---|
| 509 | //if ( !xml_parse( $this->parser, $this->data ) ) |
---|
| 510 | if ( !xml_parse( $this->parser, $data ) ) |
---|
[313] | 511 | $error = sprintf( 'XML error: %s at %d', xml_error_string( xml_get_error_code( $this->parser ) ), xml_get_current_line_number( $this->parser ) ); |
---|
[103] | 512 | } |
---|
| 513 | |
---|
[105] | 514 | function printInfo() { |
---|
| 515 | $handler = $this->xmlhandler; |
---|
| 516 | $handler->printInfo(); |
---|
| 517 | } |
---|
| 518 | |
---|
[463] | 519 | function getUsingFQDN() { |
---|
| 520 | $handler = $this->xmlhandler; |
---|
| 521 | return $handler->getUsingFQDN(); |
---|
| 522 | } |
---|
| 523 | |
---|
[106] | 524 | function getNodes() { |
---|
| 525 | $handler = $this->xmlhandler; |
---|
| 526 | return $handler->getNodes(); |
---|
| 527 | } |
---|
| 528 | |
---|
[303] | 529 | function getNode( $node ) { |
---|
| 530 | $handler = $this->xmlhandler; |
---|
| 531 | return $handler->getNode( $node ); |
---|
| 532 | } |
---|
| 533 | |
---|
[124] | 534 | function getCpus() { |
---|
| 535 | $handler = $this->xmlhandler; |
---|
| 536 | return $handler->getCpus(); |
---|
| 537 | } |
---|
| 538 | |
---|
[106] | 539 | function getJobs() { |
---|
| 540 | $handler = $this->xmlhandler; |
---|
| 541 | return $handler->getJobs(); |
---|
| 542 | } |
---|
| 543 | |
---|
[303] | 544 | function getJob( $job ) { |
---|
| 545 | $handler = $this->xmlhandler; |
---|
| 546 | return $handler->getJob( $job ); |
---|
| 547 | } |
---|
| 548 | |
---|
[114] | 549 | function getHeartbeat() { |
---|
| 550 | $handler = $this->xmlhandler; |
---|
| 551 | return $handler->getHeartbeat(); |
---|
| 552 | } |
---|
[298] | 553 | |
---|
| 554 | function isJobmonRunning() { |
---|
| 555 | $handler = $this->xmlhandler; |
---|
| 556 | return $handler->isJobmonRunning(); |
---|
| 557 | } |
---|
[103] | 558 | } |
---|
| 559 | |
---|
| 560 | class TorqueXMLHandler { |
---|
| 561 | |
---|
[163] | 562 | var $clusters, $heartbeat, $nodes, $jobs, $clustername, $proc_cluster; |
---|
[104] | 563 | |
---|
[163] | 564 | function TorqueXMLHandler( $clustername ) { |
---|
[459] | 565 | $jobs = array(); |
---|
| 566 | $clusters = array(); |
---|
| 567 | $this->nodes = array(); |
---|
| 568 | $heartbeat = array(); |
---|
[514] | 569 | $down_nodes = array(); |
---|
| 570 | $offline_nodes = array(); |
---|
[459] | 571 | $this->clustername = $clustername; |
---|
| 572 | $this->fqdn = 1; |
---|
[103] | 573 | } |
---|
| 574 | |
---|
[463] | 575 | function getUsingFQDN() { |
---|
| 576 | |
---|
| 577 | return $this->fqdn; |
---|
[514] | 578 | |
---|
| 579 | |
---|
[463] | 580 | } |
---|
| 581 | |
---|
[124] | 582 | function getCpus() { |
---|
| 583 | |
---|
| 584 | $cpus = 0; |
---|
| 585 | |
---|
[301] | 586 | if( isset( $this->jobs ) && count( $this->jobs ) > 0 ) { |
---|
[124] | 587 | |
---|
[301] | 588 | foreach( $this->jobs as $jobid=>$jobattrs ) { |
---|
[124] | 589 | |
---|
[301] | 590 | $nodes = count( $jobattrs[nodes] ); |
---|
| 591 | $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1; |
---|
| 592 | $mycpus = $nodes * $ppn; |
---|
| 593 | |
---|
| 594 | $cpus = $cpus + $mycpus; |
---|
| 595 | } |
---|
[124] | 596 | } |
---|
| 597 | } |
---|
| 598 | |
---|
[298] | 599 | function isJobmonRunning() { |
---|
| 600 | |
---|
| 601 | if (isset( $this->heartbeat['time'] )) |
---|
| 602 | return 1; |
---|
| 603 | else |
---|
| 604 | return 0; |
---|
| 605 | } |
---|
| 606 | |
---|
[514] | 607 | function makeHostname( $thostname, $tdomain=null ) |
---|
| 608 | { |
---|
| 609 | // Should hostname be FQDN or short w/o domain |
---|
| 610 | // |
---|
| 611 | $nodes = &$this->nodes; |
---|
| 612 | |
---|
| 613 | $fqdn = 1; |
---|
| 614 | |
---|
| 615 | //$tdomain = explode( '.', $thostname ); |
---|
| 616 | // TODO: domain van hostname afhalen: parameter weghalen |
---|
| 617 | |
---|
| 618 | if( $tdomain ) |
---|
| 619 | { |
---|
| 620 | $domain_len = 0 - strlen( $tdomain ); |
---|
| 621 | |
---|
| 622 | // Let's see if Ganglia use's FQDN or short hostnames |
---|
| 623 | // |
---|
| 624 | foreach( $nodes as $hostname => $nimage ) |
---|
| 625 | { |
---|
| 626 | |
---|
| 627 | if( substr( $hostname, $domain_len ) != $tdomain ) |
---|
| 628 | { |
---|
| 629 | $fqdn = 0; |
---|
| 630 | } |
---|
| 631 | } |
---|
| 632 | } |
---|
| 633 | else |
---|
| 634 | { |
---|
| 635 | $fqdn = 0; |
---|
| 636 | } |
---|
| 637 | |
---|
| 638 | if( $tdomain && $fqdn ) |
---|
| 639 | { |
---|
| 640 | if( substr( $thostname, $domain_len ) != $tdomain ) |
---|
| 641 | { |
---|
| 642 | $thostname = $thostname . '.'.$tdomain; |
---|
| 643 | } |
---|
| 644 | else |
---|
| 645 | { |
---|
| 646 | $thostname = $thostname; |
---|
| 647 | } |
---|
| 648 | } |
---|
| 649 | |
---|
| 650 | return $thostname; |
---|
| 651 | } |
---|
| 652 | |
---|
[103] | 653 | function startElement( $parser, $name, $attrs ) { |
---|
| 654 | |
---|
[262] | 655 | $jobs = $this->jobs; |
---|
| 656 | $nodes = $this->nodes; |
---|
[105] | 657 | |
---|
[103] | 658 | if ( $attrs[TN] ) { |
---|
| 659 | |
---|
| 660 | // Ignore dead metrics. Detect and mask failures. |
---|
| 661 | if ( $attrs[TN] > $attrs[TMAX] * 4 ) |
---|
| 662 | return; |
---|
| 663 | } |
---|
| 664 | |
---|
| 665 | $jobid = null; |
---|
| 666 | |
---|
[163] | 667 | //printf( '%s=%s', $attrs[NAME], $attrs[VAL] ); |
---|
[103] | 668 | |
---|
[163] | 669 | //printf( "clustername = %s proc_cluster = %s\n", $this->clustername, $this->proc_cluster ); |
---|
| 670 | |
---|
[104] | 671 | if( $name == 'CLUSTER' ) { |
---|
[103] | 672 | |
---|
[163] | 673 | $this->proc_cluster = $attrs[NAME]; |
---|
| 674 | //printf( "Found cluster %s\n", $attrs[NAME] ); |
---|
| 675 | //print_r( $attrs ); |
---|
[103] | 676 | |
---|
[163] | 677 | //if( !isset( $clusters[$clustername] ) ) |
---|
| 678 | // $clusters[$clustername] = array(); |
---|
[103] | 679 | |
---|
[163] | 680 | } else if( $name == 'HOST' and $this->proc_cluster == $this->clustername) { |
---|
[105] | 681 | |
---|
| 682 | $hostname = $attrs[NAME]; |
---|
[459] | 683 | |
---|
| 684 | |
---|
[105] | 685 | $location = $attrs[LOCATION]; |
---|
[163] | 686 | //printf( "Found node %s\n", $hostname ); |
---|
[105] | 687 | |
---|
[200] | 688 | if( !isset( $nodes[$hostname] ) ) |
---|
[326] | 689 | $nodes[$hostname] = new NodeImage( $this->proc_cluster, $hostname ); |
---|
[105] | 690 | |
---|
[219] | 691 | } else if( $name == 'METRIC' and strstr( $attrs[NAME], 'MONARCH' ) and $this->proc_cluster == $this->clustername ) { |
---|
[103] | 692 | |
---|
[514] | 693 | if( strstr( $attrs[NAME], 'MONARCH-HEARTBEAT' ) ) |
---|
| 694 | { |
---|
[114] | 695 | $this->heartbeat['time'] = $attrs[VAL]; |
---|
[514] | 696 | } |
---|
| 697 | else if( strstr( $attrs[NAME], 'MONARCH-DOWN' ) ) |
---|
| 698 | { |
---|
| 699 | $fields = explode( ' ', $attrs[VAL] ); |
---|
[104] | 700 | |
---|
[514] | 701 | $nodes_down = array(); |
---|
| 702 | $down_domain = null; |
---|
| 703 | |
---|
| 704 | foreach( $fields as $f ) |
---|
| 705 | { |
---|
| 706 | $togavalues = explode( '=', $f ); |
---|
| 707 | |
---|
| 708 | $toganame = $togavalues[0]; |
---|
| 709 | $togavalue = $togavalues[1]; |
---|
| 710 | |
---|
| 711 | if( $toganame == 'nodes' ) |
---|
| 712 | { |
---|
| 713 | $mynodes = explode( ';', $togavalue ); |
---|
| 714 | |
---|
| 715 | foreach( $mynodes as $node ) |
---|
| 716 | { |
---|
| 717 | $nodes_down[] = $node; |
---|
| 718 | } |
---|
| 719 | } |
---|
| 720 | else if( $toganame == 'domain' ) |
---|
| 721 | { |
---|
| 722 | $down_domain = $togavalue; |
---|
| 723 | } |
---|
| 724 | else if( $toganame == 'reported' ) |
---|
| 725 | { |
---|
| 726 | if( !isset( $this->down_nodes['heartbeat'] ) ) |
---|
| 727 | { |
---|
| 728 | $this->down_nodes[$togavalue] = array( $nodes_down, $down_domain ); |
---|
| 729 | } |
---|
| 730 | } |
---|
| 731 | } |
---|
| 732 | |
---|
| 733 | } else if( strstr( $attrs[NAME], 'MONARCH-OFFLINE' ) ) { |
---|
| 734 | |
---|
| 735 | $fields = explode( ' ', $attrs[VAL] ); |
---|
| 736 | |
---|
| 737 | $nodes_offline = array(); |
---|
| 738 | $offline_domain = null; |
---|
| 739 | |
---|
| 740 | foreach( $fields as $f ) |
---|
| 741 | { |
---|
| 742 | $togavalues = explode( '=', $f ); |
---|
| 743 | |
---|
| 744 | $toganame = $togavalues[0]; |
---|
| 745 | $togavalue = $togavalues[1]; |
---|
| 746 | |
---|
| 747 | if( $toganame == 'nodes' ) |
---|
| 748 | { |
---|
| 749 | $mynodes = explode( ';', $togavalue ); |
---|
| 750 | |
---|
| 751 | foreach( $mynodes as $node ) |
---|
| 752 | { |
---|
| 753 | $nodes_offline[] = $node; |
---|
| 754 | } |
---|
| 755 | } |
---|
| 756 | else if( $toganame == 'domain' ) |
---|
| 757 | { |
---|
| 758 | $offline_domain = $togavalue; |
---|
| 759 | } |
---|
| 760 | else if( $toganame == 'reported' ) |
---|
| 761 | { |
---|
| 762 | if( !isset( $this->offline_nodes['heartbeat'] ) ) |
---|
| 763 | { |
---|
| 764 | $this->offline_nodes[$togavalue] = array( $nodes_offline, $offline_domain ); |
---|
| 765 | } |
---|
| 766 | } |
---|
| 767 | } |
---|
| 768 | |
---|
[219] | 769 | } else if( strstr( $attrs[NAME], 'MONARCH-JOB' ) ) { |
---|
[104] | 770 | |
---|
[253] | 771 | sscanf( $attrs[NAME], 'MONARCH-JOB-%d-%d', $jobid, $monincr ); |
---|
[104] | 772 | |
---|
| 773 | if( !isset( $jobs[$jobid] ) ) |
---|
| 774 | $jobs[$jobid] = array(); |
---|
| 775 | |
---|
| 776 | $fields = explode( ' ', $attrs[VAL] ); |
---|
| 777 | |
---|
| 778 | foreach( $fields as $f ) { |
---|
| 779 | $togavalues = explode( '=', $f ); |
---|
| 780 | |
---|
| 781 | $toganame = $togavalues[0]; |
---|
| 782 | $togavalue = $togavalues[1]; |
---|
| 783 | |
---|
[103] | 784 | if( $toganame == 'nodes' ) { |
---|
| 785 | |
---|
[135] | 786 | if( $jobs[$jobid][status] == 'R' ) { |
---|
| 787 | |
---|
| 788 | if( !isset( $jobs[$jobid][$toganame] ) ) |
---|
| 789 | $jobs[$jobid][$toganame] = array(); |
---|
[104] | 790 | |
---|
[135] | 791 | $mynodes = explode( ';', $togavalue ); |
---|
[103] | 792 | |
---|
[300] | 793 | //print_r($mynodes); |
---|
| 794 | |
---|
[262] | 795 | foreach( $mynodes as $node ) { |
---|
[103] | 796 | |
---|
[262] | 797 | if( !in_array( $node, $jobs[$jobid][$toganame] ) ) { |
---|
[253] | 798 | $jobs[$jobid][$toganame][] = $node; |
---|
[262] | 799 | } |
---|
| 800 | } |
---|
[135] | 801 | |
---|
| 802 | } else if( $jobs[$jobid][status] == 'Q' ) { |
---|
| 803 | |
---|
| 804 | $jobs[$jobid][$toganame] = $togavalue; |
---|
| 805 | } |
---|
| 806 | |
---|
[104] | 807 | } else { |
---|
[103] | 808 | |
---|
[105] | 809 | $jobs[$jobid][$toganame] = $togavalue; |
---|
[104] | 810 | } |
---|
[103] | 811 | } |
---|
[111] | 812 | |
---|
[495] | 813 | if( isset( $jobs[$jobid][nodes] ) ) { |
---|
[112] | 814 | |
---|
| 815 | $nr_nodes = count( $jobs[$jobid][nodes] ); |
---|
[300] | 816 | |
---|
[492] | 817 | if( $jobs[$jobid][status] == 'R' ) |
---|
| 818 | { |
---|
[111] | 819 | |
---|
[495] | 820 | if( isset( $jobs[$jobid][domain] ) ) |
---|
[492] | 821 | { |
---|
| 822 | $domain = $jobs[$jobid][domain]; |
---|
| 823 | $domain_len = 0 - strlen( $domain ); |
---|
[461] | 824 | |
---|
[492] | 825 | // Let's see if Ganglia use's FQDN or short hostnames |
---|
| 826 | // |
---|
| 827 | foreach( $nodes as $hostname => $nimage ) |
---|
| 828 | { |
---|
[459] | 829 | |
---|
[492] | 830 | if( substr( $hostname, $domain_len ) != $domain ) |
---|
| 831 | { |
---|
| 832 | $this->fqdn = 0; |
---|
| 833 | } |
---|
[459] | 834 | } |
---|
| 835 | } |
---|
[496] | 836 | else |
---|
| 837 | { |
---|
| 838 | $this->fqdn = 0; |
---|
| 839 | } |
---|
[459] | 840 | |
---|
[495] | 841 | foreach( $jobs[$jobid][nodes] as $node ) |
---|
| 842 | { |
---|
[200] | 843 | |
---|
[461] | 844 | // Only add domain name to the hostname if Ganglia is doing that too |
---|
| 845 | // |
---|
[495] | 846 | if( $this->fqdn && isset( $jobs[$jobid][domain] ) ) |
---|
[459] | 847 | { |
---|
[492] | 848 | if( substr( $node, $domain_len ) != $domain ) |
---|
| 849 | { |
---|
[459] | 850 | $host = $node. '.'.$domain; |
---|
[492] | 851 | } else |
---|
| 852 | { |
---|
[459] | 853 | $host = $node; |
---|
| 854 | } |
---|
[300] | 855 | } |
---|
[459] | 856 | else |
---|
| 857 | { |
---|
| 858 | $host = $node; |
---|
| 859 | } |
---|
[300] | 860 | |
---|
| 861 | if( !isset( $nodes[$host] ) ) |
---|
[326] | 862 | $my_node = new NodeImage( $this->proc_cluster, $host ); |
---|
[300] | 863 | else |
---|
| 864 | $my_node = $nodes[$host]; |
---|
[111] | 865 | |
---|
[300] | 866 | if( !$my_node->hasJob( $jobid ) ) |
---|
[111] | 867 | |
---|
[300] | 868 | if( isset( $jobs[$jobid][ppn] ) ) |
---|
| 869 | $my_node->addJob( $jobid, ((int) $jobs[$jobid][ppn]) ); |
---|
| 870 | else |
---|
| 871 | $my_node->addJob( $jobid, 1 ); |
---|
[111] | 872 | |
---|
[300] | 873 | $nodes[$host] = $my_node; |
---|
| 874 | } |
---|
[111] | 875 | } |
---|
| 876 | } |
---|
[103] | 877 | } |
---|
| 878 | } |
---|
[114] | 879 | $this->jobs = $jobs; |
---|
[163] | 880 | //print_r( $nodes ); |
---|
| 881 | $this->nodes = $nodes; |
---|
[200] | 882 | //print_r( $this->nodes ); |
---|
[103] | 883 | } |
---|
| 884 | |
---|
| 885 | function stopElement( $parser, $name ) { |
---|
[514] | 886 | |
---|
| 887 | $nodes = $this->nodes; |
---|
| 888 | |
---|
| 889 | if( $name == "GANGLIA_XML" ) |
---|
| 890 | { |
---|
| 891 | foreach( $this->down_nodes as $reported => $dnodes ) |
---|
| 892 | { |
---|
| 893 | |
---|
| 894 | if( $reported == $this->heartbeat['time'] ) |
---|
| 895 | { |
---|
| 896 | $domain = $dnodes[1]; |
---|
| 897 | |
---|
| 898 | foreach( $dnodes[0] as $downhost ) |
---|
| 899 | { |
---|
| 900 | $downhost = $this->makeHostname( $downhost, $domain ); |
---|
| 901 | |
---|
| 902 | if( isset( $nodes[$downhost] ) ) |
---|
| 903 | { |
---|
| 904 | // OMG PHP4 is fking stupid! |
---|
| 905 | // $nodes[$downhost]->setDown( 1 ) won't work here.. |
---|
| 906 | // |
---|
| 907 | $mynode = $nodes[$downhost]; |
---|
| 908 | $mynode->setDown( 1 ); |
---|
| 909 | $nodes[$downhost] = $mynode; |
---|
| 910 | } |
---|
| 911 | } |
---|
| 912 | } |
---|
| 913 | } |
---|
| 914 | |
---|
| 915 | foreach( $this->offline_nodes as $reported => $onodes ) |
---|
| 916 | { |
---|
| 917 | if( $reported == $this->heartbeat['time'] ) |
---|
| 918 | { |
---|
| 919 | $domain = $onodes[1]; |
---|
| 920 | |
---|
| 921 | foreach( $onodes[0] as $offlinehost ) |
---|
| 922 | { |
---|
| 923 | $offlinehost = $this->makeHostname( $offlinehost, $domain ); |
---|
| 924 | |
---|
| 925 | if( isset( $nodes[$offlinehost] ) ) |
---|
| 926 | { |
---|
| 927 | // OMG PHP4 is fking stupid! |
---|
| 928 | // $nodes[$offlinehost]->setDown( 1 ) won't work here.. |
---|
| 929 | // |
---|
| 930 | $mynode = $nodes[$offlinehost]; |
---|
| 931 | $mynode->setOffline( 1 ); |
---|
| 932 | $nodes[$offlinehost] = $mynode; |
---|
| 933 | } |
---|
| 934 | } |
---|
| 935 | } |
---|
| 936 | } |
---|
| 937 | } |
---|
| 938 | |
---|
| 939 | $this->nodes = $nodes; |
---|
[103] | 940 | } |
---|
[105] | 941 | |
---|
| 942 | function printInfo() { |
---|
| 943 | |
---|
| 944 | $jobs = &$this->jobs; |
---|
| 945 | |
---|
| 946 | printf( "---jobs---\n" ); |
---|
| 947 | |
---|
| 948 | foreach( $jobs as $jobid => $job ) { |
---|
| 949 | |
---|
| 950 | printf( "job %s\n", $jobid ); |
---|
| 951 | |
---|
| 952 | if( isset( $job[nodes] ) ) { |
---|
| 953 | |
---|
| 954 | foreach( $job[nodes] as $node ) { |
---|
| 955 | |
---|
| 956 | $mynode = $this->nodes[$node]; |
---|
| 957 | $hostname = $mynode->getHostname(); |
---|
| 958 | $location = $mynode->getLocation(); |
---|
| 959 | |
---|
| 960 | printf( "\t- node %s\tlocation %s\n", $hostname, $location ); |
---|
| 961 | //$this->nodes[$hostname]->setLocation( "hier draait job ".$jobid ); |
---|
| 962 | } |
---|
| 963 | } |
---|
| 964 | } |
---|
| 965 | |
---|
| 966 | printf( "---nodes---\n" ); |
---|
| 967 | |
---|
| 968 | $nodes = &$this->nodes; |
---|
| 969 | |
---|
| 970 | foreach( $nodes as $node ) { |
---|
| 971 | |
---|
| 972 | $hostname = $node->getHostname(); |
---|
| 973 | $location = $node->getLocation(); |
---|
| 974 | $jobs = implode( ' ', $node->getJobs() ); |
---|
| 975 | printf( "* node %s\tlocation %s\tjobs %s\n", $hostname, $location, $jobs ); |
---|
| 976 | } |
---|
| 977 | } |
---|
[106] | 978 | |
---|
| 979 | function getNodes() { |
---|
[163] | 980 | //print_r( $this->nodes ); |
---|
[106] | 981 | return $this->nodes; |
---|
| 982 | } |
---|
| 983 | |
---|
[303] | 984 | function getNode( $node ) { |
---|
| 985 | |
---|
| 986 | $nodes = &$this->nodes; |
---|
| 987 | if( isset( $nodes[$node] ) ) |
---|
| 988 | return $nodes[$node]; |
---|
| 989 | else |
---|
| 990 | return NULL; |
---|
| 991 | } |
---|
| 992 | |
---|
[106] | 993 | function getJobs() { |
---|
| 994 | return $this->jobs; |
---|
| 995 | } |
---|
[114] | 996 | |
---|
[303] | 997 | function getJob( $job ) { |
---|
| 998 | |
---|
| 999 | $jobs = &$this->jobs; |
---|
| 1000 | if( isset( $jobs[$job] ) ) |
---|
| 1001 | return $jobs[$job]; |
---|
| 1002 | else |
---|
| 1003 | return NULL; |
---|
| 1004 | } |
---|
| 1005 | |
---|
[114] | 1006 | function getHeartbeat() { |
---|
| 1007 | return $this->heartbeat['time']; |
---|
| 1008 | } |
---|
[103] | 1009 | } |
---|
| 1010 | |
---|
[107] | 1011 | class NodeImage { |
---|
[102] | 1012 | |
---|
[122] | 1013 | var $image, $x, $y, $hostname, $jobs, $tasks, $showinfo; |
---|
[102] | 1014 | |
---|
[326] | 1015 | function NodeImage( $cluster, $hostname ) { |
---|
[102] | 1016 | |
---|
[305] | 1017 | global $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
| 1018 | |
---|
[111] | 1019 | $this->jobs = array(); |
---|
| 1020 | //$this->image = $image; |
---|
| 1021 | //$this->x = $x; |
---|
| 1022 | //$this->y = $y; |
---|
| 1023 | $this->tasks = 0; |
---|
[110] | 1024 | $this->hostname = $hostname; |
---|
[111] | 1025 | $this->cpus = $this->determineCpus(); |
---|
[326] | 1026 | $this->clustername = $cluster; |
---|
[122] | 1027 | $this->showinfo = 1; |
---|
[305] | 1028 | $this->size = $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
[514] | 1029 | $this->down = 0; |
---|
| 1030 | $this->offline = 0; |
---|
[102] | 1031 | } |
---|
| 1032 | |
---|
[111] | 1033 | function addJob( $jobid, $cpus ) { |
---|
| 1034 | $jobs = &$this->jobs; |
---|
| 1035 | |
---|
| 1036 | $jobs[] = $jobid; |
---|
| 1037 | $this->jobs = $jobs; |
---|
| 1038 | |
---|
| 1039 | $this->addTask( $cpus ); |
---|
| 1040 | } |
---|
| 1041 | |
---|
| 1042 | function hasJob( $jobid ) { |
---|
| 1043 | |
---|
| 1044 | $jobfound = 0; |
---|
| 1045 | |
---|
| 1046 | if( count( $this->jobs ) > 0 ) |
---|
| 1047 | foreach( $this->jobs as $job ) |
---|
| 1048 | |
---|
| 1049 | if( $job == $jobid ) |
---|
| 1050 | $jobfound = 1; |
---|
| 1051 | |
---|
| 1052 | return $jobfound; |
---|
| 1053 | } |
---|
| 1054 | |
---|
| 1055 | function addTask( $cpus ) { |
---|
| 1056 | |
---|
| 1057 | $this->tasks = $this->tasks + $cpus; |
---|
| 1058 | } |
---|
| 1059 | |
---|
[514] | 1060 | function setDown( $down ) { |
---|
| 1061 | |
---|
| 1062 | $this->down = $down; |
---|
| 1063 | } |
---|
| 1064 | |
---|
| 1065 | function isDown() { |
---|
| 1066 | |
---|
| 1067 | return $this->down; |
---|
| 1068 | } |
---|
| 1069 | function setOffline( $offline ) { |
---|
| 1070 | |
---|
| 1071 | $this->offline = $offline; |
---|
| 1072 | } |
---|
| 1073 | |
---|
| 1074 | function isOffline() { |
---|
| 1075 | |
---|
| 1076 | return $this->offline; |
---|
| 1077 | } |
---|
| 1078 | |
---|
[111] | 1079 | function setImage( $image ) { |
---|
| 1080 | |
---|
| 1081 | $this->image = $image; |
---|
| 1082 | } |
---|
| 1083 | |
---|
[106] | 1084 | function setCoords( $x, $y ) { |
---|
[107] | 1085 | |
---|
[106] | 1086 | $this->x = $x; |
---|
| 1087 | $this->y = $y; |
---|
| 1088 | } |
---|
| 1089 | |
---|
[326] | 1090 | function getImagemapArea() { |
---|
| 1091 | |
---|
| 1092 | $area_topleft = $this->x . "," . $this->y; |
---|
| 1093 | $area_bottomright = ($this->x + $this->size) . "," . ($this->y + $this->size); |
---|
| 1094 | $area_coords = $area_topleft . "," . $area_bottomright; |
---|
| 1095 | |
---|
| 1096 | $area_href = "./?c=" . $this->clustername . "&h=" . $this->hostname; |
---|
| 1097 | |
---|
[514] | 1098 | $area_tooltip = $this->hostname; |
---|
| 1099 | |
---|
| 1100 | if( $this->down) |
---|
| 1101 | { |
---|
| 1102 | $area_tooltip = $area_tooltip . ": DOWN"; |
---|
| 1103 | } |
---|
| 1104 | else if( $this->offline ) |
---|
| 1105 | { |
---|
| 1106 | $area_tooltip = $area_tooltip . ": OFFLINE"; |
---|
| 1107 | } |
---|
| 1108 | |
---|
| 1109 | $area_tooltip = $area_tooltip . ": " . implode( " ", $this->jobs ); |
---|
| 1110 | |
---|
[326] | 1111 | $tag_href = "HREF=\"" . $area_href . "\""; |
---|
| 1112 | $tag_coords = "COORDS=\"" . $area_coords . "\""; |
---|
| 1113 | $tag_tooltip1 = "ALT=\"" . $area_tooltip . "\""; |
---|
| 1114 | $tag_tooltip2 = "TITLE=\"" . $area_tooltip . "\""; |
---|
| 1115 | |
---|
| 1116 | return ("<AREA SHAPE=\"RECT\" " . $tag_coords . " " . $tag_href . " " . $tag_tooltip1 . " " . $tag_tooltip2 . ">"); |
---|
| 1117 | } |
---|
| 1118 | |
---|
[102] | 1119 | function colorHex( $color ) { |
---|
| 1120 | |
---|
[109] | 1121 | $my_color = imageColorAllocate( $this->image, hexdec( substr( $color, 0, 2 )), hexdec( substr( $color, 2, 2 )), hexdec( substr( $color, 4, 2 )) ); |
---|
[102] | 1122 | |
---|
| 1123 | return $my_color; |
---|
| 1124 | } |
---|
| 1125 | |
---|
[106] | 1126 | function setLoad( $load ) { |
---|
| 1127 | $this->load = $load; |
---|
| 1128 | } |
---|
| 1129 | |
---|
[108] | 1130 | function setHostname( $hostname ) { |
---|
| 1131 | $this->hostname = $hostname; |
---|
| 1132 | } |
---|
| 1133 | |
---|
[122] | 1134 | function getHostname() { |
---|
| 1135 | return $this->hostname; |
---|
| 1136 | } |
---|
| 1137 | |
---|
[114] | 1138 | function getJobs() { |
---|
| 1139 | return $this->jobs; |
---|
| 1140 | } |
---|
| 1141 | |
---|
[122] | 1142 | function setShowinfo( $showinfo ) { |
---|
| 1143 | $this->showinfo = $showinfo; |
---|
| 1144 | } |
---|
| 1145 | |
---|
[305] | 1146 | function drawSmall() { |
---|
[106] | 1147 | |
---|
[305] | 1148 | global $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
| 1149 | |
---|
| 1150 | $this->size = $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
| 1151 | |
---|
| 1152 | $this->draw(); |
---|
[122] | 1153 | } |
---|
[110] | 1154 | |
---|
[122] | 1155 | function drawBig() { |
---|
[111] | 1156 | |
---|
[305] | 1157 | global $BIG_CLUSTERIMAGE_NODEWIDTH; |
---|
| 1158 | |
---|
| 1159 | $this->size = $BIG_CLUSTERIMAGE_NODEWIDTH; |
---|
| 1160 | |
---|
| 1161 | $this->draw(); |
---|
[122] | 1162 | } |
---|
[106] | 1163 | |
---|
[305] | 1164 | function draw() { |
---|
[106] | 1165 | |
---|
[514] | 1166 | global $JOB_NODE_MARKING, $NODE_DOWN_MARKING, $NODE_OFFLINE_MARKING; |
---|
[102] | 1167 | |
---|
[122] | 1168 | $black_color = imageColorAllocate( $this->image, 0, 0, 0 ); |
---|
[305] | 1169 | $size = $this->size; |
---|
[107] | 1170 | |
---|
[110] | 1171 | imageFilledRectangle( $this->image, $this->x, $this->y, $this->x+($size), $this->y+($size), $black_color ); |
---|
| 1172 | |
---|
[122] | 1173 | if( $this->showinfo) { |
---|
| 1174 | |
---|
| 1175 | $this->load = $this->determineLoad(); |
---|
[111] | 1176 | |
---|
[122] | 1177 | if( !isset( $this->image ) or !isset( $this->x ) or !isset( $this->y ) ) { |
---|
| 1178 | printf( "aborting\n" ); |
---|
| 1179 | printf( "x %d y %d load %f\n", $this->x, $this->y, $load ); |
---|
| 1180 | return; |
---|
| 1181 | } |
---|
[111] | 1182 | |
---|
| 1183 | |
---|
[122] | 1184 | // Convert Ganglias Hexadecimal load color to a Decimal one |
---|
| 1185 | // |
---|
| 1186 | $load = $this->determineLoad(); |
---|
| 1187 | $usecolor = $this->colorHex( load_color($load) ); |
---|
| 1188 | imageFilledRectangle( $this->image, $this->x+1, $this->y+1, $this->x+($size-1), $this->y+($size-1), $usecolor ); |
---|
[514] | 1189 | if( $this->down ) |
---|
| 1190 | { |
---|
| 1191 | imageString( $this->image, 1, $this->x+(($size/2)-1), $this->y+(($size/2)-4), $NODE_DOWN_MARKING, $black_color ); |
---|
| 1192 | } |
---|
| 1193 | else if( $this->offline ) |
---|
| 1194 | { |
---|
| 1195 | imageString( $this->image, 1, $this->x+(($size/2)-1), $this->y+(($size/2)-4), $NODE_OFFLINE_MARKING, $black_color ); |
---|
| 1196 | } |
---|
| 1197 | else if( count( $this->jobs ) > 0 ) |
---|
| 1198 | { |
---|
[280] | 1199 | imageString( $this->image, 1, $this->x+(($size/2)-1), $this->y+(($size/2)-4), $JOB_NODE_MARKING, $black_color ); |
---|
[514] | 1200 | } |
---|
[111] | 1201 | |
---|
[122] | 1202 | } else { |
---|
[111] | 1203 | |
---|
[122] | 1204 | // White |
---|
| 1205 | $usecolor = imageColorAllocate( $this->image, 255, 255, 255 ); |
---|
| 1206 | imageFilledRectangle( $this->image, $this->x+1, $this->y+1, $this->x+($size-1), $this->y+($size-1), $usecolor ); |
---|
| 1207 | } |
---|
| 1208 | |
---|
| 1209 | |
---|
[102] | 1210 | } |
---|
| 1211 | |
---|
[111] | 1212 | function determineCpus() { |
---|
[102] | 1213 | |
---|
[108] | 1214 | global $metrics; |
---|
| 1215 | |
---|
| 1216 | $cpus = $metrics[$this->hostname][cpu_num][VAL]; |
---|
[107] | 1217 | if (!$cpus) $cpus=1; |
---|
[111] | 1218 | |
---|
| 1219 | return $cpus; |
---|
| 1220 | } |
---|
| 1221 | |
---|
| 1222 | function determineLoad() { |
---|
| 1223 | |
---|
| 1224 | global $metrics; |
---|
| 1225 | |
---|
[108] | 1226 | $load_one = $metrics[$this->hostname][load_one][VAL]; |
---|
[111] | 1227 | $load = ((float) $load_one)/$this->cpus; |
---|
[102] | 1228 | |
---|
[111] | 1229 | return $load; |
---|
[106] | 1230 | } |
---|
| 1231 | } |
---|
| 1232 | |
---|
[107] | 1233 | class ClusterImage { |
---|
[106] | 1234 | |
---|
[111] | 1235 | var $dataget, $image, $clustername; |
---|
[124] | 1236 | var $filtername, $filters; |
---|
[106] | 1237 | |
---|
[326] | 1238 | //function ClusterImage( $clustername ) { |
---|
| 1239 | function ClusterImage( $data, $clustername ) { |
---|
[114] | 1240 | |
---|
[326] | 1241 | //$this->dataget = $dataget; |
---|
[305] | 1242 | $this->dataget = new DataGatherer( $clustername ); |
---|
[326] | 1243 | $this->data = $data; |
---|
[305] | 1244 | $this->clustername = $clustername; |
---|
| 1245 | $this->filters = array(); |
---|
| 1246 | $this->size = 's'; |
---|
[326] | 1247 | $this->width = 0; |
---|
| 1248 | $this->height = 0; |
---|
| 1249 | $this->output = 1; |
---|
[106] | 1250 | } |
---|
| 1251 | |
---|
[326] | 1252 | function getWidth() { |
---|
| 1253 | return $this->width; |
---|
| 1254 | } |
---|
| 1255 | function getHeight() { |
---|
| 1256 | return $this->height; |
---|
| 1257 | } |
---|
| 1258 | |
---|
[305] | 1259 | function setSmall() { |
---|
| 1260 | $this->size = 's'; |
---|
| 1261 | } |
---|
| 1262 | |
---|
| 1263 | function setBig() { |
---|
| 1264 | $this->size = 'b'; |
---|
| 1265 | } |
---|
| 1266 | |
---|
[326] | 1267 | function setNoimage() { |
---|
| 1268 | $this->output = 0; |
---|
| 1269 | } |
---|
| 1270 | |
---|
[305] | 1271 | function isSmall() { |
---|
| 1272 | return ($this->size == 's'); |
---|
| 1273 | } |
---|
| 1274 | |
---|
| 1275 | function isBig() { |
---|
| 1276 | return ($this->size == 'b'); |
---|
| 1277 | } |
---|
| 1278 | |
---|
[122] | 1279 | function setFilter( $filtername, $filtervalue ) { |
---|
| 1280 | |
---|
[124] | 1281 | $this->filters[$filtername] = $filtervalue; |
---|
[122] | 1282 | } |
---|
| 1283 | |
---|
| 1284 | function filterNodes( $jobs, $nodes ) { |
---|
| 1285 | |
---|
| 1286 | $filtered_nodes = array(); |
---|
| 1287 | |
---|
| 1288 | foreach( $nodes as $node ) { |
---|
| 1289 | |
---|
| 1290 | $hostname = $node->getHostname(); |
---|
| 1291 | |
---|
[124] | 1292 | $addhost = 1; |
---|
[122] | 1293 | |
---|
[124] | 1294 | if( count( $this->filters ) > 0 ) { |
---|
| 1295 | |
---|
| 1296 | $mynjobs = $node->getJobs(); |
---|
| 1297 | |
---|
| 1298 | if( count( $mynjobs ) > 0 ) { |
---|
| 1299 | |
---|
| 1300 | foreach( $mynjobs as $myjob ) { |
---|
| 1301 | |
---|
| 1302 | foreach( $this->filters as $filtername => $filtervalue ) { |
---|
| 1303 | |
---|
| 1304 | if( $filtername!=null && $filtername!='' ) { |
---|
| 1305 | |
---|
| 1306 | if( $filtername == 'jobid' && !$node->hasJob( $filtervalue) ) { |
---|
| 1307 | $addhost = 0; |
---|
| 1308 | } else if( $filtername != 'jobid' ) { |
---|
| 1309 | if( $jobs[$myjob][$filtername] != $filtervalue ) { |
---|
| 1310 | $addhost = 0; |
---|
| 1311 | } |
---|
| 1312 | } |
---|
| 1313 | } |
---|
| 1314 | } |
---|
| 1315 | } |
---|
| 1316 | } else |
---|
| 1317 | $addhost = 0; |
---|
| 1318 | } |
---|
| 1319 | |
---|
| 1320 | if( $addhost ) |
---|
[122] | 1321 | $filtered_nodes[] = $hostname; |
---|
| 1322 | } |
---|
| 1323 | |
---|
| 1324 | return $filtered_nodes; |
---|
| 1325 | } |
---|
| 1326 | |
---|
[106] | 1327 | function draw() { |
---|
[110] | 1328 | |
---|
| 1329 | global $SMALL_CLUSTERIMAGE_MAXWIDTH, $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
[305] | 1330 | global $BIG_CLUSTERIMAGE_MAXWIDTH, $BIG_CLUSTERIMAGE_NODEWIDTH; |
---|
[339] | 1331 | global $CLUSTER_CONFS, $confcluster; |
---|
[329] | 1332 | |
---|
[339] | 1333 | global $SORTBY_HOSTNAME, $SORT_ORDER, $skan_str; |
---|
[329] | 1334 | global $x_first, $y_first; |
---|
[331] | 1335 | |
---|
[337] | 1336 | foreach( $CLUSTER_CONFS as $confcluster => $conffile ) |
---|
| 1337 | { |
---|
[339] | 1338 | if( strtolower( trim($this->clustername) ) == strtolower(trim($confcluster)) ) |
---|
[337] | 1339 | { |
---|
| 1340 | include_once $conffile; |
---|
| 1341 | } |
---|
| 1342 | } |
---|
| 1343 | |
---|
[339] | 1344 | //global $SORTBY_HOSTNAME, $SORT_ORDER; |
---|
| 1345 | //global $SORT_XLABEL, $SORT_YLABEL; |
---|
[110] | 1346 | |
---|
[339] | 1347 | //printf( "SORTBY_HOSTNAME %s SORT_YLABEL %s\n", $SORTBY_HOSTNAME, $SORT_YLABEL ); |
---|
| 1348 | |
---|
[107] | 1349 | $mydatag = $this->dataget; |
---|
[326] | 1350 | $mydatag->parseXML( $this->data ); |
---|
[106] | 1351 | |
---|
[305] | 1352 | if( $this->isSmall() ) { |
---|
| 1353 | $max_width = $SMALL_CLUSTERIMAGE_MAXWIDTH; |
---|
| 1354 | $node_width = $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
| 1355 | } else if( $this->isBig() ) { |
---|
| 1356 | $max_width = $BIG_CLUSTERIMAGE_MAXWIDTH; |
---|
| 1357 | $node_width = $BIG_CLUSTERIMAGE_NODEWIDTH; |
---|
| 1358 | } |
---|
[106] | 1359 | |
---|
| 1360 | $nodes = $mydatag->getNodes(); |
---|
[111] | 1361 | $nodes_hosts = array_keys( $nodes ); |
---|
[106] | 1362 | |
---|
| 1363 | $nodes_nr = count( $nodes ); |
---|
| 1364 | |
---|
| 1365 | $nodes_size = $nodes_nr*$node_width; |
---|
| 1366 | $node_rows = 0; |
---|
| 1367 | |
---|
| 1368 | if( $nodes_size > $max_width ) { |
---|
[107] | 1369 | $nodes_per_row = ( (int) ($max_width/$node_width) ); |
---|
[106] | 1370 | } else { |
---|
| 1371 | $nodes_per_row = $nodes_size; |
---|
| 1372 | $node_rows = 1; |
---|
| 1373 | } |
---|
| 1374 | |
---|
| 1375 | if( $nodes_per_row < $nodes_nr ) { |
---|
[107] | 1376 | $node_rows = ( (int) ($nodes_nr/$nodes_per_row) ); |
---|
| 1377 | $node_rest = fmod( $nodes_nr, $nodes_per_row ); |
---|
| 1378 | //printf( "nodesnr %d noderest %f\n", $nodes_nr, $node_rest ); |
---|
| 1379 | if( $node_rest > 0 ) { |
---|
[106] | 1380 | $node_rows++; |
---|
[107] | 1381 | //printf( "noderows %d\n", $node_rows ); |
---|
[106] | 1382 | } |
---|
| 1383 | } |
---|
| 1384 | |
---|
[306] | 1385 | $y_offset = 0; |
---|
| 1386 | $font = 2; |
---|
[329] | 1387 | $fontwidth = ImageFontWidth( $font ); |
---|
[306] | 1388 | $fontheight = ImageFontHeight( $font ); |
---|
| 1389 | $fontspaceing = 2; |
---|
| 1390 | $y_offset = $fontheight + (2 * $fontspaceing); |
---|
| 1391 | |
---|
[326] | 1392 | $this->width = $max_width; |
---|
| 1393 | $this->height = ($y_offset + (($node_rows*$node_width)+1) ); |
---|
| 1394 | |
---|
[329] | 1395 | //$image = imageCreateTrueColor( $max_width, ($y_offset + (($node_rows*$node_width)+1) ) ); |
---|
| 1396 | //$colorwhite = imageColorAllocate( $image, 255, 255, 255 ); |
---|
| 1397 | //imageFill( $image, 0, 0, $colorwhite ); |
---|
[106] | 1398 | |
---|
[329] | 1399 | //if( $this->isSmall() ) { |
---|
[306] | 1400 | |
---|
[329] | 1401 | // $colorblue = imageColorAllocate( $image, 0, 0, 255 ); |
---|
[306] | 1402 | |
---|
[329] | 1403 | // imageString( $image, $font, 2, 2, "Monarch Joblist - cluster: ".$this->clustername, $colorblue ); |
---|
| 1404 | //} |
---|
[306] | 1405 | |
---|
[122] | 1406 | $jobs = $mydatag->getJobs(); |
---|
| 1407 | //printf("filtername = %s\n", $filtername ); |
---|
| 1408 | $filtered_nodes = $this->filterNodes( $jobs, $nodes ); |
---|
| 1409 | |
---|
| 1410 | //print_r($filtered_nodes); |
---|
| 1411 | |
---|
[329] | 1412 | if( $SORTBY_HOSTNAME != "" ) |
---|
| 1413 | { |
---|
| 1414 | |
---|
| 1415 | $sorted = array(); |
---|
| 1416 | |
---|
| 1417 | $x_first = 0; |
---|
| 1418 | $y_first = 0; |
---|
| 1419 | |
---|
[339] | 1420 | $skan_str = $SORTBY_HOSTNAME; |
---|
[329] | 1421 | |
---|
[339] | 1422 | global $x_present, $y_present; |
---|
| 1423 | $x_present = false; |
---|
| 1424 | $y_present = false; |
---|
| 1425 | |
---|
[464] | 1426 | // Should we scan by X, Y or both |
---|
| 1427 | // |
---|
| 1428 | if(strpos( $SORTBY_HOSTNAME, "{x}" ) != false ) |
---|
[329] | 1429 | { |
---|
[464] | 1430 | $x_str = "{x}"; |
---|
[339] | 1431 | $x_present = true; |
---|
| 1432 | } |
---|
[464] | 1433 | else if(strpos( $SORTBY_HOSTNAME, "{X}" ) != false ) |
---|
[339] | 1434 | { |
---|
[464] | 1435 | $x_str = "{X}"; |
---|
| 1436 | $x_present = true; |
---|
| 1437 | } |
---|
| 1438 | if(strpos( $SORTBY_HOSTNAME, "{y}" ) != false ) |
---|
| 1439 | { |
---|
| 1440 | $y_str = "{y}"; |
---|
[339] | 1441 | $y_present = true; |
---|
| 1442 | } |
---|
[464] | 1443 | else if(strpos( $SORTBY_HOSTNAME, "{Y}" ) != false ) |
---|
| 1444 | { |
---|
| 1445 | $y_str = "{Y}"; |
---|
| 1446 | $y_present = true; |
---|
| 1447 | } |
---|
[339] | 1448 | |
---|
[464] | 1449 | // If we should scan for both X and Y: see which one is first |
---|
| 1450 | // |
---|
| 1451 | if(( strpos( $SORTBY_HOSTNAME, $x_str ) < strpos( $SORTBY_HOSTNAME, $y_str ) ) && ( $x_present && $y_present )) |
---|
[339] | 1452 | { |
---|
[106] | 1453 | |
---|
[329] | 1454 | $x_first = 1; |
---|
| 1455 | } |
---|
[464] | 1456 | else if(( strpos( $SORTBY_HOSTNAME, $x_str ) > strpos( $SORTBY_HOSTNAME, $y_str ) ) && ( $x_present && $y_present )) |
---|
[329] | 1457 | { |
---|
| 1458 | $y_first = 1; |
---|
| 1459 | |
---|
| 1460 | } |
---|
[339] | 1461 | else if( $x_present ) |
---|
| 1462 | { |
---|
| 1463 | $x_first = 1; |
---|
| 1464 | } |
---|
| 1465 | else if( $y_present ) |
---|
| 1466 | { |
---|
| 1467 | $y_first = 1; |
---|
| 1468 | } |
---|
[329] | 1469 | |
---|
[464] | 1470 | // Now replace our {x} and {y} with %d for sscanf parsing |
---|
| 1471 | // |
---|
[339] | 1472 | if(( $x_first ) && ( $x_present && $y_present ) ) |
---|
| 1473 | { |
---|
[464] | 1474 | $skan_str = str_replace( $x_str, "%d", $skan_str ); |
---|
| 1475 | $skan_str = str_replace( $y_str, "%d", $skan_str ); |
---|
[339] | 1476 | } |
---|
| 1477 | else if( $x_present) |
---|
| 1478 | { |
---|
[464] | 1479 | $skan_str = str_replace( $x_str, "%d", $skan_str ); |
---|
[339] | 1480 | } |
---|
| 1481 | else if( $y_present) |
---|
| 1482 | { |
---|
[464] | 1483 | $skan_str = str_replace( $y_str, "%d", $skan_str ); |
---|
[339] | 1484 | } |
---|
[329] | 1485 | |
---|
| 1486 | $x_min = null; |
---|
| 1487 | $x_max = null; |
---|
| 1488 | $y_min = null; |
---|
| 1489 | $y_max = null; |
---|
| 1490 | |
---|
[464] | 1491 | // Now let's walk through all our nodes and see which one are valid for our scan pattern |
---|
| 1492 | // |
---|
[329] | 1493 | foreach( $nodes as $hostname => $node ) |
---|
| 1494 | { |
---|
[404] | 1495 | $x = null; |
---|
| 1496 | $y = null; |
---|
[339] | 1497 | |
---|
| 1498 | if( $x_present && $y_present ) |
---|
[329] | 1499 | { |
---|
[339] | 1500 | if( $x_first ) |
---|
| 1501 | { |
---|
| 1502 | $n = sscanf( $hostname, $skan_str, $x, $y ); |
---|
| 1503 | } |
---|
| 1504 | else if( $y_first ) |
---|
| 1505 | { |
---|
| 1506 | $n = sscanf( $hostname, $skan_str, $y, $x ); |
---|
| 1507 | } |
---|
[463] | 1508 | |
---|
[339] | 1509 | // Remove nodes that don't match |
---|
| 1510 | // |
---|
| 1511 | if( $n < 2 ) |
---|
| 1512 | { |
---|
[463] | 1513 | // This node hostname has no match for: {x} and {y} |
---|
| 1514 | // |
---|
[339] | 1515 | unset( $nodes[$hostname] ); |
---|
| 1516 | } |
---|
[329] | 1517 | } |
---|
[339] | 1518 | else if( $x_present && !$y_present ) |
---|
[329] | 1519 | { |
---|
[339] | 1520 | $n = sscanf( $hostname, $skan_str, $x ); |
---|
[463] | 1521 | |
---|
[339] | 1522 | // Remove nodes that don't match |
---|
| 1523 | // |
---|
| 1524 | if( $n < 1 ) |
---|
| 1525 | { |
---|
[463] | 1526 | // This node hostname has no match for: {x} |
---|
| 1527 | // |
---|
[339] | 1528 | unset( $nodes[$hostname] ); |
---|
| 1529 | } |
---|
| 1530 | $y = 1; |
---|
[329] | 1531 | } |
---|
[339] | 1532 | else if( $y_present && !$x_present ) |
---|
| 1533 | { |
---|
| 1534 | $n = sscanf( $hostname, $skan_str, $y ); |
---|
[463] | 1535 | |
---|
[339] | 1536 | // Remove nodes that don't match |
---|
| 1537 | // |
---|
| 1538 | if( $n < 1 ) |
---|
| 1539 | { |
---|
[463] | 1540 | // This node hostname has no match for: {y} |
---|
| 1541 | // |
---|
[339] | 1542 | unset( $nodes[$hostname] ); |
---|
| 1543 | } |
---|
| 1544 | $x = 1; |
---|
| 1545 | } |
---|
[329] | 1546 | |
---|
[463] | 1547 | // Determine the lowest value of {x} that exists in all node hostnames |
---|
| 1548 | // |
---|
[404] | 1549 | if( !$x_min && $x != null ) |
---|
[329] | 1550 | { |
---|
| 1551 | $x_min = $x; |
---|
| 1552 | } |
---|
[404] | 1553 | else if( $x < $x_min && $x != null ) |
---|
[329] | 1554 | { |
---|
| 1555 | $x_min = $x; |
---|
| 1556 | } |
---|
[463] | 1557 | |
---|
| 1558 | // Determine the highest value of {x} that exists in all node hostnames |
---|
| 1559 | // |
---|
[404] | 1560 | if( !$x_max && $x != null ) |
---|
[329] | 1561 | { |
---|
| 1562 | $x_max = $x; |
---|
| 1563 | } |
---|
[404] | 1564 | else if( $x > $x_max && $x != null ) |
---|
[329] | 1565 | { |
---|
| 1566 | $x_max = $x; |
---|
| 1567 | } |
---|
[463] | 1568 | |
---|
| 1569 | // Determine the lowest value of {y} that exists in all node hostnames |
---|
| 1570 | // |
---|
[404] | 1571 | if( !$y_min && $y != null ) |
---|
[329] | 1572 | { |
---|
| 1573 | $y_min = $y; |
---|
| 1574 | } |
---|
[404] | 1575 | else if( $y < $y_min && $y != null ) |
---|
[329] | 1576 | { |
---|
| 1577 | $y_min = $y; |
---|
| 1578 | } |
---|
[463] | 1579 | |
---|
| 1580 | // Determine the highest value of {y} that exists in all node hostnames |
---|
| 1581 | // |
---|
[404] | 1582 | if( !$y_max && $y != null ) |
---|
[329] | 1583 | { |
---|
| 1584 | $y_max = $y; |
---|
| 1585 | } |
---|
[404] | 1586 | else if( $y > $y_max && $y != null ) |
---|
[329] | 1587 | { |
---|
| 1588 | $y_max = $y; |
---|
| 1589 | } |
---|
| 1590 | } |
---|
| 1591 | |
---|
[463] | 1592 | // Sort all the nodes (alpha and numerically) |
---|
| 1593 | // 1: gb-r1n1, 2: gb-r1n2, 3: gb-r2n1, etc |
---|
| 1594 | // |
---|
[329] | 1595 | $sorted_nodes = usort( $nodes, "cmp" ); |
---|
| 1596 | |
---|
| 1597 | $cur_node = 0; |
---|
| 1598 | |
---|
[331] | 1599 | $x_offset = 0; |
---|
| 1600 | $y_offset = 0; |
---|
| 1601 | $font = 2; |
---|
| 1602 | $fontwidth = ImageFontWidth( $font ); |
---|
| 1603 | $fontheight = ImageFontHeight( $font ); |
---|
| 1604 | $fontspaceing = 2; |
---|
| 1605 | |
---|
[333] | 1606 | if( $this->isSmall() ) |
---|
| 1607 | { |
---|
| 1608 | $y_offset = $y_offset + (2 * $fontspaceing) + $fontheight; |
---|
| 1609 | } |
---|
| 1610 | |
---|
[331] | 1611 | if( $this->isBig() ) |
---|
| 1612 | { |
---|
| 1613 | |
---|
| 1614 | $y_offset = ($fontheight * (1 + strlen( $x_max) ) ) + ((2 + strlen( $x_max)) * $fontspaceing); |
---|
| 1615 | $x_offset = ($fontwidth * (1 + strlen( $y_max) ) ) + ((2 + strlen( $y_max)) * $fontspaceing); |
---|
| 1616 | |
---|
| 1617 | } |
---|
| 1618 | //$x_offset = ($fontwidth * 3) + (5 * $fontspaceing); |
---|
| 1619 | |
---|
[329] | 1620 | //printf( "xmin %s xmax %s\n", $x_min, $x_max ); |
---|
| 1621 | //printf( "ymin %s ymax %s\n", $y_min, $y_max ); |
---|
| 1622 | |
---|
| 1623 | // werkt |
---|
| 1624 | //print_r( $nodes ); |
---|
| 1625 | |
---|
[330] | 1626 | $image_width = $x_offset + ($node_width * ($x_max-$x_min+2)); |
---|
[428] | 1627 | |
---|
| 1628 | if( $this->isSmall() ) |
---|
[340] | 1629 | { |
---|
[428] | 1630 | $image_width = $max_width; |
---|
| 1631 | } else if( $this->isBig() ) |
---|
[340] | 1632 | { |
---|
[428] | 1633 | $image_width = ($image_width < $max_width) ? $image_width : $max_width; |
---|
[340] | 1634 | } |
---|
[428] | 1635 | //else if( $this->isSmall() ) |
---|
| 1636 | //{ |
---|
| 1637 | // $image_width = $this->width; |
---|
| 1638 | //} |
---|
[330] | 1639 | $image_height = $y_offset + ($node_width * ($y_max-$y_min+2)); |
---|
| 1640 | |
---|
| 1641 | $this->width = $image_width; |
---|
| 1642 | $this->heigth = $image_heigth; |
---|
| 1643 | |
---|
| 1644 | $image = imageCreateTrueColor( $image_width, $image_height ); |
---|
[329] | 1645 | $colorwhite = imageColorAllocate( $image, 255, 255, 255 ); |
---|
| 1646 | |
---|
| 1647 | imageFill( $image, 0, 0, $colorwhite ); |
---|
| 1648 | |
---|
[333] | 1649 | if( $this->isSmall() ) { |
---|
| 1650 | |
---|
[463] | 1651 | // Draw a fancy little header text to explain what it is |
---|
| 1652 | // |
---|
[333] | 1653 | $colorblue = imageColorAllocate( $image, 0, 0, 255 ); |
---|
| 1654 | |
---|
| 1655 | imageString( $image, $font, 2, 2, "Monarch Joblist - cluster: ".$this->clustername, $colorblue ); |
---|
| 1656 | } |
---|
| 1657 | |
---|
[339] | 1658 | if( $this->isBig() && ( isset( $SORT_XLABEL ) || isset( $SORT_YLABEL ) ) ) |
---|
[331] | 1659 | { |
---|
| 1660 | $colorblue = imageColorAllocate( $image, 0, 0, 255 ); |
---|
[329] | 1661 | |
---|
[339] | 1662 | if( isset( $SORT_XLABEL ) ) |
---|
| 1663 | { |
---|
[463] | 1664 | // Print the {x} label: rack |
---|
| 1665 | // |
---|
[339] | 1666 | imageString( $image, $font, $x_offset, $fontspaceing, $SORT_XLABEL, $colorblue ); |
---|
| 1667 | } |
---|
[329] | 1668 | |
---|
[339] | 1669 | if( isset( $SORT_YLABEL ) ) |
---|
| 1670 | { |
---|
[463] | 1671 | // Stupid php without imageStringDown function... we'll make one ourself |
---|
[339] | 1672 | // |
---|
[463] | 1673 | |
---|
| 1674 | // Print the {y} label: node |
---|
| 1675 | // |
---|
[339] | 1676 | imageStringDown( $image, $font, $fontspaceing, $y_offset, $SORT_YLABEL, $colorblue ); |
---|
| 1677 | } |
---|
[331] | 1678 | } |
---|
[329] | 1679 | |
---|
| 1680 | for( $n = $x_min; $n <= $x_max; $n++ ) |
---|
| 1681 | { |
---|
| 1682 | for( $m = $y_min; $m <= $y_max; $m++ ) |
---|
| 1683 | { |
---|
[463] | 1684 | |
---|
[329] | 1685 | if( $x_min > 0 ) |
---|
| 1686 | { |
---|
| 1687 | $x = $x_offset + ( ($n-$x_min) * $node_width ); |
---|
| 1688 | } |
---|
| 1689 | if( $y_min > 0 ) |
---|
| 1690 | { |
---|
| 1691 | $y = $y_offset + ( ($m-$y_min) * $node_width ); |
---|
| 1692 | } |
---|
| 1693 | |
---|
[463] | 1694 | if( $this->isBig() ) |
---|
| 1695 | { |
---|
| 1696 | // Draw y(node) column number header |
---|
| 1697 | // |
---|
| 1698 | if(( $n == $x_min ) && ( isset($SORT_YLABEL) ) ) |
---|
| 1699 | { |
---|
| 1700 | $mfontspacing = 1; |
---|
| 1701 | |
---|
| 1702 | $ylabel_x = $x - ( $fontwidth * strlen( $y_max ) ) - $mfontspacing; |
---|
| 1703 | $ylabel_y = $y; |
---|
| 1704 | |
---|
| 1705 | imageString( $image, $font, $ylabel_x, $ylabel_y, strval( $m ), $colorblue ); |
---|
| 1706 | |
---|
| 1707 | $xmin_hit[$n] = true; |
---|
| 1708 | } |
---|
| 1709 | |
---|
| 1710 | // Draw x(rack) column number header |
---|
| 1711 | // |
---|
| 1712 | if(( $m == $y_min ) && ( isset($SORT_XLABEL) ) ) |
---|
| 1713 | { |
---|
| 1714 | $mfontspacing = 2; |
---|
| 1715 | $xlabel_y = $y - ( $fontheight * strlen( $x_max ) ); |
---|
| 1716 | $xlabel_x = $x + $mfontspacing; |
---|
| 1717 | |
---|
| 1718 | imageStringDown( $image, $font, $xlabel_x, $xlabel_y, strval( $n ), $colorblue ); |
---|
| 1719 | } |
---|
| 1720 | } |
---|
| 1721 | |
---|
[330] | 1722 | if( isset( $nodes[$cur_node] ) ) |
---|
| 1723 | { |
---|
[329] | 1724 | $host = $nodes[$cur_node]->getHostname(); |
---|
| 1725 | |
---|
[339] | 1726 | if( $x_present && $y_present ) |
---|
[329] | 1727 | { |
---|
[339] | 1728 | if( $x_first ) |
---|
| 1729 | { |
---|
| 1730 | $nn = sscanf( $host, $skan_str, $rx, $ry ); |
---|
| 1731 | } |
---|
| 1732 | else if( $y_first ) |
---|
| 1733 | { |
---|
| 1734 | $nn = sscanf( $host, $skan_str, $ry, $rx ); |
---|
| 1735 | } |
---|
| 1736 | if ( $nn < 2 ) |
---|
| 1737 | { |
---|
[404] | 1738 | //printf( "skipping node %s - y present & x present + <2 x,y matchs\n", $host); |
---|
[339] | 1739 | continue; |
---|
| 1740 | } |
---|
[404] | 1741 | if( intval( $rx ) > $n ) |
---|
[339] | 1742 | { |
---|
[463] | 1743 | // If x(rack) is higher than current x, skip to next x(rack) |
---|
| 1744 | // |
---|
| 1745 | $m = $y_max + 1; |
---|
| 1746 | |
---|
[339] | 1747 | continue; |
---|
| 1748 | } |
---|
[404] | 1749 | if( intval( $ry ) > $m ) |
---|
| 1750 | { |
---|
[463] | 1751 | // If y(node) is higher than current y, skip to next y(node) |
---|
| 1752 | // |
---|
[404] | 1753 | continue; |
---|
| 1754 | } |
---|
[329] | 1755 | } |
---|
[339] | 1756 | else if( $x_present ) |
---|
[329] | 1757 | { |
---|
[339] | 1758 | $nn = sscanf( $host, $skan_str, $rx ); |
---|
[329] | 1759 | } |
---|
[339] | 1760 | else if( $y_present ) |
---|
[329] | 1761 | { |
---|
[339] | 1762 | $nn = sscanf( $host, $skan_str, $ry ); |
---|
[329] | 1763 | } |
---|
| 1764 | |
---|
| 1765 | if( !in_array( $host, $filtered_nodes ) ) |
---|
[404] | 1766 | { |
---|
[463] | 1767 | // This node has been filtered out: we only want to see certain nodes |
---|
| 1768 | // |
---|
[329] | 1769 | $nodes[$cur_node]->setShowinfo( 0 ); |
---|
[404] | 1770 | } |
---|
[329] | 1771 | |
---|
| 1772 | $nodes[$cur_node]->setCoords( $x, $y ); |
---|
| 1773 | $nodes[$cur_node]->setImage( $image ); |
---|
| 1774 | |
---|
| 1775 | //print_r( $nodes[$cur_node] ); |
---|
| 1776 | |
---|
| 1777 | if( $this->isSmall() ) |
---|
| 1778 | $nodes[$cur_node]->drawSmall(); |
---|
| 1779 | else if( $this->isBig() ) |
---|
| 1780 | $nodes[$cur_node]->drawBig(); |
---|
[404] | 1781 | |
---|
| 1782 | $cur_node++; |
---|
[329] | 1783 | } |
---|
| 1784 | } |
---|
| 1785 | } |
---|
| 1786 | |
---|
| 1787 | } |
---|
| 1788 | else |
---|
| 1789 | { |
---|
[428] | 1790 | if( $this->isSmall() ) { |
---|
| 1791 | $image = imageCreateTrueColor( $max_width, ($y_offset + (($node_rows*$node_width)+1) ) ); |
---|
| 1792 | } else if( $this->isBig() ) { |
---|
| 1793 | $image_width = ($node_width * $nodes_nr) + 2; |
---|
| 1794 | $image_width = ($image_width < $max_width) ? $image_width : $max_width; |
---|
| 1795 | $image = imageCreateTrueColor( $image_width, ($y_offset + (($node_rows*$node_width)+1) ) ); |
---|
| 1796 | } |
---|
[329] | 1797 | $colorwhite = imageColorAllocate( $image, 255, 255, 255 ); |
---|
| 1798 | |
---|
| 1799 | imageFill( $image, 0, 0, $colorwhite ); |
---|
| 1800 | |
---|
| 1801 | if( $this->isSmall() ) { |
---|
| 1802 | |
---|
| 1803 | $colorblue = imageColorAllocate( $image, 0, 0, 255 ); |
---|
| 1804 | |
---|
| 1805 | imageString( $image, $font, 2, 2, "Monarch Joblist - cluster: ".$this->clustername, $colorblue ); |
---|
| 1806 | } |
---|
| 1807 | |
---|
| 1808 | for( $n = 0; $n < $node_rows; $n++ ) { |
---|
[107] | 1809 | |
---|
[329] | 1810 | for( $m = 0; $m < $nodes_per_row; $m++ ) { |
---|
| 1811 | |
---|
| 1812 | $x = ($m * $node_width); |
---|
| 1813 | $y = $y_offset + ($n * $node_width); |
---|
[107] | 1814 | |
---|
[329] | 1815 | $cur_node = ($n * $nodes_per_row) + ($m); |
---|
| 1816 | $host = $nodes_hosts[$cur_node]; |
---|
[107] | 1817 | |
---|
[329] | 1818 | if( isset( $nodes[$host] ) ) { |
---|
[111] | 1819 | |
---|
[329] | 1820 | $nodes[$host]->setCoords( $x, $y ); |
---|
| 1821 | $nodes[$host]->setImage( $image ); |
---|
[122] | 1822 | |
---|
[329] | 1823 | if( !in_array( $host, $filtered_nodes ) ) |
---|
[404] | 1824 | { |
---|
[329] | 1825 | $nodes[$host]->setShowinfo( 0 ); |
---|
[404] | 1826 | } |
---|
[122] | 1827 | |
---|
[329] | 1828 | if( $this->isSmall() ) |
---|
| 1829 | $nodes[$host]->drawSmall(); |
---|
| 1830 | else if( $this->isBig() ) |
---|
| 1831 | $nodes[$host]->drawBig(); |
---|
| 1832 | } |
---|
[111] | 1833 | } |
---|
[106] | 1834 | } |
---|
| 1835 | } |
---|
[326] | 1836 | |
---|
| 1837 | $this->nodes = &$nodes; |
---|
| 1838 | |
---|
| 1839 | if ($this->output) { |
---|
| 1840 | header( 'Content-type: image/png' ); |
---|
| 1841 | imagePNG( $image ); |
---|
| 1842 | imageDestroy( $image ); |
---|
| 1843 | } |
---|
[102] | 1844 | } |
---|
[326] | 1845 | |
---|
| 1846 | function getImagemapArea() { |
---|
| 1847 | |
---|
| 1848 | $clusterimage_map = ""; |
---|
| 1849 | |
---|
| 1850 | foreach( $this->nodes as $hostname => $node ) { |
---|
| 1851 | |
---|
| 1852 | $node_map = $node->getImagemapArea(); |
---|
| 1853 | $clusterimage_map .= $node_map; |
---|
| 1854 | } |
---|
| 1855 | |
---|
| 1856 | return $clusterimage_map; |
---|
| 1857 | } |
---|
[102] | 1858 | } |
---|
| 1859 | |
---|
[298] | 1860 | class EmptyImage { |
---|
| 1861 | |
---|
| 1862 | function draw() { |
---|
| 1863 | $image = imageCreateTrueColor( 1, 1 ); |
---|
| 1864 | $colorwhite = imageColorAllocate( $image, 255, 255, 255 ); |
---|
| 1865 | imageFill( $image, 0, 0, $colorwhite ); |
---|
| 1866 | |
---|
| 1867 | header( 'Content-type: image/png' ); |
---|
| 1868 | imagePNG( $image ); |
---|
| 1869 | imageDestroy( $image ); |
---|
| 1870 | } |
---|
| 1871 | } |
---|
| 1872 | |
---|
[303] | 1873 | class HostImage { |
---|
[106] | 1874 | |
---|
[303] | 1875 | var $data_gather, $cluster, $host, $node, $image; |
---|
| 1876 | var $headerstrlen; |
---|
| 1877 | |
---|
| 1878 | function HostImage( $data_gather, $cluster, $host ) { |
---|
| 1879 | |
---|
| 1880 | $this->data_gather = $data_gather; |
---|
| 1881 | $this->cluster = $cluster; |
---|
| 1882 | $this->host = $host; |
---|
| 1883 | $this->y_offset = 0; |
---|
| 1884 | $this->font = 2; |
---|
| 1885 | $this->fontspaceing = 2; |
---|
| 1886 | $this->headerstrlen = array(); |
---|
| 1887 | |
---|
| 1888 | $this->fontheight = ImageFontHeight( $this->font ); |
---|
| 1889 | $this->fontwidth = ImageFontWidth( $this->font ); |
---|
| 1890 | |
---|
| 1891 | $dg = &$this->data_gather; |
---|
| 1892 | $this->node = &$dg->getNode( $this->host ); |
---|
| 1893 | $n = &$this->node; |
---|
| 1894 | $this->njobs = $n->getJobs(); |
---|
| 1895 | } |
---|
| 1896 | |
---|
| 1897 | function drawJobs() { |
---|
| 1898 | |
---|
| 1899 | $dg = &$this->data_gather; |
---|
| 1900 | $colorblack = imageColorAllocate( $this->image, 0, 0, 0 ); |
---|
| 1901 | |
---|
| 1902 | for( $n = 0; $n < count( $this->njobs ); $n++ ) { |
---|
| 1903 | |
---|
| 1904 | $jobid = $this->njobs[$n]; |
---|
| 1905 | $jobinfo = $dg->getJob( $jobid ); |
---|
| 1906 | |
---|
| 1907 | $xoffset = 5; |
---|
| 1908 | imageString( $this->image, $this->font, $xoffset, $this->y_offset, strval( $jobid ), $colorblack ); |
---|
| 1909 | |
---|
| 1910 | foreach( $this->headerstrlen as $headername => $headerlen ) { |
---|
| 1911 | |
---|
| 1912 | if( $headername == 'nodes' ) { |
---|
| 1913 | $attrval = strval( count( $jobinfo[nodes] ) ); |
---|
| 1914 | } else if( $headername == 'cpus' ) { |
---|
| 1915 | |
---|
| 1916 | if( !isset( $jobinfo[ppn] ) ) |
---|
| 1917 | $jobinfo[ppn] = 1; |
---|
| 1918 | |
---|
| 1919 | $attrval = strval( count( $jobinfo[nodes] ) * intval( $jobinfo[ppn] ) ); |
---|
| 1920 | |
---|
| 1921 | } else if( $headername == 'runningtime' ) { |
---|
| 1922 | $attrval = makeTime( intval( $jobinfo[reported] ) - intval( $jobinfo[start_timestamp] ) ); |
---|
| 1923 | } else { |
---|
| 1924 | $attrval = strval( $jobinfo[$headername] ); |
---|
| 1925 | } |
---|
| 1926 | |
---|
| 1927 | imageString( $this->image, $this->font, $xoffset, $this->y_offset, $attrval, $colorblack ); |
---|
| 1928 | |
---|
| 1929 | $xoffset = $xoffset + ($this->fontwidth * ( $headerlen + 1 ) ); |
---|
| 1930 | |
---|
| 1931 | } |
---|
| 1932 | |
---|
| 1933 | $this->newLineOffset(); |
---|
| 1934 | } |
---|
| 1935 | } |
---|
| 1936 | |
---|
| 1937 | function drawHeader() { |
---|
| 1938 | |
---|
| 1939 | $dg = &$this->data_gather; |
---|
| 1940 | |
---|
| 1941 | for( $n = 0; $n < count( $this->njobs ); $n++ ) { |
---|
| 1942 | |
---|
| 1943 | $jobid = $this->njobs[$n]; |
---|
| 1944 | $jobinfo = $dg->getJob( $jobid ); |
---|
| 1945 | |
---|
| 1946 | if( !isset( $this->headerstrlen[id] ) ) |
---|
| 1947 | $this->headerstrlen[id] = strlen( strval( $jobid ) ); |
---|
| 1948 | else |
---|
| 1949 | if( strlen( strval( $jobid ) ) > $this->headerstrlen[id] ) |
---|
| 1950 | $this->headerstrlen[id] = strlen( strval( $jobid ) ); |
---|
| 1951 | |
---|
| 1952 | if( !isset( $this->headerstrlen[owner] ) ) |
---|
| 1953 | $this->headerstrlen[owner] = strlen( strval( $jobinfo[owner] ) ); |
---|
| 1954 | else |
---|
| 1955 | if( strlen( strval( $jobinfo[owner] ) ) > $this->headerstrlen[owner] ) |
---|
| 1956 | $this->headerstrlen[owner] = strlen( strval( $jobinfo[owner] ) ); |
---|
| 1957 | |
---|
| 1958 | if( !isset( $this->headerstrlen[queue] ) ) |
---|
| 1959 | $this->headerstrlen[queue] = strlen( strval( $jobinfo[queue] ) ); |
---|
| 1960 | else |
---|
| 1961 | if( strlen( strval( $jobinfo[queue] ) ) > $this->headerstrlen[queue] ) |
---|
| 1962 | $this->headerstrlen[queue] = strlen( strval( $jobinfo[queue] ) ); |
---|
| 1963 | |
---|
| 1964 | if( !isset( $jobinfo[ppn] ) ) |
---|
| 1965 | $jobinfo[ppn] = 1; |
---|
| 1966 | |
---|
| 1967 | $cpus = count( $jobinfo[nodes] ) * intval( $jobinfo[ppn] ); |
---|
| 1968 | |
---|
| 1969 | if( !isset( $this->headerstrlen[cpus] ) ) |
---|
| 1970 | $this->headerstrlen[cpus] = strlen( strval( $cpus ) ); |
---|
| 1971 | else |
---|
| 1972 | if( strlen( strval( $cpus ) ) > $this->headerstrlen[cpus] ) |
---|
| 1973 | $this->headerstrlen[cpus] = strlen( strval( $cpus ) ); |
---|
| 1974 | |
---|
| 1975 | $nodes = count( $jobinfo[nodes] ); |
---|
| 1976 | |
---|
| 1977 | if( !isset( $this->headerstrlen[nodes] ) ) |
---|
| 1978 | $this->headerstrlen[nodes] = strlen( strval( $nodes ) ); |
---|
| 1979 | else |
---|
| 1980 | if( strlen( strval( $nodes) ) > $this->headerstrlen[nodes] ) |
---|
| 1981 | $this->headerstrlen[nodes] = strlen( strval( $nodes ) ); |
---|
| 1982 | |
---|
| 1983 | $runningtime = makeTime( intval( $jobinfo[reported] ) - intval( $jobinfo[start_timestamp] ) ); |
---|
| 1984 | |
---|
| 1985 | if( !isset( $this->headerstrlen[runningtime] ) ) |
---|
| 1986 | $this->headerstrlen[runningtime] = strlen( strval( $runningtime) ); |
---|
| 1987 | else |
---|
| 1988 | if( strlen( strval( $runningtime) ) > $this->headerstrlen[runningtime] ) |
---|
| 1989 | $this->headerstrlen[runningtime] = strlen( strval( $runningtime) ); |
---|
| 1990 | |
---|
| 1991 | if( !isset( $this->headerstrlen[name] ) ) |
---|
| 1992 | $this->headerstrlen[name] = strlen( strval( $jobinfo[name] ) ); |
---|
| 1993 | else |
---|
| 1994 | if( strlen( strval( $jobinfo[name] ) ) > $this->headerstrlen[name] ) |
---|
| 1995 | $this->headerstrlen[name] = strlen( strval( $jobinfo[name] ) ); |
---|
| 1996 | |
---|
| 1997 | } |
---|
| 1998 | |
---|
| 1999 | $xoffset = 5; |
---|
| 2000 | |
---|
[350] | 2001 | foreach( $this->headerstrlen as $headername => $headerlen ) { |
---|
[303] | 2002 | |
---|
| 2003 | $colorgreen = imageColorAllocate( $this->image, 0, 200, 0 ); |
---|
| 2004 | |
---|
| 2005 | if( $headerlen < strlen( $headername ) ) |
---|
[350] | 2006 | $this->headerstrlen[$headername] = strlen( $headername ); |
---|
[303] | 2007 | |
---|
[426] | 2008 | imageString( $this->image, $this->font, $xoffset, $this->y_offset, ucfirst( $headername ), $colorgreen ); |
---|
[303] | 2009 | |
---|
[426] | 2010 | $xoffset = $xoffset + ($this->fontwidth * ( $this->headerstrlen[$headername] + 1 ) ); |
---|
| 2011 | |
---|
[303] | 2012 | } |
---|
| 2013 | $this->newLineOffset(); |
---|
| 2014 | } |
---|
| 2015 | |
---|
| 2016 | function newLineOffset() { |
---|
| 2017 | |
---|
| 2018 | $this->y_offset = $this->y_offset + $this->fontheight + $this->fontspaceing; |
---|
| 2019 | } |
---|
| 2020 | |
---|
| 2021 | function draw() { |
---|
| 2022 | |
---|
| 2023 | $xlen = 450; |
---|
| 2024 | $ylen = ( count( $this->njobs ) * ( $this->fontheight + $this->fontspaceing ) ) + (3 * $this->fontheight); |
---|
| 2025 | |
---|
| 2026 | $this->image = imageCreateTrueColor( $xlen, $ylen ); |
---|
| 2027 | $colorwhite = imageColorAllocate( $this->image, 255, 255, 255 ); |
---|
| 2028 | imageFill( $this->image, 0, 0, $colorwhite ); |
---|
| 2029 | |
---|
| 2030 | $colorblue = imageColorAllocate( $this->image, 0, 0, 255 ); |
---|
| 2031 | |
---|
| 2032 | imageString( $this->image, $this->font, 1, $this->y_offset, "Monarch Joblist - host: ".$this->host, $colorblue ); |
---|
| 2033 | $this->newLineOffset(); |
---|
| 2034 | |
---|
| 2035 | $this->drawHeader(); |
---|
| 2036 | $this->drawJobs(); |
---|
| 2037 | |
---|
| 2038 | header( 'Content-type: image/png' ); |
---|
| 2039 | imagePNG( $this->image ); |
---|
| 2040 | imageDestroy( $this->image ); |
---|
| 2041 | } |
---|
| 2042 | } |
---|
| 2043 | |
---|
[331] | 2044 | function imageStringDown( &$image, $font, $x, $y, &$s, &$col ) |
---|
| 2045 | { |
---|
| 2046 | $fw = imagefontwidth( $font); |
---|
| 2047 | $fh = imagefontheight( $font); |
---|
| 2048 | |
---|
| 2049 | $fontspacing = 0; |
---|
| 2050 | |
---|
| 2051 | $fx = $x; |
---|
| 2052 | $fy = $y; |
---|
| 2053 | |
---|
| 2054 | for( $n=0; $n<strlen( $s ); $n++ ) |
---|
| 2055 | { |
---|
| 2056 | $myc = $s{$n}; |
---|
| 2057 | |
---|
| 2058 | imagestring( $image, $font, $fx, $fy, $myc, $col ); |
---|
| 2059 | |
---|
| 2060 | $fy += ($fontspacing + $fh ); |
---|
| 2061 | } |
---|
| 2062 | } |
---|
| 2063 | |
---|
[329] | 2064 | function array_rem( $val, &$arr ) |
---|
| 2065 | { |
---|
| 2066 | // Delete val from arr |
---|
| 2067 | // |
---|
| 2068 | $i = array_search( $val, $arr ); |
---|
| 2069 | |
---|
| 2070 | if( $i == false ) return false; |
---|
| 2071 | |
---|
| 2072 | $arr = array_merge( array_slice( $arr, 0, $i ), array_slice( $arr, $i+1, count( $arr ) ) ); |
---|
| 2073 | |
---|
| 2074 | return true; |
---|
| 2075 | } |
---|
| 2076 | |
---|
| 2077 | function cmp( $a, $b ) |
---|
| 2078 | { |
---|
| 2079 | global $SORT_ORDER; |
---|
| 2080 | global $skan_str; |
---|
| 2081 | global $x_first, $y_first; |
---|
[339] | 2082 | global $x_present, $y_present; |
---|
[329] | 2083 | |
---|
[339] | 2084 | //printf("ppoep = %s\n", $skan_str); |
---|
[329] | 2085 | $a_node = $a; |
---|
| 2086 | $b_node = $b; |
---|
| 2087 | $a = $a_node->getHostname(); |
---|
| 2088 | $b = $b_node->getHostname(); |
---|
| 2089 | |
---|
| 2090 | if( $a == $b ) return 0; |
---|
| 2091 | |
---|
[339] | 2092 | $a_x = 0; |
---|
| 2093 | $b_x = 0; |
---|
| 2094 | $a_y = 0; |
---|
| 2095 | $b_y = 0; |
---|
| 2096 | |
---|
| 2097 | if( $x_present && $y_present ) |
---|
[329] | 2098 | { |
---|
[339] | 2099 | if( $x_first ) |
---|
| 2100 | { |
---|
| 2101 | $n = sscanf( $a, $skan_str, $a_x, $a_y ); |
---|
| 2102 | $n = sscanf( $b, $skan_str, $b_x, $b_y ); |
---|
| 2103 | } |
---|
| 2104 | else if( $y_first ) |
---|
| 2105 | { |
---|
| 2106 | $n = sscanf( $a, $skan_str, $a_y, $a_x ); |
---|
| 2107 | $n = sscanf( $b, $skan_str, $b_y, $b_x ); |
---|
| 2108 | } |
---|
| 2109 | } |
---|
| 2110 | else if( $x_present && !$y_present ) |
---|
| 2111 | { |
---|
| 2112 | $n = sscanf( $a, $skan_str, $a_x ); |
---|
| 2113 | $n = sscanf( $b, $skan_str, $b_x ); |
---|
[329] | 2114 | } |
---|
[339] | 2115 | else if( $y_present && !$x_present ) |
---|
[329] | 2116 | { |
---|
[339] | 2117 | $n = sscanf( $a, $skan_str, $a_y ); |
---|
| 2118 | $n = sscanf( $b, $skan_str, $b_y ); |
---|
[329] | 2119 | } |
---|
| 2120 | |
---|
| 2121 | if ( $SORT_ORDER=="desc" ) |
---|
| 2122 | { |
---|
| 2123 | |
---|
[339] | 2124 | if( $x_present && $y_present ) |
---|
[329] | 2125 | { |
---|
[339] | 2126 | // 1 = a < b |
---|
| 2127 | // -1 = a > b |
---|
| 2128 | // |
---|
| 2129 | if ($a_x == $b_x) |
---|
[329] | 2130 | { |
---|
[339] | 2131 | if ($a_y < $b_y) |
---|
| 2132 | { |
---|
| 2133 | return 1; |
---|
| 2134 | } |
---|
| 2135 | else if ($a_y > $b_y) |
---|
| 2136 | { |
---|
| 2137 | return -1; |
---|
| 2138 | } |
---|
| 2139 | } |
---|
| 2140 | else if ($a_x < $b_x) |
---|
| 2141 | { |
---|
[329] | 2142 | return 1; |
---|
| 2143 | } |
---|
[339] | 2144 | else if ($a_x > $b_x) |
---|
[329] | 2145 | { |
---|
| 2146 | return -1; |
---|
| 2147 | } |
---|
[339] | 2148 | } |
---|
| 2149 | else if( $x_present && !$y_present ) |
---|
[329] | 2150 | { |
---|
[339] | 2151 | if ($a_x < $b_x) |
---|
| 2152 | { |
---|
| 2153 | return 1; |
---|
| 2154 | } |
---|
| 2155 | else if ($a_x > $b_x) |
---|
| 2156 | { |
---|
| 2157 | return -1; |
---|
| 2158 | } |
---|
[329] | 2159 | } |
---|
[339] | 2160 | else if( $y_present && !$x_present ) |
---|
[329] | 2161 | { |
---|
[339] | 2162 | if ($a_y < $b_y) |
---|
| 2163 | { |
---|
| 2164 | return 1; |
---|
| 2165 | } |
---|
| 2166 | else if ($a_y > $b_y) |
---|
| 2167 | { |
---|
| 2168 | return -1; |
---|
| 2169 | } |
---|
[329] | 2170 | } |
---|
| 2171 | } |
---|
| 2172 | else if ( $SORT_ORDER == "asc" ) |
---|
| 2173 | { |
---|
| 2174 | |
---|
[339] | 2175 | if( $x_present && $y_present ) |
---|
[329] | 2176 | { |
---|
[339] | 2177 | // 1 = a > b |
---|
| 2178 | // -1 = a < b |
---|
| 2179 | // |
---|
| 2180 | if ($a_x == $b_x) |
---|
[329] | 2181 | { |
---|
[339] | 2182 | if ($a_y > $b_y) |
---|
| 2183 | { |
---|
| 2184 | return 1; |
---|
| 2185 | } |
---|
| 2186 | else if ($a_y < $b_y) |
---|
| 2187 | { |
---|
| 2188 | return -1; |
---|
| 2189 | } |
---|
| 2190 | } |
---|
| 2191 | else if ($a_x > $b_x) |
---|
| 2192 | { |
---|
[329] | 2193 | return 1; |
---|
| 2194 | } |
---|
[339] | 2195 | else if ($a_x < $b_x) |
---|
[329] | 2196 | { |
---|
| 2197 | return -1; |
---|
| 2198 | } |
---|
| 2199 | } |
---|
[339] | 2200 | else if( $x_present && !$y_present ) |
---|
[329] | 2201 | { |
---|
[339] | 2202 | if ($a_x > $b_x) |
---|
| 2203 | { |
---|
| 2204 | return 1; |
---|
| 2205 | } |
---|
| 2206 | else if ($a_x < $b_x) |
---|
| 2207 | { |
---|
| 2208 | return -1; |
---|
| 2209 | } |
---|
[329] | 2210 | } |
---|
[339] | 2211 | else if( $y_present && !$x_present ) |
---|
[329] | 2212 | { |
---|
[339] | 2213 | if ($a_y > $b_y) |
---|
| 2214 | { |
---|
| 2215 | return 1; |
---|
| 2216 | } |
---|
| 2217 | else if ($a_y < $b_y) |
---|
| 2218 | { |
---|
| 2219 | return -1; |
---|
| 2220 | } |
---|
[329] | 2221 | } |
---|
| 2222 | } |
---|
| 2223 | } |
---|
[303] | 2224 | function makeTime( $time ) { |
---|
| 2225 | |
---|
| 2226 | $days = intval( $time / 86400 ); |
---|
| 2227 | $time = ($days>0) ? $time % ($days * 86400) : $time; |
---|
| 2228 | |
---|
| 2229 | //printf( "time = %s, days = %s\n", $time, $days ); |
---|
| 2230 | |
---|
| 2231 | $date_str = ''; |
---|
| 2232 | $day_str = ''; |
---|
| 2233 | |
---|
| 2234 | if( $days > 0 ) { |
---|
| 2235 | if( $days > 1 ) |
---|
| 2236 | $day_str .= $days . ' days'; |
---|
| 2237 | else |
---|
| 2238 | $day_str .= $days . ' day'; |
---|
| 2239 | } |
---|
| 2240 | |
---|
| 2241 | $hours = intval( $time / 3600 ); |
---|
| 2242 | $time = $hours ? $time % ($hours * 3600) : $time; |
---|
| 2243 | |
---|
| 2244 | //printf( "time = %s, days = %s, hours = %s\n", $time, $days, $hours ); |
---|
| 2245 | if( $hours > 0 ) { |
---|
| 2246 | $date_str .= $hours . ':'; |
---|
| 2247 | $date_unit = 'hours'; |
---|
| 2248 | } |
---|
| 2249 | |
---|
| 2250 | $minutes = intval( $time / 60 ); |
---|
| 2251 | $seconds = $minutes ? $time % ($minutes * 60) : $time; |
---|
| 2252 | |
---|
| 2253 | if( $minutes > 0 ) { |
---|
| 2254 | |
---|
| 2255 | if( $minutes >= 10 ) |
---|
| 2256 | $date_str .= $minutes . ':'; |
---|
| 2257 | else |
---|
| 2258 | $date_str .= '0' . $minutes . ':'; |
---|
| 2259 | |
---|
| 2260 | $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit; |
---|
| 2261 | } else { |
---|
| 2262 | if($hours > 0 ) { |
---|
| 2263 | $date_str .= '00:'; |
---|
| 2264 | $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit; |
---|
| 2265 | } |
---|
| 2266 | } |
---|
| 2267 | |
---|
| 2268 | |
---|
| 2269 | $date_unit = (!isset($date_unit)) ? 'seconds' : $date_unit; |
---|
| 2270 | |
---|
| 2271 | if( $seconds > 0 ) { |
---|
| 2272 | |
---|
| 2273 | if( $seconds >= 10 ) |
---|
| 2274 | $date_str .= $seconds . ' ' . $date_unit; |
---|
| 2275 | else |
---|
| 2276 | $date_str .= '0' . $seconds . ' ' . $date_unit; |
---|
| 2277 | |
---|
| 2278 | } else if ( $hours > 0 or $minutes > 0 ) |
---|
| 2279 | |
---|
| 2280 | $date_str .= '00 ' . $date_unit; |
---|
| 2281 | |
---|
| 2282 | if( $days > 0) { |
---|
| 2283 | |
---|
| 2284 | if( $hours > 0 or $minutes > 0 or $seconds > 0 ) |
---|
| 2285 | $date_str = $day_str . ' - ' . $date_str; |
---|
| 2286 | else |
---|
| 2287 | $date_str = $day_str; |
---|
| 2288 | } |
---|
| 2289 | |
---|
| 2290 | return $date_str; |
---|
| 2291 | } |
---|
[102] | 2292 | ?> |
---|