[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 426 2007-07-07 11:57:33Z 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 | |
---|
[130] | 128 | class TarchDbase { |
---|
| 129 | |
---|
[138] | 130 | var $ip, $dbase, $conn; |
---|
[130] | 131 | |
---|
[294] | 132 | function TarchDbase( $ip = null, $dbase = null ) { |
---|
[207] | 133 | |
---|
| 134 | global $JOB_ARCHIVE_DBASE; |
---|
| 135 | |
---|
| 136 | $db_fields = explode( '/', $JOB_ARCHIVE_DBASE ); |
---|
| 137 | |
---|
| 138 | $this->ip = $db_fields[0]; |
---|
| 139 | $this->dbase = $db_fields[1]; |
---|
[138] | 140 | $this->conn = null; |
---|
[130] | 141 | } |
---|
| 142 | |
---|
| 143 | function connect() { |
---|
| 144 | |
---|
[294] | 145 | if( $this->ip == null ) |
---|
[138] | 146 | $this->conn = pg_connect( "dbname=".$this->dbase ); |
---|
[130] | 147 | else |
---|
[204] | 148 | $this->conn = pg_connect( "host=".$this->ip." dbname=".$this->dbase ); |
---|
[130] | 149 | } |
---|
[138] | 150 | |
---|
| 151 | 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 ) { |
---|
| 152 | |
---|
[248] | 153 | global $SEARCH_RESULT_LIMIT; |
---|
| 154 | |
---|
[251] | 155 | if( $id ) { |
---|
| 156 | $select_query = "SELECT job_id FROM jobs WHERE job_id = '$id' AND job_status = 'F'"; |
---|
| 157 | $this->resultcount = 1; |
---|
| 158 | } else { |
---|
[138] | 159 | $query_args = array(); |
---|
| 160 | |
---|
| 161 | if( $queue ) |
---|
| 162 | $query_args[] = "job_queue ='$queue'"; |
---|
| 163 | if( $user ) |
---|
| 164 | $query_args[] = "job_owner ='$user'"; |
---|
| 165 | if( $name ) |
---|
| 166 | $query_args[] = "job_name = '$name'"; |
---|
| 167 | if( $start_from_time ) |
---|
| 168 | $query_args[] = "job_start_timestamp >= $start_from_time"; |
---|
[142] | 169 | if( $start_to_time ) |
---|
[138] | 170 | $query_args[] = "job_start_timestamp <= $start_to_time"; |
---|
| 171 | if( $end_from_time ) |
---|
| 172 | $query_args[] = "job_stop_timestamp >= $end_from_time"; |
---|
| 173 | if( $end_to_time ) |
---|
| 174 | $query_args[] = "job_stop_timestamp <= $end_to_time"; |
---|
| 175 | |
---|
[248] | 176 | $query = "FROM jobs WHERE job_status = 'F' AND "; |
---|
[138] | 177 | $extra_query_args = ''; |
---|
| 178 | |
---|
| 179 | foreach( $query_args as $myquery ) { |
---|
| 180 | |
---|
| 181 | if( $extra_query_args == '' ) |
---|
| 182 | $extra_query_args = $myquery; |
---|
| 183 | else |
---|
| 184 | $extra_query_args .= " AND ".$myquery; |
---|
| 185 | } |
---|
| 186 | $query .= $extra_query_args; |
---|
| 187 | |
---|
[251] | 188 | $count_result_idname = "COUNT(job_id)"; |
---|
| 189 | $select_result_idname = "job_id"; |
---|
[140] | 190 | |
---|
[251] | 191 | $count_query = "SELECT " . $count_result_idname . " " . $query; |
---|
[248] | 192 | |
---|
[251] | 193 | $count_result = $this->queryDbase( $count_query ); |
---|
| 194 | $this->resultcount = (int) $count_result[0][count]; |
---|
[248] | 195 | |
---|
[251] | 196 | $select_query = "SELECT " . $select_result_idname . " " . $query . " ORDER BY job_id LIMIT " . $SEARCH_RESULT_LIMIT; |
---|
| 197 | } |
---|
| 198 | |
---|
[248] | 199 | $ids = $this->queryDbase( $select_query ); |
---|
| 200 | |
---|
[140] | 201 | $ret = array(); |
---|
| 202 | |
---|
| 203 | foreach( $ids as $crow) |
---|
| 204 | $ret[] = $crow[job_id]; |
---|
| 205 | |
---|
| 206 | return $ret; |
---|
[138] | 207 | } |
---|
| 208 | |
---|
| 209 | function getNodesForJob( $jobid ) { |
---|
| 210 | |
---|
| 211 | $result = $this->queryDbase( "SELECT node_id FROM job_nodes WHERE job_id = '$jobid'" ); |
---|
| 212 | |
---|
| 213 | $nodes = array(); |
---|
| 214 | |
---|
| 215 | foreach( $result as $result_row ) |
---|
| 216 | |
---|
[141] | 217 | $nodes[] = $this->getNodeArray( $result_row[node_id] ); |
---|
[138] | 218 | |
---|
| 219 | return $nodes; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | function getJobsForNode( $nodeid ) { |
---|
| 223 | |
---|
| 224 | $result = $this->queryDbase( "SELECT job_id FROM job_nodes WHERE node_id = '$nodeid'" ); |
---|
| 225 | |
---|
| 226 | $jobs = array(); |
---|
| 227 | |
---|
| 228 | foreach( $result as $result_row ) |
---|
| 229 | |
---|
[141] | 230 | $jobs[] = $this->getJobArray( $result_row[job_id] ); |
---|
[138] | 231 | |
---|
| 232 | return $jobs; |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | function getJobArray( $id ) { |
---|
| 236 | $result = $this->queryDbase( "SELECT * FROM jobs WHERE job_id = '$id'" ); |
---|
| 237 | |
---|
| 238 | return ( $this->makeArray( $result[0] ) ); |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | function getNodeArray( $id ) { |
---|
| 242 | |
---|
| 243 | $result = $this->queryDbase( "SELECT * FROM nodes WHERE node_id = '$id'" ); |
---|
| 244 | |
---|
| 245 | return ( $this->makeArray( $result[0] ) ); |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | function makeArray( $result_row ) { |
---|
| 249 | |
---|
| 250 | $myar = array(); |
---|
| 251 | |
---|
| 252 | foreach( $result_row as $mykey => $myval ) { |
---|
| 253 | |
---|
| 254 | $map_key = explode( '_', $mykey ); |
---|
| 255 | |
---|
[141] | 256 | $rmap_key = array_reverse( $map_key ); |
---|
| 257 | array_pop( $rmap_key ); |
---|
| 258 | $map_key = array_reverse( $rmap_key ); |
---|
[138] | 259 | |
---|
[141] | 260 | $newkey = implode( '_', $map_key ); |
---|
| 261 | |
---|
[138] | 262 | $myar[$newkey] = $result_row[$mykey]; |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | return $myar; |
---|
| 266 | } |
---|
| 267 | |
---|
| 268 | function queryDbase( $query ) { |
---|
| 269 | |
---|
| 270 | $result_rows = array(); |
---|
| 271 | |
---|
| 272 | if( !$this->conn ) |
---|
| 273 | $this->connect(); |
---|
| 274 | |
---|
[143] | 275 | //printf( "query = [%s]\n", $query ); |
---|
[138] | 276 | $result = pg_query( $this->conn, $query ); |
---|
| 277 | |
---|
| 278 | while ($row = pg_fetch_assoc($result)) |
---|
| 279 | $result_rows[] = $row; |
---|
| 280 | |
---|
| 281 | return $result_rows; |
---|
| 282 | } |
---|
[130] | 283 | } |
---|
| 284 | |
---|
[138] | 285 | class TarchRrdGraph { |
---|
[130] | 286 | var $rrdbin, $rrdvalues, $clustername, $hostname, $tempdir, $tarchdir, $metrics; |
---|
| 287 | |
---|
[206] | 288 | function TarchRrdGraph( $clustername, $hostname ) { |
---|
| 289 | |
---|
| 290 | global $RRDTOOL; |
---|
| 291 | global $JOB_ARCHIVE_DIR; |
---|
| 292 | |
---|
| 293 | $this->rrdbin = $RRDTOOL; |
---|
[130] | 294 | $this->rrdvalues = array(); |
---|
[206] | 295 | $this->tarchdir = $JOB_ARCHIVE_DIR; |
---|
[145] | 296 | $this->clustername = $clustername; |
---|
| 297 | $this->hostname = $hostname; |
---|
[130] | 298 | } |
---|
| 299 | |
---|
| 300 | function doCmd( $command ) { |
---|
| 301 | |
---|
| 302 | printf( "command = %s\n", $command ); |
---|
| 303 | $pipe = popen( $command . ' 2>&1', 'r' ); |
---|
| 304 | |
---|
| 305 | if (!$pipe) { |
---|
| 306 | print "pipe failed."; |
---|
| 307 | return ""; |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | $output = ''; |
---|
| 311 | while(!feof($pipe)) |
---|
| 312 | $output .= fread($pipe, 1024); |
---|
| 313 | |
---|
| 314 | pclose($pipe); |
---|
| 315 | |
---|
| 316 | $output = explode( "\n", $output ); |
---|
[135] | 317 | //print_r( $output ); |
---|
[130] | 318 | return $output; |
---|
| 319 | } |
---|
| 320 | |
---|
| 321 | function dirList( $dir ) { |
---|
| 322 | |
---|
| 323 | $dirlist = array(); |
---|
| 324 | |
---|
| 325 | if ($handle = opendir( $dir )) { |
---|
| 326 | while (false !== ($file = readdir($handle))) { |
---|
| 327 | if ($file != "." && $file != "..") { |
---|
| 328 | $dirlist[] = $file; |
---|
| 329 | } |
---|
| 330 | } |
---|
| 331 | closedir($handle); |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | return $dirlist; |
---|
| 335 | } |
---|
| 336 | |
---|
| 337 | function getTimePeriods( $start, $end ) { |
---|
| 338 | |
---|
[145] | 339 | //printf("start = %s end = %s\n", $start, $end ); |
---|
[130] | 340 | $times = array(); |
---|
| 341 | $dirlist = $this->dirList( $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname ); |
---|
[145] | 342 | |
---|
| 343 | //print_r( $dirlist ); |
---|
| 344 | |
---|
[130] | 345 | $first = 0; |
---|
| 346 | $last = 9999999999999; |
---|
| 347 | |
---|
| 348 | foreach( $dirlist as $dir ) { |
---|
| 349 | |
---|
| 350 | if( $dir > $first and $dir <= $start ) |
---|
| 351 | $first = $dir; |
---|
| 352 | if( $dir < $last and $dir >= $end ) |
---|
| 353 | $last = $dir; |
---|
| 354 | } |
---|
| 355 | |
---|
[145] | 356 | //printf( "first = %s last = %s\n", $first, $last ); |
---|
| 357 | |
---|
[130] | 358 | foreach( $dirlist as $dir ) { |
---|
| 359 | |
---|
[145] | 360 | //printf( "dir %s ", $dir ); |
---|
| 361 | |
---|
| 362 | if( $dir >= $first and $dir <= $last and !array_key_exists( $dir, $times ) ) { |
---|
| 363 | |
---|
[130] | 364 | $times[] = $dir; |
---|
[145] | 365 | //printf("newtime %s ", $dir ); |
---|
| 366 | |
---|
| 367 | } |
---|
[130] | 368 | } |
---|
| 369 | |
---|
[145] | 370 | //print_r( $times ); |
---|
| 371 | |
---|
[130] | 372 | sort( $times ); |
---|
| 373 | |
---|
[145] | 374 | //print_r( $times ); |
---|
| 375 | |
---|
[130] | 376 | return $times; |
---|
| 377 | } |
---|
| 378 | |
---|
[145] | 379 | function getRrdDirs( $start, $stop ) { |
---|
| 380 | |
---|
| 381 | //printf( "tarchdir = %s\n", $this->tarchdir ); |
---|
| 382 | $timess = $this->getTimePeriods( $start, $stop ); |
---|
| 383 | //print_r( $timess ); |
---|
| 384 | |
---|
| 385 | $rrd_files = array(); |
---|
| 386 | |
---|
| 387 | foreach( $timess as $time ) { |
---|
| 388 | |
---|
| 389 | $rrd_files[] = $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname. '/'.$time; |
---|
| 390 | } |
---|
| 391 | |
---|
| 392 | return $rrd_files; |
---|
| 393 | } |
---|
| 394 | |
---|
| 395 | function getRrdFiles( $metric, $start, $stop ) { |
---|
| 396 | |
---|
| 397 | $times = $this->getTimePeriods( $start, $stop ); |
---|
| 398 | |
---|
| 399 | $rrd_files = array(); |
---|
| 400 | |
---|
| 401 | foreach( $times as $time ) { |
---|
| 402 | |
---|
| 403 | $rrd_files[] = $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname . '/' .$time. '/' . $metric. '.rrd'; |
---|
| 404 | } |
---|
| 405 | |
---|
| 406 | return $rrd_files; |
---|
| 407 | } |
---|
| 408 | |
---|
[130] | 409 | function graph( $descr ) { |
---|
[141] | 410 | // 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 |
---|
| 411 | // 380x461 |
---|
| 412 | // monitor2:/data/toga/rrds/LISA Cluster/gb-r15n11.irc.sara.nl# |
---|
[130] | 413 | //$command = $this->rrdbin . " graph - --start $start --end $end ". |
---|
| 414 | "--width $width --height $height $upper_limit $lower_limit ". |
---|
| 415 | "--title '$title' $vertical_label $extras $background ". $series; |
---|
| 416 | |
---|
| 417 | //$graph = $this->doCmd( $command ); |
---|
| 418 | |
---|
| 419 | //return $graph; |
---|
[145] | 420 | return 0; |
---|
[130] | 421 | } |
---|
| 422 | } |
---|
| 423 | |
---|
[103] | 424 | class DataSource { |
---|
| 425 | |
---|
| 426 | var $data, $ip, $port; |
---|
| 427 | |
---|
[326] | 428 | //function DataSource( $ip = '127.0.0.1', $port = 8649 ) { |
---|
| 429 | function DataSource() { |
---|
| 430 | |
---|
| 431 | global $DATA_SOURCE; |
---|
| 432 | |
---|
| 433 | $ds_fields = explode( ':', $DATA_SOURCE ); |
---|
| 434 | |
---|
| 435 | $ds_ip = $ds_fields[0]; |
---|
| 436 | $ds_port = $ds_fields[1]; |
---|
| 437 | |
---|
| 438 | $this->ip = $ds_ip; |
---|
| 439 | $this->port = $ds_port; |
---|
| 440 | |
---|
[103] | 441 | } |
---|
| 442 | |
---|
| 443 | function getData() { |
---|
| 444 | |
---|
| 445 | $errstr; |
---|
| 446 | $errno = 0; |
---|
| 447 | $timeout = 3; |
---|
| 448 | |
---|
[313] | 449 | $fp = fsockopen( $this->ip, $this->port, $errno, $errstr, $timeout ); |
---|
[103] | 450 | |
---|
[106] | 451 | if( !$fp ) { |
---|
[103] | 452 | echo 'Unable to connect to '.$this->ip.':'.$this->port; // printf( 'Unable to connect to [%s:%.0f]', $this->ip, $this->port ); |
---|
| 453 | return; |
---|
| 454 | } |
---|
| 455 | |
---|
[177] | 456 | stream_set_timeout( $fp, 30 ); |
---|
| 457 | |
---|
[103] | 458 | while ( !feof( $fp ) ) { |
---|
| 459 | |
---|
| 460 | $data .= fread( $fp, 16384 ); |
---|
| 461 | } |
---|
| 462 | |
---|
| 463 | fclose( $fp ); |
---|
| 464 | |
---|
| 465 | return $data; |
---|
| 466 | } |
---|
| 467 | } |
---|
| 468 | |
---|
| 469 | class DataGatherer { |
---|
| 470 | |
---|
[105] | 471 | var $xmlhandler, $data, $httpvars; |
---|
[103] | 472 | |
---|
[163] | 473 | function DataGatherer( $cluster ) { |
---|
[103] | 474 | |
---|
[326] | 475 | //global $DATA_SOURCE; |
---|
[163] | 476 | |
---|
| 477 | //printf("dg cluster = %s\n", $cluster ); |
---|
[326] | 478 | //$ds_fields = explode( ':', $DATA_SOURCE ); |
---|
| 479 | //$ds_ip = $ds_fields[0]; |
---|
| 480 | //$ds_port = $ds_fields[1]; |
---|
[110] | 481 | |
---|
[326] | 482 | //$this->source = new DataSource( $ds_ip, $ds_port ); |
---|
[110] | 483 | |
---|
[326] | 484 | $this->cluster = $cluster; |
---|
[112] | 485 | $this->httpvars = $httpvars; |
---|
[103] | 486 | } |
---|
| 487 | |
---|
[326] | 488 | function parseXML( $data ) { |
---|
[103] | 489 | |
---|
[326] | 490 | //$src = &$this->source; |
---|
| 491 | //$this->data = $src->getData(); |
---|
[103] | 492 | |
---|
[326] | 493 | $this->parser = xml_parser_create(); |
---|
| 494 | $this->xmlhandler = new TorqueXMLHandler( $this->cluster ); |
---|
| 495 | |
---|
| 496 | xml_set_element_handler( $this->parser, array( &$this->xmlhandler, 'startElement' ), array( &$this->xmlhandler, 'stopElement' ) ); |
---|
| 497 | //if ( !xml_parse( $this->parser, $this->data ) ) |
---|
| 498 | if ( !xml_parse( $this->parser, $data ) ) |
---|
[313] | 499 | $error = sprintf( 'XML error: %s at %d', xml_error_string( xml_get_error_code( $this->parser ) ), xml_get_current_line_number( $this->parser ) ); |
---|
[103] | 500 | } |
---|
| 501 | |
---|
[105] | 502 | function printInfo() { |
---|
| 503 | $handler = $this->xmlhandler; |
---|
| 504 | $handler->printInfo(); |
---|
| 505 | } |
---|
| 506 | |
---|
[106] | 507 | function getNodes() { |
---|
| 508 | $handler = $this->xmlhandler; |
---|
| 509 | return $handler->getNodes(); |
---|
| 510 | } |
---|
| 511 | |
---|
[303] | 512 | function getNode( $node ) { |
---|
| 513 | $handler = $this->xmlhandler; |
---|
| 514 | return $handler->getNode( $node ); |
---|
| 515 | } |
---|
| 516 | |
---|
[124] | 517 | function getCpus() { |
---|
| 518 | $handler = $this->xmlhandler; |
---|
| 519 | return $handler->getCpus(); |
---|
| 520 | } |
---|
| 521 | |
---|
[106] | 522 | function getJobs() { |
---|
| 523 | $handler = $this->xmlhandler; |
---|
| 524 | return $handler->getJobs(); |
---|
| 525 | } |
---|
| 526 | |
---|
[303] | 527 | function getJob( $job ) { |
---|
| 528 | $handler = $this->xmlhandler; |
---|
| 529 | return $handler->getJob( $job ); |
---|
| 530 | } |
---|
| 531 | |
---|
[114] | 532 | function getHeartbeat() { |
---|
| 533 | $handler = $this->xmlhandler; |
---|
| 534 | return $handler->getHeartbeat(); |
---|
| 535 | } |
---|
[298] | 536 | |
---|
| 537 | function isJobmonRunning() { |
---|
| 538 | $handler = $this->xmlhandler; |
---|
| 539 | return $handler->isJobmonRunning(); |
---|
| 540 | } |
---|
[103] | 541 | } |
---|
| 542 | |
---|
| 543 | class TorqueXMLHandler { |
---|
| 544 | |
---|
[163] | 545 | var $clusters, $heartbeat, $nodes, $jobs, $clustername, $proc_cluster; |
---|
[104] | 546 | |
---|
[163] | 547 | function TorqueXMLHandler( $clustername ) { |
---|
[105] | 548 | $jobs = array(); |
---|
[104] | 549 | $clusters = array(); |
---|
[163] | 550 | $this->nodes = array(); |
---|
[104] | 551 | $heartbeat = array(); |
---|
[163] | 552 | $this->clustername = $clustername; |
---|
| 553 | //printf(" cluster set to %s \n", $this->clustername ); |
---|
[103] | 554 | } |
---|
| 555 | |
---|
[124] | 556 | function getCpus() { |
---|
| 557 | |
---|
| 558 | $cpus = 0; |
---|
| 559 | |
---|
[301] | 560 | if( isset( $this->jobs ) && count( $this->jobs ) > 0 ) { |
---|
[124] | 561 | |
---|
[301] | 562 | foreach( $this->jobs as $jobid=>$jobattrs ) { |
---|
[124] | 563 | |
---|
[301] | 564 | $nodes = count( $jobattrs[nodes] ); |
---|
| 565 | $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1; |
---|
| 566 | $mycpus = $nodes * $ppn; |
---|
| 567 | |
---|
| 568 | $cpus = $cpus + $mycpus; |
---|
| 569 | } |
---|
[124] | 570 | } |
---|
| 571 | } |
---|
| 572 | |
---|
[298] | 573 | function isJobmonRunning() { |
---|
| 574 | |
---|
| 575 | if (isset( $this->heartbeat['time'] )) |
---|
| 576 | return 1; |
---|
| 577 | else |
---|
| 578 | return 0; |
---|
| 579 | } |
---|
| 580 | |
---|
[103] | 581 | function startElement( $parser, $name, $attrs ) { |
---|
| 582 | |
---|
[262] | 583 | $jobs = $this->jobs; |
---|
| 584 | $nodes = $this->nodes; |
---|
[105] | 585 | |
---|
[103] | 586 | if ( $attrs[TN] ) { |
---|
| 587 | |
---|
| 588 | // Ignore dead metrics. Detect and mask failures. |
---|
| 589 | if ( $attrs[TN] > $attrs[TMAX] * 4 ) |
---|
| 590 | return; |
---|
| 591 | } |
---|
| 592 | |
---|
| 593 | $jobid = null; |
---|
| 594 | |
---|
[163] | 595 | //printf( '%s=%s', $attrs[NAME], $attrs[VAL] ); |
---|
[103] | 596 | |
---|
[163] | 597 | //printf( "clustername = %s proc_cluster = %s\n", $this->clustername, $this->proc_cluster ); |
---|
| 598 | |
---|
[104] | 599 | if( $name == 'CLUSTER' ) { |
---|
[103] | 600 | |
---|
[163] | 601 | $this->proc_cluster = $attrs[NAME]; |
---|
| 602 | //printf( "Found cluster %s\n", $attrs[NAME] ); |
---|
| 603 | //print_r( $attrs ); |
---|
[103] | 604 | |
---|
[163] | 605 | //if( !isset( $clusters[$clustername] ) ) |
---|
| 606 | // $clusters[$clustername] = array(); |
---|
[103] | 607 | |
---|
[163] | 608 | } else if( $name == 'HOST' and $this->proc_cluster == $this->clustername) { |
---|
[105] | 609 | |
---|
| 610 | $hostname = $attrs[NAME]; |
---|
| 611 | $location = $attrs[LOCATION]; |
---|
[163] | 612 | //printf( "Found node %s\n", $hostname ); |
---|
[105] | 613 | |
---|
[200] | 614 | if( !isset( $nodes[$hostname] ) ) |
---|
[326] | 615 | $nodes[$hostname] = new NodeImage( $this->proc_cluster, $hostname ); |
---|
[105] | 616 | |
---|
[219] | 617 | } else if( $name == 'METRIC' and strstr( $attrs[NAME], 'MONARCH' ) and $this->proc_cluster == $this->clustername ) { |
---|
[103] | 618 | |
---|
[219] | 619 | if( strstr( $attrs[NAME], 'MONARCH-HEARTBEAT' ) ) { |
---|
[103] | 620 | |
---|
[114] | 621 | $this->heartbeat['time'] = $attrs[VAL]; |
---|
[106] | 622 | //printf( "heartbeat %s\n", $heartbeat['time'] ); |
---|
[104] | 623 | |
---|
[219] | 624 | } else if( strstr( $attrs[NAME], 'MONARCH-JOB' ) ) { |
---|
[104] | 625 | |
---|
[253] | 626 | sscanf( $attrs[NAME], 'MONARCH-JOB-%d-%d', $jobid, $monincr ); |
---|
[104] | 627 | |
---|
[106] | 628 | //printf( "jobid %s\n", $jobid ); |
---|
[104] | 629 | |
---|
| 630 | if( !isset( $jobs[$jobid] ) ) |
---|
| 631 | $jobs[$jobid] = array(); |
---|
| 632 | |
---|
| 633 | $fields = explode( ' ', $attrs[VAL] ); |
---|
| 634 | |
---|
| 635 | foreach( $fields as $f ) { |
---|
| 636 | $togavalues = explode( '=', $f ); |
---|
| 637 | |
---|
| 638 | $toganame = $togavalues[0]; |
---|
| 639 | $togavalue = $togavalues[1]; |
---|
| 640 | |
---|
[106] | 641 | //printf( "\t%s\t= %s\n", $toganame, $togavalue ); |
---|
[104] | 642 | |
---|
[103] | 643 | if( $toganame == 'nodes' ) { |
---|
| 644 | |
---|
[135] | 645 | if( $jobs[$jobid][status] == 'R' ) { |
---|
| 646 | |
---|
| 647 | if( !isset( $jobs[$jobid][$toganame] ) ) |
---|
| 648 | $jobs[$jobid][$toganame] = array(); |
---|
[104] | 649 | |
---|
[135] | 650 | $mynodes = explode( ';', $togavalue ); |
---|
[103] | 651 | |
---|
[300] | 652 | //print_r($mynodes); |
---|
| 653 | |
---|
[262] | 654 | foreach( $mynodes as $node ) { |
---|
[103] | 655 | |
---|
[262] | 656 | if( !in_array( $node, $jobs[$jobid][$toganame] ) ) { |
---|
[253] | 657 | $jobs[$jobid][$toganame][] = $node; |
---|
[262] | 658 | } |
---|
| 659 | } |
---|
[135] | 660 | |
---|
| 661 | } else if( $jobs[$jobid][status] == 'Q' ) { |
---|
| 662 | |
---|
| 663 | $jobs[$jobid][$toganame] = $togavalue; |
---|
| 664 | } |
---|
| 665 | |
---|
[104] | 666 | } else { |
---|
[103] | 667 | |
---|
[105] | 668 | $jobs[$jobid][$toganame] = $togavalue; |
---|
[104] | 669 | } |
---|
[103] | 670 | } |
---|
[111] | 671 | |
---|
| 672 | if( isset( $jobs[$jobid][domain] ) and isset( $jobs[$jobid][nodes] ) ) { |
---|
[112] | 673 | |
---|
| 674 | $nr_nodes = count( $jobs[$jobid][nodes] ); |
---|
[300] | 675 | |
---|
| 676 | if( $jobs[$jobid][status] == 'R' ) { |
---|
[111] | 677 | |
---|
[300] | 678 | foreach( $jobs[$jobid][nodes] as $node ) { |
---|
[200] | 679 | |
---|
[300] | 680 | $domain = $jobs[$jobid][domain]; |
---|
| 681 | $domain_len = 0 - strlen( $domain ); |
---|
[200] | 682 | |
---|
[300] | 683 | if( substr( $node, $domain_len ) != $domain ) { |
---|
| 684 | $host = $node. '.'.$domain; |
---|
| 685 | } else { |
---|
| 686 | $host = $node; |
---|
| 687 | } |
---|
| 688 | |
---|
| 689 | //$host = $node.'.'.$jobs[$jobid][domain]; |
---|
[111] | 690 | |
---|
[300] | 691 | if( !isset( $nodes[$host] ) ) |
---|
[326] | 692 | $my_node = new NodeImage( $this->proc_cluster, $host ); |
---|
[300] | 693 | else |
---|
| 694 | $my_node = $nodes[$host]; |
---|
[111] | 695 | |
---|
[300] | 696 | if( !$my_node->hasJob( $jobid ) ) |
---|
[111] | 697 | |
---|
[300] | 698 | if( isset( $jobs[$jobid][ppn] ) ) |
---|
| 699 | $my_node->addJob( $jobid, ((int) $jobs[$jobid][ppn]) ); |
---|
| 700 | else |
---|
| 701 | $my_node->addJob( $jobid, 1 ); |
---|
[111] | 702 | |
---|
[300] | 703 | $nodes[$host] = $my_node; |
---|
| 704 | } |
---|
[111] | 705 | } |
---|
| 706 | } |
---|
[103] | 707 | } |
---|
| 708 | } |
---|
[114] | 709 | $this->jobs = $jobs; |
---|
[163] | 710 | //print_r( $nodes ); |
---|
| 711 | $this->nodes = $nodes; |
---|
[200] | 712 | //print_r( $this->nodes ); |
---|
[103] | 713 | } |
---|
| 714 | |
---|
| 715 | function stopElement( $parser, $name ) { |
---|
| 716 | } |
---|
[105] | 717 | |
---|
| 718 | function printInfo() { |
---|
| 719 | |
---|
| 720 | $jobs = &$this->jobs; |
---|
| 721 | |
---|
| 722 | printf( "---jobs---\n" ); |
---|
| 723 | |
---|
| 724 | foreach( $jobs as $jobid => $job ) { |
---|
| 725 | |
---|
| 726 | printf( "job %s\n", $jobid ); |
---|
| 727 | |
---|
| 728 | if( isset( $job[nodes] ) ) { |
---|
| 729 | |
---|
| 730 | foreach( $job[nodes] as $node ) { |
---|
| 731 | |
---|
| 732 | $mynode = $this->nodes[$node]; |
---|
| 733 | $hostname = $mynode->getHostname(); |
---|
| 734 | $location = $mynode->getLocation(); |
---|
| 735 | |
---|
| 736 | printf( "\t- node %s\tlocation %s\n", $hostname, $location ); |
---|
| 737 | //$this->nodes[$hostname]->setLocation( "hier draait job ".$jobid ); |
---|
| 738 | } |
---|
| 739 | } |
---|
| 740 | } |
---|
| 741 | |
---|
| 742 | printf( "---nodes---\n" ); |
---|
| 743 | |
---|
| 744 | $nodes = &$this->nodes; |
---|
| 745 | |
---|
| 746 | foreach( $nodes as $node ) { |
---|
| 747 | |
---|
| 748 | $hostname = $node->getHostname(); |
---|
| 749 | $location = $node->getLocation(); |
---|
| 750 | $jobs = implode( ' ', $node->getJobs() ); |
---|
| 751 | printf( "* node %s\tlocation %s\tjobs %s\n", $hostname, $location, $jobs ); |
---|
| 752 | } |
---|
| 753 | } |
---|
[106] | 754 | |
---|
| 755 | function getNodes() { |
---|
[163] | 756 | //print_r( $this->nodes ); |
---|
[106] | 757 | return $this->nodes; |
---|
| 758 | } |
---|
| 759 | |
---|
[303] | 760 | function getNode( $node ) { |
---|
| 761 | |
---|
| 762 | $nodes = &$this->nodes; |
---|
| 763 | if( isset( $nodes[$node] ) ) |
---|
| 764 | return $nodes[$node]; |
---|
| 765 | else |
---|
| 766 | return NULL; |
---|
| 767 | } |
---|
| 768 | |
---|
[106] | 769 | function getJobs() { |
---|
| 770 | return $this->jobs; |
---|
| 771 | } |
---|
[114] | 772 | |
---|
[303] | 773 | function getJob( $job ) { |
---|
| 774 | |
---|
| 775 | $jobs = &$this->jobs; |
---|
| 776 | if( isset( $jobs[$job] ) ) |
---|
| 777 | return $jobs[$job]; |
---|
| 778 | else |
---|
| 779 | return NULL; |
---|
| 780 | } |
---|
| 781 | |
---|
[114] | 782 | function getHeartbeat() { |
---|
| 783 | return $this->heartbeat['time']; |
---|
| 784 | } |
---|
[103] | 785 | } |
---|
| 786 | |
---|
[107] | 787 | class NodeImage { |
---|
[102] | 788 | |
---|
[122] | 789 | var $image, $x, $y, $hostname, $jobs, $tasks, $showinfo; |
---|
[102] | 790 | |
---|
[326] | 791 | function NodeImage( $cluster, $hostname ) { |
---|
[102] | 792 | |
---|
[305] | 793 | global $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
| 794 | |
---|
[111] | 795 | $this->jobs = array(); |
---|
| 796 | //$this->image = $image; |
---|
| 797 | //$this->x = $x; |
---|
| 798 | //$this->y = $y; |
---|
| 799 | $this->tasks = 0; |
---|
[110] | 800 | $this->hostname = $hostname; |
---|
[111] | 801 | $this->cpus = $this->determineCpus(); |
---|
[326] | 802 | $this->clustername = $cluster; |
---|
[122] | 803 | $this->showinfo = 1; |
---|
[305] | 804 | $this->size = $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
[102] | 805 | } |
---|
| 806 | |
---|
[111] | 807 | function addJob( $jobid, $cpus ) { |
---|
| 808 | $jobs = &$this->jobs; |
---|
| 809 | |
---|
| 810 | $jobs[] = $jobid; |
---|
| 811 | $this->jobs = $jobs; |
---|
| 812 | |
---|
| 813 | $this->addTask( $cpus ); |
---|
| 814 | } |
---|
| 815 | |
---|
| 816 | function hasJob( $jobid ) { |
---|
| 817 | |
---|
| 818 | $jobfound = 0; |
---|
| 819 | |
---|
| 820 | if( count( $this->jobs ) > 0 ) |
---|
| 821 | foreach( $this->jobs as $job ) |
---|
| 822 | |
---|
| 823 | if( $job == $jobid ) |
---|
| 824 | $jobfound = 1; |
---|
| 825 | |
---|
| 826 | return $jobfound; |
---|
| 827 | } |
---|
| 828 | |
---|
| 829 | function addTask( $cpus ) { |
---|
| 830 | |
---|
| 831 | $this->tasks = $this->tasks + $cpus; |
---|
| 832 | } |
---|
| 833 | |
---|
| 834 | function setImage( $image ) { |
---|
| 835 | |
---|
| 836 | $this->image = $image; |
---|
| 837 | } |
---|
| 838 | |
---|
[106] | 839 | function setCoords( $x, $y ) { |
---|
[107] | 840 | |
---|
[106] | 841 | $this->x = $x; |
---|
| 842 | $this->y = $y; |
---|
| 843 | } |
---|
| 844 | |
---|
[326] | 845 | function getImagemapArea() { |
---|
| 846 | |
---|
| 847 | $area_topleft = $this->x . "," . $this->y; |
---|
| 848 | $area_bottomright = ($this->x + $this->size) . "," . ($this->y + $this->size); |
---|
| 849 | $area_coords = $area_topleft . "," . $area_bottomright; |
---|
| 850 | |
---|
| 851 | $area_href = "./?c=" . $this->clustername . "&h=" . $this->hostname; |
---|
| 852 | $area_tooltip = $this->hostname . ": " . implode( " ", $this->jobs ); |
---|
| 853 | |
---|
| 854 | $tag_href = "HREF=\"" . $area_href . "\""; |
---|
| 855 | $tag_coords = "COORDS=\"" . $area_coords . "\""; |
---|
| 856 | $tag_tooltip1 = "ALT=\"" . $area_tooltip . "\""; |
---|
| 857 | $tag_tooltip2 = "TITLE=\"" . $area_tooltip . "\""; |
---|
| 858 | |
---|
| 859 | return ("<AREA SHAPE=\"RECT\" " . $tag_coords . " " . $tag_href . " " . $tag_tooltip1 . " " . $tag_tooltip2 . ">"); |
---|
| 860 | } |
---|
| 861 | |
---|
[102] | 862 | function colorHex( $color ) { |
---|
| 863 | |
---|
[109] | 864 | $my_color = imageColorAllocate( $this->image, hexdec( substr( $color, 0, 2 )), hexdec( substr( $color, 2, 2 )), hexdec( substr( $color, 4, 2 )) ); |
---|
[102] | 865 | |
---|
| 866 | return $my_color; |
---|
| 867 | } |
---|
| 868 | |
---|
[106] | 869 | function setLoad( $load ) { |
---|
| 870 | $this->load = $load; |
---|
| 871 | } |
---|
| 872 | |
---|
[108] | 873 | function setHostname( $hostname ) { |
---|
| 874 | $this->hostname = $hostname; |
---|
| 875 | } |
---|
| 876 | |
---|
[122] | 877 | function getHostname() { |
---|
| 878 | return $this->hostname; |
---|
| 879 | } |
---|
| 880 | |
---|
[114] | 881 | function getJobs() { |
---|
| 882 | return $this->jobs; |
---|
| 883 | } |
---|
| 884 | |
---|
[122] | 885 | function setShowinfo( $showinfo ) { |
---|
| 886 | $this->showinfo = $showinfo; |
---|
| 887 | } |
---|
| 888 | |
---|
[305] | 889 | function drawSmall() { |
---|
[106] | 890 | |
---|
[305] | 891 | global $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
| 892 | |
---|
| 893 | $this->size = $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
| 894 | |
---|
| 895 | $this->draw(); |
---|
[122] | 896 | } |
---|
[110] | 897 | |
---|
[122] | 898 | function drawBig() { |
---|
[111] | 899 | |
---|
[305] | 900 | global $BIG_CLUSTERIMAGE_NODEWIDTH; |
---|
| 901 | |
---|
| 902 | $this->size = $BIG_CLUSTERIMAGE_NODEWIDTH; |
---|
| 903 | |
---|
| 904 | $this->draw(); |
---|
[122] | 905 | } |
---|
[106] | 906 | |
---|
[305] | 907 | function draw() { |
---|
[106] | 908 | |
---|
[122] | 909 | global $JOB_NODE_MARKING; |
---|
[102] | 910 | |
---|
[122] | 911 | $black_color = imageColorAllocate( $this->image, 0, 0, 0 ); |
---|
[305] | 912 | $size = $this->size; |
---|
[107] | 913 | |
---|
[110] | 914 | imageFilledRectangle( $this->image, $this->x, $this->y, $this->x+($size), $this->y+($size), $black_color ); |
---|
| 915 | |
---|
[122] | 916 | if( $this->showinfo) { |
---|
| 917 | |
---|
| 918 | $this->load = $this->determineLoad(); |
---|
[111] | 919 | |
---|
[122] | 920 | if( !isset( $this->image ) or !isset( $this->x ) or !isset( $this->y ) ) { |
---|
| 921 | printf( "aborting\n" ); |
---|
| 922 | printf( "x %d y %d load %f\n", $this->x, $this->y, $load ); |
---|
| 923 | return; |
---|
| 924 | } |
---|
[111] | 925 | |
---|
| 926 | |
---|
[122] | 927 | // Convert Ganglias Hexadecimal load color to a Decimal one |
---|
| 928 | // |
---|
| 929 | $load = $this->determineLoad(); |
---|
| 930 | $usecolor = $this->colorHex( load_color($load) ); |
---|
| 931 | imageFilledRectangle( $this->image, $this->x+1, $this->y+1, $this->x+($size-1), $this->y+($size-1), $usecolor ); |
---|
| 932 | if( count( $this->jobs ) > 0 ) |
---|
[280] | 933 | imageString( $this->image, 1, $this->x+(($size/2)-1), $this->y+(($size/2)-4), $JOB_NODE_MARKING, $black_color ); |
---|
[111] | 934 | |
---|
[122] | 935 | } else { |
---|
[111] | 936 | |
---|
[122] | 937 | // White |
---|
| 938 | $usecolor = imageColorAllocate( $this->image, 255, 255, 255 ); |
---|
| 939 | imageFilledRectangle( $this->image, $this->x+1, $this->y+1, $this->x+($size-1), $this->y+($size-1), $usecolor ); |
---|
| 940 | } |
---|
| 941 | |
---|
| 942 | |
---|
[102] | 943 | } |
---|
| 944 | |
---|
[111] | 945 | function determineCpus() { |
---|
[102] | 946 | |
---|
[108] | 947 | global $metrics; |
---|
| 948 | |
---|
| 949 | $cpus = $metrics[$this->hostname][cpu_num][VAL]; |
---|
[107] | 950 | if (!$cpus) $cpus=1; |
---|
[111] | 951 | |
---|
| 952 | return $cpus; |
---|
| 953 | } |
---|
| 954 | |
---|
| 955 | function determineLoad() { |
---|
| 956 | |
---|
| 957 | global $metrics; |
---|
| 958 | |
---|
[108] | 959 | $load_one = $metrics[$this->hostname][load_one][VAL]; |
---|
[111] | 960 | $load = ((float) $load_one)/$this->cpus; |
---|
[102] | 961 | |
---|
[111] | 962 | return $load; |
---|
[106] | 963 | } |
---|
| 964 | } |
---|
| 965 | |
---|
[107] | 966 | class ClusterImage { |
---|
[106] | 967 | |
---|
[111] | 968 | var $dataget, $image, $clustername; |
---|
[124] | 969 | var $filtername, $filters; |
---|
[106] | 970 | |
---|
[326] | 971 | //function ClusterImage( $clustername ) { |
---|
| 972 | function ClusterImage( $data, $clustername ) { |
---|
[114] | 973 | |
---|
[326] | 974 | //$this->dataget = $dataget; |
---|
[305] | 975 | $this->dataget = new DataGatherer( $clustername ); |
---|
[326] | 976 | $this->data = $data; |
---|
[305] | 977 | $this->clustername = $clustername; |
---|
| 978 | $this->filters = array(); |
---|
| 979 | $this->size = 's'; |
---|
[326] | 980 | $this->width = 0; |
---|
| 981 | $this->height = 0; |
---|
| 982 | $this->output = 1; |
---|
[106] | 983 | } |
---|
| 984 | |
---|
[326] | 985 | function getWidth() { |
---|
| 986 | return $this->width; |
---|
| 987 | } |
---|
| 988 | function getHeight() { |
---|
| 989 | return $this->height; |
---|
| 990 | } |
---|
| 991 | |
---|
[305] | 992 | function setSmall() { |
---|
| 993 | $this->size = 's'; |
---|
| 994 | } |
---|
| 995 | |
---|
| 996 | function setBig() { |
---|
| 997 | $this->size = 'b'; |
---|
| 998 | } |
---|
| 999 | |
---|
[326] | 1000 | function setNoimage() { |
---|
| 1001 | $this->output = 0; |
---|
| 1002 | } |
---|
| 1003 | |
---|
[305] | 1004 | function isSmall() { |
---|
| 1005 | return ($this->size == 's'); |
---|
| 1006 | } |
---|
| 1007 | |
---|
| 1008 | function isBig() { |
---|
| 1009 | return ($this->size == 'b'); |
---|
| 1010 | } |
---|
| 1011 | |
---|
[122] | 1012 | function setFilter( $filtername, $filtervalue ) { |
---|
| 1013 | |
---|
[124] | 1014 | $this->filters[$filtername] = $filtervalue; |
---|
[122] | 1015 | } |
---|
| 1016 | |
---|
| 1017 | function filterNodes( $jobs, $nodes ) { |
---|
| 1018 | |
---|
| 1019 | $filtered_nodes = array(); |
---|
| 1020 | |
---|
| 1021 | foreach( $nodes as $node ) { |
---|
| 1022 | |
---|
| 1023 | $hostname = $node->getHostname(); |
---|
| 1024 | |
---|
[124] | 1025 | $addhost = 1; |
---|
[122] | 1026 | |
---|
[124] | 1027 | if( count( $this->filters ) > 0 ) { |
---|
| 1028 | |
---|
| 1029 | $mynjobs = $node->getJobs(); |
---|
| 1030 | |
---|
| 1031 | if( count( $mynjobs ) > 0 ) { |
---|
| 1032 | |
---|
| 1033 | foreach( $mynjobs as $myjob ) { |
---|
| 1034 | |
---|
| 1035 | foreach( $this->filters as $filtername => $filtervalue ) { |
---|
| 1036 | |
---|
| 1037 | if( $filtername!=null && $filtername!='' ) { |
---|
| 1038 | |
---|
| 1039 | if( $filtername == 'jobid' && !$node->hasJob( $filtervalue) ) { |
---|
| 1040 | $addhost = 0; |
---|
| 1041 | } else if( $filtername != 'jobid' ) { |
---|
| 1042 | if( $jobs[$myjob][$filtername] != $filtervalue ) { |
---|
| 1043 | $addhost = 0; |
---|
| 1044 | } |
---|
| 1045 | } |
---|
| 1046 | } |
---|
| 1047 | } |
---|
| 1048 | } |
---|
| 1049 | } else |
---|
| 1050 | $addhost = 0; |
---|
| 1051 | } |
---|
| 1052 | |
---|
| 1053 | if( $addhost ) |
---|
[122] | 1054 | $filtered_nodes[] = $hostname; |
---|
| 1055 | } |
---|
| 1056 | |
---|
| 1057 | return $filtered_nodes; |
---|
| 1058 | } |
---|
| 1059 | |
---|
[106] | 1060 | function draw() { |
---|
[110] | 1061 | |
---|
| 1062 | global $SMALL_CLUSTERIMAGE_MAXWIDTH, $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
[305] | 1063 | global $BIG_CLUSTERIMAGE_MAXWIDTH, $BIG_CLUSTERIMAGE_NODEWIDTH; |
---|
[339] | 1064 | global $CLUSTER_CONFS, $confcluster; |
---|
[329] | 1065 | |
---|
[339] | 1066 | global $SORTBY_HOSTNAME, $SORT_ORDER, $skan_str; |
---|
| 1067 | //global $skan_str; |
---|
[329] | 1068 | global $x_first, $y_first; |
---|
[331] | 1069 | |
---|
[337] | 1070 | foreach( $CLUSTER_CONFS as $confcluster => $conffile ) |
---|
| 1071 | { |
---|
[339] | 1072 | //printf( "cf %s cc %s\n", $this->clustername, $confcluster); |
---|
| 1073 | //printf( "cf %s cc %s\n", strtolower( trim($this->clustername)), trim($confcluster) ); |
---|
| 1074 | if( strtolower( trim($this->clustername) ) == strtolower(trim($confcluster)) ) |
---|
[337] | 1075 | { |
---|
[339] | 1076 | //printf( "cf %s cc %s\n", $conffile, $confcluster); |
---|
[337] | 1077 | include_once $conffile; |
---|
| 1078 | } |
---|
| 1079 | } |
---|
| 1080 | |
---|
[339] | 1081 | //global $SORTBY_HOSTNAME, $SORT_ORDER; |
---|
| 1082 | //global $SORT_XLABEL, $SORT_YLABEL; |
---|
[110] | 1083 | |
---|
[339] | 1084 | //printf( "SORTBY_HOSTNAME %s SORT_YLABEL %s\n", $SORTBY_HOSTNAME, $SORT_YLABEL ); |
---|
| 1085 | |
---|
[107] | 1086 | $mydatag = $this->dataget; |
---|
[326] | 1087 | $mydatag->parseXML( $this->data ); |
---|
[106] | 1088 | |
---|
[305] | 1089 | if( $this->isSmall() ) { |
---|
| 1090 | $max_width = $SMALL_CLUSTERIMAGE_MAXWIDTH; |
---|
| 1091 | $node_width = $SMALL_CLUSTERIMAGE_NODEWIDTH; |
---|
| 1092 | } else if( $this->isBig() ) { |
---|
| 1093 | $max_width = $BIG_CLUSTERIMAGE_MAXWIDTH; |
---|
| 1094 | $node_width = $BIG_CLUSTERIMAGE_NODEWIDTH; |
---|
| 1095 | } |
---|
[106] | 1096 | |
---|
| 1097 | $nodes = $mydatag->getNodes(); |
---|
[111] | 1098 | $nodes_hosts = array_keys( $nodes ); |
---|
[106] | 1099 | |
---|
| 1100 | $nodes_nr = count( $nodes ); |
---|
| 1101 | |
---|
| 1102 | $nodes_size = $nodes_nr*$node_width; |
---|
| 1103 | $node_rows = 0; |
---|
| 1104 | |
---|
| 1105 | if( $nodes_size > $max_width ) { |
---|
[107] | 1106 | $nodes_per_row = ( (int) ($max_width/$node_width) ); |
---|
[106] | 1107 | } else { |
---|
| 1108 | $nodes_per_row = $nodes_size; |
---|
| 1109 | $node_rows = 1; |
---|
| 1110 | } |
---|
| 1111 | |
---|
| 1112 | if( $nodes_per_row < $nodes_nr ) { |
---|
[107] | 1113 | $node_rows = ( (int) ($nodes_nr/$nodes_per_row) ); |
---|
| 1114 | $node_rest = fmod( $nodes_nr, $nodes_per_row ); |
---|
| 1115 | //printf( "nodesnr %d noderest %f\n", $nodes_nr, $node_rest ); |
---|
| 1116 | if( $node_rest > 0 ) { |
---|
[106] | 1117 | $node_rows++; |
---|
[107] | 1118 | //printf( "noderows %d\n", $node_rows ); |
---|
[106] | 1119 | } |
---|
| 1120 | } |
---|
| 1121 | |
---|
[306] | 1122 | $y_offset = 0; |
---|
| 1123 | $font = 2; |
---|
[329] | 1124 | $fontwidth = ImageFontWidth( $font ); |
---|
[306] | 1125 | $fontheight = ImageFontHeight( $font ); |
---|
| 1126 | $fontspaceing = 2; |
---|
| 1127 | $y_offset = $fontheight + (2 * $fontspaceing); |
---|
| 1128 | |
---|
[326] | 1129 | $this->width = $max_width; |
---|
| 1130 | $this->height = ($y_offset + (($node_rows*$node_width)+1) ); |
---|
| 1131 | |
---|
[329] | 1132 | //$image = imageCreateTrueColor( $max_width, ($y_offset + (($node_rows*$node_width)+1) ) ); |
---|
| 1133 | //$colorwhite = imageColorAllocate( $image, 255, 255, 255 ); |
---|
| 1134 | //imageFill( $image, 0, 0, $colorwhite ); |
---|
[106] | 1135 | |
---|
[329] | 1136 | //if( $this->isSmall() ) { |
---|
[306] | 1137 | |
---|
[329] | 1138 | // $colorblue = imageColorAllocate( $image, 0, 0, 255 ); |
---|
[306] | 1139 | |
---|
[329] | 1140 | // imageString( $image, $font, 2, 2, "Monarch Joblist - cluster: ".$this->clustername, $colorblue ); |
---|
| 1141 | //} |
---|
[306] | 1142 | |
---|
[122] | 1143 | $jobs = $mydatag->getJobs(); |
---|
| 1144 | //printf("filtername = %s\n", $filtername ); |
---|
| 1145 | $filtered_nodes = $this->filterNodes( $jobs, $nodes ); |
---|
| 1146 | |
---|
| 1147 | //print_r($filtered_nodes); |
---|
| 1148 | |
---|
[329] | 1149 | if( $SORTBY_HOSTNAME != "" ) |
---|
| 1150 | { |
---|
| 1151 | |
---|
| 1152 | $sorted = array(); |
---|
| 1153 | |
---|
| 1154 | $x_first = 0; |
---|
| 1155 | $y_first = 0; |
---|
| 1156 | |
---|
[339] | 1157 | $skan_str = $SORTBY_HOSTNAME; |
---|
[329] | 1158 | |
---|
[339] | 1159 | global $x_present, $y_present; |
---|
| 1160 | $x_present = false; |
---|
| 1161 | $y_present = false; |
---|
| 1162 | |
---|
| 1163 | if(stripos( $SORTBY_HOSTNAME, "{x}" ) != false ) |
---|
[329] | 1164 | { |
---|
[339] | 1165 | $x_present = true; |
---|
| 1166 | } |
---|
| 1167 | if(stripos( $SORTBY_HOSTNAME, "{y}" ) != false ) |
---|
| 1168 | { |
---|
| 1169 | $y_present = true; |
---|
| 1170 | } |
---|
| 1171 | |
---|
| 1172 | if(( strpos( $SORTBY_HOSTNAME, "{x}" ) < strpos( $SORTBY_HOSTNAME, "{y}" ) ) && ( $x_present && $y_present )) |
---|
| 1173 | { |
---|
[106] | 1174 | |
---|
[329] | 1175 | $x_first = 1; |
---|
| 1176 | } |
---|
[339] | 1177 | else if(( strpos( $SORTBY_HOSTNAME, "{x}" ) > strpos( $SORTBY_HOSTNAME, "{y}" ) ) && ( $x_present && $y_present )) |
---|
[329] | 1178 | { |
---|
| 1179 | $y_first = 1; |
---|
| 1180 | |
---|
| 1181 | } |
---|
[339] | 1182 | else if( $x_present ) |
---|
| 1183 | { |
---|
| 1184 | $x_first = 1; |
---|
| 1185 | } |
---|
| 1186 | else if( $y_present ) |
---|
| 1187 | { |
---|
| 1188 | $y_first = 1; |
---|
| 1189 | } |
---|
[329] | 1190 | |
---|
[339] | 1191 | if(( $x_first ) && ( $x_present && $y_present ) ) |
---|
| 1192 | { |
---|
| 1193 | $skan_str = str_replace( "{x}", "%d", $skan_str ); |
---|
| 1194 | $skan_str = str_replace( "{y}", "%d", $skan_str ); |
---|
| 1195 | //printf("ppoep = %s\n", $skan_str); |
---|
| 1196 | } |
---|
| 1197 | else if( $x_present) |
---|
| 1198 | { |
---|
| 1199 | $skan_str = str_replace( "{x}", "%d", $skan_str ); |
---|
| 1200 | } |
---|
| 1201 | else if( $y_present) |
---|
| 1202 | { |
---|
| 1203 | $skan_str = str_replace( "{y}", "%d", $skan_str ); |
---|
| 1204 | } |
---|
[329] | 1205 | |
---|
| 1206 | $x_min = null; |
---|
| 1207 | $x_max = null; |
---|
| 1208 | $y_min = null; |
---|
| 1209 | $y_max = null; |
---|
| 1210 | |
---|
| 1211 | foreach( $nodes as $hostname => $node ) |
---|
| 1212 | { |
---|
[404] | 1213 | $x = null; |
---|
| 1214 | $y = null; |
---|
[339] | 1215 | |
---|
| 1216 | if( $x_present && $y_present ) |
---|
[329] | 1217 | { |
---|
[339] | 1218 | //$n = sscanf( $hostname, $skan_str, $i, $j ); |
---|
| 1219 | if( $x_first ) |
---|
| 1220 | { |
---|
| 1221 | $n = sscanf( $hostname, $skan_str, $x, $y ); |
---|
| 1222 | } |
---|
| 1223 | else if( $y_first ) |
---|
| 1224 | { |
---|
| 1225 | $n = sscanf( $hostname, $skan_str, $y, $x ); |
---|
| 1226 | } |
---|
| 1227 | // Remove nodes that don't match |
---|
| 1228 | // |
---|
| 1229 | if( $n < 2 ) |
---|
| 1230 | { |
---|
[404] | 1231 | //printf( "removing node %s - x present & y present + <2 x,y matches\n", $hostname ); |
---|
[339] | 1232 | unset( $nodes[$hostname] ); |
---|
| 1233 | } |
---|
[329] | 1234 | } |
---|
[339] | 1235 | else if( $x_present && !$y_present ) |
---|
[329] | 1236 | { |
---|
[339] | 1237 | $n = sscanf( $hostname, $skan_str, $x ); |
---|
| 1238 | // Remove nodes that don't match |
---|
| 1239 | // |
---|
| 1240 | if( $n < 1 ) |
---|
| 1241 | { |
---|
[404] | 1242 | //printf( "removing node %s - x present & !y present + <1 x match\n", $hostname ); |
---|
[339] | 1243 | unset( $nodes[$hostname] ); |
---|
| 1244 | } |
---|
| 1245 | $y = 1; |
---|
[329] | 1246 | } |
---|
[339] | 1247 | else if( $y_present && !$x_present ) |
---|
| 1248 | { |
---|
| 1249 | $n = sscanf( $hostname, $skan_str, $y ); |
---|
| 1250 | // Remove nodes that don't match |
---|
| 1251 | // |
---|
| 1252 | if( $n < 1 ) |
---|
| 1253 | { |
---|
[404] | 1254 | //printf( "removing node %s - y present & !x present + <1 y match\n", $hostname ); |
---|
[339] | 1255 | unset( $nodes[$hostname] ); |
---|
| 1256 | } |
---|
| 1257 | $x = 1; |
---|
| 1258 | } |
---|
| 1259 | //printf( "xfirst %s yfirst %s\n", $x_first, $y_first ); |
---|
[329] | 1260 | |
---|
| 1261 | //printf( "n %s\n", $n ); |
---|
| 1262 | |
---|
| 1263 | |
---|
[404] | 1264 | //printf( "node %s x_min %s x %s\n", $hostname, $x_min, $x ); |
---|
| 1265 | |
---|
| 1266 | if( !$x_min && $x != null ) |
---|
[329] | 1267 | { |
---|
| 1268 | $x_min = $x; |
---|
| 1269 | } |
---|
[404] | 1270 | else if( $x < $x_min && $x != null ) |
---|
[329] | 1271 | { |
---|
| 1272 | $x_min = $x; |
---|
| 1273 | } |
---|
[404] | 1274 | if( !$x_max && $x != null ) |
---|
[329] | 1275 | { |
---|
| 1276 | $x_max = $x; |
---|
| 1277 | } |
---|
[404] | 1278 | else if( $x > $x_max && $x != null ) |
---|
[329] | 1279 | { |
---|
| 1280 | $x_max = $x; |
---|
| 1281 | } |
---|
[404] | 1282 | if( !$y_min && $y != null ) |
---|
[329] | 1283 | { |
---|
| 1284 | $y_min = $y; |
---|
| 1285 | } |
---|
[404] | 1286 | else if( $y < $y_min && $y != null ) |
---|
[329] | 1287 | { |
---|
| 1288 | $y_min = $y; |
---|
| 1289 | } |
---|
[404] | 1290 | if( !$y_max && $y != null ) |
---|
[329] | 1291 | { |
---|
| 1292 | $y_max = $y; |
---|
| 1293 | } |
---|
[404] | 1294 | else if( $y > $y_max && $y != null ) |
---|
[329] | 1295 | { |
---|
| 1296 | $y_max = $y; |
---|
| 1297 | } |
---|
| 1298 | } |
---|
| 1299 | |
---|
| 1300 | //printf( "ss %s\n", $skan_str); |
---|
| 1301 | $sorted_nodes = usort( $nodes, "cmp" ); |
---|
| 1302 | |
---|
[339] | 1303 | //print_r( $nodes ); |
---|
| 1304 | |
---|
[329] | 1305 | $cur_node = 0; |
---|
| 1306 | |
---|
[331] | 1307 | $x_offset = 0; |
---|
| 1308 | $y_offset = 0; |
---|
| 1309 | $font = 2; |
---|
| 1310 | $fontwidth = ImageFontWidth( $font ); |
---|
| 1311 | $fontheight = ImageFontHeight( $font ); |
---|
| 1312 | $fontspaceing = 2; |
---|
| 1313 | |
---|
[333] | 1314 | if( $this->isSmall() ) |
---|
| 1315 | { |
---|
| 1316 | $y_offset = $y_offset + (2 * $fontspaceing) + $fontheight; |
---|
| 1317 | } |
---|
| 1318 | |
---|
[331] | 1319 | if( $this->isBig() ) |
---|
| 1320 | { |
---|
| 1321 | |
---|
| 1322 | $y_offset = ($fontheight * (1 + strlen( $x_max) ) ) + ((2 + strlen( $x_max)) * $fontspaceing); |
---|
| 1323 | $x_offset = ($fontwidth * (1 + strlen( $y_max) ) ) + ((2 + strlen( $y_max)) * $fontspaceing); |
---|
| 1324 | |
---|
| 1325 | } |
---|
| 1326 | //$x_offset = ($fontwidth * 3) + (5 * $fontspaceing); |
---|
| 1327 | |
---|
[329] | 1328 | //printf( "xmin %s xmax %s\n", $x_min, $x_max ); |
---|
| 1329 | //printf( "ymin %s ymax %s\n", $y_min, $y_max ); |
---|
| 1330 | |
---|
| 1331 | // werkt |
---|
| 1332 | //print_r( $nodes ); |
---|
| 1333 | |
---|
[330] | 1334 | $image_width = $x_offset + ($node_width * ($x_max-$x_min+2)); |
---|
[340] | 1335 | if( $this->isBig() ) |
---|
| 1336 | { |
---|
| 1337 | $image_width = ($image_width < $this->width) ? $image_width : $this->width; |
---|
| 1338 | } |
---|
| 1339 | else if( $this->isSmall() ) |
---|
| 1340 | { |
---|
| 1341 | $image_width = $this->width; |
---|
| 1342 | } |
---|
[330] | 1343 | $image_height = $y_offset + ($node_width * ($y_max-$y_min+2)); |
---|
| 1344 | |
---|
| 1345 | $this->width = $image_width; |
---|
| 1346 | $this->heigth = $image_heigth; |
---|
| 1347 | |
---|
| 1348 | $image = imageCreateTrueColor( $image_width, $image_height ); |
---|
[329] | 1349 | $colorwhite = imageColorAllocate( $image, 255, 255, 255 ); |
---|
| 1350 | |
---|
| 1351 | imageFill( $image, 0, 0, $colorwhite ); |
---|
| 1352 | |
---|
[333] | 1353 | if( $this->isSmall() ) { |
---|
| 1354 | |
---|
| 1355 | $colorblue = imageColorAllocate( $image, 0, 0, 255 ); |
---|
| 1356 | |
---|
| 1357 | imageString( $image, $font, 2, 2, "Monarch Joblist - cluster: ".$this->clustername, $colorblue ); |
---|
| 1358 | } |
---|
| 1359 | |
---|
[339] | 1360 | if( $this->isBig() && ( isset( $SORT_XLABEL ) || isset( $SORT_YLABEL ) ) ) |
---|
[331] | 1361 | { |
---|
| 1362 | $colorblue = imageColorAllocate( $image, 0, 0, 255 ); |
---|
[329] | 1363 | |
---|
[339] | 1364 | if( isset( $SORT_XLABEL ) ) |
---|
| 1365 | { |
---|
| 1366 | imageString( $image, $font, $x_offset, $fontspaceing, $SORT_XLABEL, $colorblue ); |
---|
| 1367 | } |
---|
[329] | 1368 | |
---|
[339] | 1369 | if( isset( $SORT_YLABEL ) ) |
---|
| 1370 | { |
---|
| 1371 | // Stupid php without imageStringDown function |
---|
| 1372 | // |
---|
| 1373 | imageStringDown( $image, $font, $fontspaceing, $y_offset, $SORT_YLABEL, $colorblue ); |
---|
| 1374 | } |
---|
[331] | 1375 | } |
---|
[404] | 1376 | //print_r( $nodes ); |
---|
[329] | 1377 | |
---|
| 1378 | for( $n = $x_min; $n <= $x_max; $n++ ) |
---|
| 1379 | { |
---|
| 1380 | for( $m = $y_min; $m <= $y_max; $m++ ) |
---|
| 1381 | { |
---|
| 1382 | if( $x_min > 0 ) |
---|
| 1383 | { |
---|
| 1384 | $x = $x_offset + ( ($n-$x_min) * $node_width ); |
---|
| 1385 | } |
---|
| 1386 | if( $y_min > 0 ) |
---|
| 1387 | { |
---|
| 1388 | $y = $y_offset + ( ($m-$y_min) * $node_width ); |
---|
| 1389 | } |
---|
| 1390 | |
---|
[330] | 1391 | if( isset( $nodes[$cur_node] ) ) |
---|
| 1392 | { |
---|
[329] | 1393 | $host = $nodes[$cur_node]->getHostname(); |
---|
| 1394 | |
---|
[339] | 1395 | if( $x_present && $y_present ) |
---|
[329] | 1396 | { |
---|
[339] | 1397 | if( $x_first ) |
---|
| 1398 | { |
---|
| 1399 | $nn = sscanf( $host, $skan_str, $rx, $ry ); |
---|
| 1400 | } |
---|
| 1401 | else if( $y_first ) |
---|
| 1402 | { |
---|
| 1403 | $nn = sscanf( $host, $skan_str, $ry, $rx ); |
---|
| 1404 | } |
---|
| 1405 | if ( $nn < 2 ) |
---|
| 1406 | { |
---|
[404] | 1407 | //printf( "skipping node %s - y present & x present + <2 x,y matchs\n", $host); |
---|
[339] | 1408 | continue; |
---|
| 1409 | } |
---|
[404] | 1410 | if( intval( $rx ) > $n ) |
---|
[339] | 1411 | { |
---|
| 1412 | $m = $y_max + 1; |
---|
[404] | 1413 | //printf( "skipping node %s - y present & x present + rx %s > n %s\n", $rx, $n); |
---|
[339] | 1414 | continue; |
---|
| 1415 | } |
---|
[404] | 1416 | if( intval( $ry ) > $m ) |
---|
| 1417 | { |
---|
| 1418 | //printf( "skipping node %s - y present & x present + ry %s > m %s\n", $ry, $m); |
---|
| 1419 | continue; |
---|
| 1420 | } |
---|
[329] | 1421 | } |
---|
[339] | 1422 | else if( $x_present ) |
---|
[329] | 1423 | { |
---|
[339] | 1424 | $nn = sscanf( $host, $skan_str, $rx ); |
---|
[329] | 1425 | } |
---|
[339] | 1426 | else if( $y_present ) |
---|
[329] | 1427 | { |
---|
[339] | 1428 | $nn = sscanf( $host, $skan_str, $ry ); |
---|
[329] | 1429 | } |
---|
| 1430 | |
---|
| 1431 | if( !in_array( $host, $filtered_nodes ) ) |
---|
[404] | 1432 | { |
---|
[405] | 1433 | //printf( "setting node %s showinfo to 0 - not found in filtered_nodes", $host); |
---|
[329] | 1434 | $nodes[$cur_node]->setShowinfo( 0 ); |
---|
[404] | 1435 | } |
---|
[329] | 1436 | |
---|
| 1437 | $nodes[$cur_node]->setCoords( $x, $y ); |
---|
| 1438 | $nodes[$cur_node]->setImage( $image ); |
---|
| 1439 | |
---|
| 1440 | //print_r( $nodes[$cur_node] ); |
---|
| 1441 | |
---|
| 1442 | if( $this->isSmall() ) |
---|
| 1443 | $nodes[$cur_node]->drawSmall(); |
---|
| 1444 | else if( $this->isBig() ) |
---|
| 1445 | $nodes[$cur_node]->drawBig(); |
---|
[404] | 1446 | |
---|
| 1447 | $cur_node++; |
---|
[329] | 1448 | } |
---|
[333] | 1449 | if( $this->isBig() ) |
---|
[332] | 1450 | { |
---|
[339] | 1451 | if(( $n == $x_min ) && ( isset($SORT_YLABEL) ) ) |
---|
[333] | 1452 | { |
---|
| 1453 | $mfontspacing = 1; |
---|
| 1454 | $ylabel_x = $x - ( $fontwidth * strlen( $y_max ) ) - $mfontspacing; |
---|
| 1455 | $ylabel_y = $y; |
---|
[332] | 1456 | |
---|
[333] | 1457 | imageString( $image, $font, $ylabel_x, $ylabel_y, strval( $m ), $colorblue ); |
---|
| 1458 | } |
---|
[339] | 1459 | if(( $m == $y_min ) && ( isset($SORT_XLABEL) ) ) |
---|
[333] | 1460 | { |
---|
| 1461 | $mfontspacing = 2; |
---|
| 1462 | $xlabel_y = $y - ( $fontheight * strlen( $x_max ) ); |
---|
| 1463 | $xlabel_x = $x + $mfontspacing; |
---|
[332] | 1464 | |
---|
[333] | 1465 | imageStringDown( $image, $font, $xlabel_x, $xlabel_y, strval( $n ), $colorblue ); |
---|
| 1466 | } |
---|
[332] | 1467 | } |
---|
| 1468 | |
---|
[329] | 1469 | } |
---|
| 1470 | } |
---|
| 1471 | |
---|
| 1472 | } |
---|
| 1473 | else |
---|
| 1474 | { |
---|
| 1475 | $image = imageCreateTrueColor( $max_width, ($y_offset + (($node_rows*$node_width)+1) ) ); |
---|
| 1476 | $colorwhite = imageColorAllocate( $image, 255, 255, 255 ); |
---|
| 1477 | |
---|
| 1478 | imageFill( $image, 0, 0, $colorwhite ); |
---|
| 1479 | |
---|
| 1480 | if( $this->isSmall() ) { |
---|
| 1481 | |
---|
| 1482 | $colorblue = imageColorAllocate( $image, 0, 0, 255 ); |
---|
| 1483 | |
---|
| 1484 | imageString( $image, $font, 2, 2, "Monarch Joblist - cluster: ".$this->clustername, $colorblue ); |
---|
| 1485 | } |
---|
| 1486 | |
---|
| 1487 | for( $n = 0; $n < $node_rows; $n++ ) { |
---|
[107] | 1488 | |
---|
[329] | 1489 | for( $m = 0; $m < $nodes_per_row; $m++ ) { |
---|
| 1490 | |
---|
| 1491 | $x = ($m * $node_width); |
---|
| 1492 | $y = $y_offset + ($n * $node_width); |
---|
[107] | 1493 | |
---|
[329] | 1494 | $cur_node = ($n * $nodes_per_row) + ($m); |
---|
| 1495 | $host = $nodes_hosts[$cur_node]; |
---|
[107] | 1496 | |
---|
[329] | 1497 | if( isset( $nodes[$host] ) ) { |
---|
[111] | 1498 | |
---|
[329] | 1499 | $nodes[$host]->setCoords( $x, $y ); |
---|
| 1500 | $nodes[$host]->setImage( $image ); |
---|
[122] | 1501 | |
---|
[329] | 1502 | if( !in_array( $host, $filtered_nodes ) ) |
---|
[404] | 1503 | { |
---|
[329] | 1504 | $nodes[$host]->setShowinfo( 0 ); |
---|
[404] | 1505 | } |
---|
[122] | 1506 | |
---|
[329] | 1507 | if( $this->isSmall() ) |
---|
| 1508 | $nodes[$host]->drawSmall(); |
---|
| 1509 | else if( $this->isBig() ) |
---|
| 1510 | $nodes[$host]->drawBig(); |
---|
| 1511 | } |
---|
[111] | 1512 | } |
---|
[106] | 1513 | } |
---|
| 1514 | } |
---|
[326] | 1515 | |
---|
| 1516 | $this->nodes = &$nodes; |
---|
| 1517 | |
---|
| 1518 | if ($this->output) { |
---|
| 1519 | header( 'Content-type: image/png' ); |
---|
| 1520 | imagePNG( $image ); |
---|
| 1521 | imageDestroy( $image ); |
---|
| 1522 | } |
---|
[102] | 1523 | } |
---|
[326] | 1524 | |
---|
| 1525 | function getImagemapArea() { |
---|
| 1526 | |
---|
| 1527 | $clusterimage_map = ""; |
---|
| 1528 | |
---|
| 1529 | foreach( $this->nodes as $hostname => $node ) { |
---|
| 1530 | |
---|
| 1531 | $node_map = $node->getImagemapArea(); |
---|
| 1532 | $clusterimage_map .= $node_map; |
---|
| 1533 | } |
---|
| 1534 | |
---|
| 1535 | return $clusterimage_map; |
---|
| 1536 | } |
---|
[102] | 1537 | } |
---|
| 1538 | |
---|
[298] | 1539 | class EmptyImage { |
---|
| 1540 | |
---|
| 1541 | function draw() { |
---|
| 1542 | $image = imageCreateTrueColor( 1, 1 ); |
---|
| 1543 | $colorwhite = imageColorAllocate( $image, 255, 255, 255 ); |
---|
| 1544 | imageFill( $image, 0, 0, $colorwhite ); |
---|
| 1545 | |
---|
| 1546 | header( 'Content-type: image/png' ); |
---|
| 1547 | imagePNG( $image ); |
---|
| 1548 | imageDestroy( $image ); |
---|
| 1549 | } |
---|
| 1550 | } |
---|
| 1551 | |
---|
[303] | 1552 | class HostImage { |
---|
[106] | 1553 | |
---|
[303] | 1554 | var $data_gather, $cluster, $host, $node, $image; |
---|
| 1555 | var $headerstrlen; |
---|
| 1556 | |
---|
| 1557 | function HostImage( $data_gather, $cluster, $host ) { |
---|
| 1558 | |
---|
| 1559 | $this->data_gather = $data_gather; |
---|
| 1560 | $this->cluster = $cluster; |
---|
| 1561 | $this->host = $host; |
---|
| 1562 | $this->y_offset = 0; |
---|
| 1563 | $this->font = 2; |
---|
| 1564 | $this->fontspaceing = 2; |
---|
| 1565 | $this->headerstrlen = array(); |
---|
| 1566 | |
---|
| 1567 | $this->fontheight = ImageFontHeight( $this->font ); |
---|
| 1568 | $this->fontwidth = ImageFontWidth( $this->font ); |
---|
| 1569 | |
---|
| 1570 | $dg = &$this->data_gather; |
---|
| 1571 | $this->node = &$dg->getNode( $this->host ); |
---|
| 1572 | $n = &$this->node; |
---|
| 1573 | $this->njobs = $n->getJobs(); |
---|
| 1574 | } |
---|
| 1575 | |
---|
| 1576 | function drawJobs() { |
---|
| 1577 | |
---|
| 1578 | $dg = &$this->data_gather; |
---|
| 1579 | $colorblack = imageColorAllocate( $this->image, 0, 0, 0 ); |
---|
| 1580 | |
---|
| 1581 | for( $n = 0; $n < count( $this->njobs ); $n++ ) { |
---|
| 1582 | |
---|
| 1583 | $jobid = $this->njobs[$n]; |
---|
| 1584 | $jobinfo = $dg->getJob( $jobid ); |
---|
| 1585 | |
---|
| 1586 | $xoffset = 5; |
---|
| 1587 | imageString( $this->image, $this->font, $xoffset, $this->y_offset, strval( $jobid ), $colorblack ); |
---|
| 1588 | |
---|
| 1589 | foreach( $this->headerstrlen as $headername => $headerlen ) { |
---|
| 1590 | |
---|
| 1591 | if( $headername == 'nodes' ) { |
---|
| 1592 | $attrval = strval( count( $jobinfo[nodes] ) ); |
---|
| 1593 | } else if( $headername == 'cpus' ) { |
---|
| 1594 | |
---|
| 1595 | if( !isset( $jobinfo[ppn] ) ) |
---|
| 1596 | $jobinfo[ppn] = 1; |
---|
| 1597 | |
---|
| 1598 | $attrval = strval( count( $jobinfo[nodes] ) * intval( $jobinfo[ppn] ) ); |
---|
| 1599 | |
---|
| 1600 | } else if( $headername == 'runningtime' ) { |
---|
| 1601 | $attrval = makeTime( intval( $jobinfo[reported] ) - intval( $jobinfo[start_timestamp] ) ); |
---|
| 1602 | } else { |
---|
| 1603 | $attrval = strval( $jobinfo[$headername] ); |
---|
| 1604 | } |
---|
| 1605 | |
---|
| 1606 | imageString( $this->image, $this->font, $xoffset, $this->y_offset, $attrval, $colorblack ); |
---|
| 1607 | |
---|
| 1608 | $xoffset = $xoffset + ($this->fontwidth * ( $headerlen + 1 ) ); |
---|
| 1609 | |
---|
| 1610 | } |
---|
| 1611 | |
---|
| 1612 | $this->newLineOffset(); |
---|
| 1613 | } |
---|
| 1614 | } |
---|
| 1615 | |
---|
| 1616 | function drawHeader() { |
---|
| 1617 | |
---|
| 1618 | $dg = &$this->data_gather; |
---|
| 1619 | |
---|
| 1620 | for( $n = 0; $n < count( $this->njobs ); $n++ ) { |
---|
| 1621 | |
---|
| 1622 | $jobid = $this->njobs[$n]; |
---|
| 1623 | $jobinfo = $dg->getJob( $jobid ); |
---|
| 1624 | |
---|
| 1625 | if( !isset( $this->headerstrlen[id] ) ) |
---|
| 1626 | $this->headerstrlen[id] = strlen( strval( $jobid ) ); |
---|
| 1627 | else |
---|
| 1628 | if( strlen( strval( $jobid ) ) > $this->headerstrlen[id] ) |
---|
| 1629 | $this->headerstrlen[id] = strlen( strval( $jobid ) ); |
---|
| 1630 | |
---|
| 1631 | if( !isset( $this->headerstrlen[owner] ) ) |
---|
| 1632 | $this->headerstrlen[owner] = strlen( strval( $jobinfo[owner] ) ); |
---|
| 1633 | else |
---|
| 1634 | if( strlen( strval( $jobinfo[owner] ) ) > $this->headerstrlen[owner] ) |
---|
| 1635 | $this->headerstrlen[owner] = strlen( strval( $jobinfo[owner] ) ); |
---|
| 1636 | |
---|
| 1637 | if( !isset( $this->headerstrlen[queue] ) ) |
---|
| 1638 | $this->headerstrlen[queue] = strlen( strval( $jobinfo[queue] ) ); |
---|
| 1639 | else |
---|
| 1640 | if( strlen( strval( $jobinfo[queue] ) ) > $this->headerstrlen[queue] ) |
---|
| 1641 | $this->headerstrlen[queue] = strlen( strval( $jobinfo[queue] ) ); |
---|
| 1642 | |
---|
| 1643 | if( !isset( $jobinfo[ppn] ) ) |
---|
| 1644 | $jobinfo[ppn] = 1; |
---|
| 1645 | |
---|
| 1646 | $cpus = count( $jobinfo[nodes] ) * intval( $jobinfo[ppn] ); |
---|
| 1647 | |
---|
| 1648 | if( !isset( $this->headerstrlen[cpus] ) ) |
---|
| 1649 | $this->headerstrlen[cpus] = strlen( strval( $cpus ) ); |
---|
| 1650 | else |
---|
| 1651 | if( strlen( strval( $cpus ) ) > $this->headerstrlen[cpus] ) |
---|
| 1652 | $this->headerstrlen[cpus] = strlen( strval( $cpus ) ); |
---|
| 1653 | |
---|
| 1654 | $nodes = count( $jobinfo[nodes] ); |
---|
| 1655 | |
---|
| 1656 | if( !isset( $this->headerstrlen[nodes] ) ) |
---|
| 1657 | $this->headerstrlen[nodes] = strlen( strval( $nodes ) ); |
---|
| 1658 | else |
---|
| 1659 | if( strlen( strval( $nodes) ) > $this->headerstrlen[nodes] ) |
---|
| 1660 | $this->headerstrlen[nodes] = strlen( strval( $nodes ) ); |
---|
| 1661 | |
---|
| 1662 | $runningtime = makeTime( intval( $jobinfo[reported] ) - intval( $jobinfo[start_timestamp] ) ); |
---|
| 1663 | |
---|
| 1664 | if( !isset( $this->headerstrlen[runningtime] ) ) |
---|
| 1665 | $this->headerstrlen[runningtime] = strlen( strval( $runningtime) ); |
---|
| 1666 | else |
---|
| 1667 | if( strlen( strval( $runningtime) ) > $this->headerstrlen[runningtime] ) |
---|
| 1668 | $this->headerstrlen[runningtime] = strlen( strval( $runningtime) ); |
---|
| 1669 | |
---|
| 1670 | if( !isset( $this->headerstrlen[name] ) ) |
---|
| 1671 | $this->headerstrlen[name] = strlen( strval( $jobinfo[name] ) ); |
---|
| 1672 | else |
---|
| 1673 | if( strlen( strval( $jobinfo[name] ) ) > $this->headerstrlen[name] ) |
---|
| 1674 | $this->headerstrlen[name] = strlen( strval( $jobinfo[name] ) ); |
---|
| 1675 | |
---|
| 1676 | } |
---|
| 1677 | |
---|
| 1678 | $xoffset = 5; |
---|
| 1679 | |
---|
[350] | 1680 | foreach( $this->headerstrlen as $headername => $headerlen ) { |
---|
[303] | 1681 | |
---|
| 1682 | $colorgreen = imageColorAllocate( $this->image, 0, 200, 0 ); |
---|
| 1683 | |
---|
| 1684 | if( $headerlen < strlen( $headername ) ) |
---|
[350] | 1685 | $this->headerstrlen[$headername] = strlen( $headername ); |
---|
[303] | 1686 | |
---|
[426] | 1687 | imageString( $this->image, $this->font, $xoffset, $this->y_offset, ucfirst( $headername ), $colorgreen ); |
---|
[303] | 1688 | |
---|
[426] | 1689 | $xoffset = $xoffset + ($this->fontwidth * ( $this->headerstrlen[$headername] + 1 ) ); |
---|
| 1690 | |
---|
[303] | 1691 | } |
---|
| 1692 | $this->newLineOffset(); |
---|
| 1693 | } |
---|
| 1694 | |
---|
| 1695 | function newLineOffset() { |
---|
| 1696 | |
---|
| 1697 | $this->y_offset = $this->y_offset + $this->fontheight + $this->fontspaceing; |
---|
| 1698 | } |
---|
| 1699 | |
---|
| 1700 | function draw() { |
---|
| 1701 | |
---|
| 1702 | $xlen = 450; |
---|
| 1703 | $ylen = ( count( $this->njobs ) * ( $this->fontheight + $this->fontspaceing ) ) + (3 * $this->fontheight); |
---|
| 1704 | |
---|
| 1705 | $this->image = imageCreateTrueColor( $xlen, $ylen ); |
---|
| 1706 | $colorwhite = imageColorAllocate( $this->image, 255, 255, 255 ); |
---|
| 1707 | imageFill( $this->image, 0, 0, $colorwhite ); |
---|
| 1708 | |
---|
| 1709 | $colorblue = imageColorAllocate( $this->image, 0, 0, 255 ); |
---|
| 1710 | |
---|
| 1711 | imageString( $this->image, $this->font, 1, $this->y_offset, "Monarch Joblist - host: ".$this->host, $colorblue ); |
---|
| 1712 | $this->newLineOffset(); |
---|
| 1713 | |
---|
| 1714 | $this->drawHeader(); |
---|
| 1715 | $this->drawJobs(); |
---|
| 1716 | |
---|
| 1717 | header( 'Content-type: image/png' ); |
---|
| 1718 | imagePNG( $this->image ); |
---|
| 1719 | imageDestroy( $this->image ); |
---|
| 1720 | } |
---|
| 1721 | } |
---|
| 1722 | |
---|
[331] | 1723 | function imageStringDown( &$image, $font, $x, $y, &$s, &$col ) |
---|
| 1724 | { |
---|
| 1725 | $fw = imagefontwidth( $font); |
---|
| 1726 | $fh = imagefontheight( $font); |
---|
| 1727 | |
---|
| 1728 | $fontspacing = 0; |
---|
| 1729 | |
---|
| 1730 | $fx = $x; |
---|
| 1731 | $fy = $y; |
---|
| 1732 | |
---|
| 1733 | for( $n=0; $n<strlen( $s ); $n++ ) |
---|
| 1734 | { |
---|
| 1735 | $myc = $s{$n}; |
---|
| 1736 | |
---|
| 1737 | imagestring( $image, $font, $fx, $fy, $myc, $col ); |
---|
| 1738 | |
---|
| 1739 | $fy += ($fontspacing + $fh ); |
---|
| 1740 | } |
---|
| 1741 | } |
---|
| 1742 | |
---|
[329] | 1743 | function array_rem( $val, &$arr ) |
---|
| 1744 | { |
---|
| 1745 | // Delete val from arr |
---|
| 1746 | // |
---|
| 1747 | $i = array_search( $val, $arr ); |
---|
| 1748 | |
---|
| 1749 | if( $i == false ) return false; |
---|
| 1750 | |
---|
| 1751 | $arr = array_merge( array_slice( $arr, 0, $i ), array_slice( $arr, $i+1, count( $arr ) ) ); |
---|
| 1752 | |
---|
| 1753 | return true; |
---|
| 1754 | } |
---|
| 1755 | |
---|
| 1756 | function cmp( $a, $b ) |
---|
| 1757 | { |
---|
| 1758 | global $SORT_ORDER; |
---|
| 1759 | global $skan_str; |
---|
| 1760 | global $x_first, $y_first; |
---|
[339] | 1761 | global $x_present, $y_present; |
---|
[329] | 1762 | |
---|
[339] | 1763 | //printf("ppoep = %s\n", $skan_str); |
---|
[329] | 1764 | $a_node = $a; |
---|
| 1765 | $b_node = $b; |
---|
| 1766 | $a = $a_node->getHostname(); |
---|
| 1767 | $b = $b_node->getHostname(); |
---|
| 1768 | |
---|
| 1769 | if( $a == $b ) return 0; |
---|
| 1770 | |
---|
[339] | 1771 | $a_x = 0; |
---|
| 1772 | $b_x = 0; |
---|
| 1773 | $a_y = 0; |
---|
| 1774 | $b_y = 0; |
---|
| 1775 | |
---|
| 1776 | if( $x_present && $y_present ) |
---|
[329] | 1777 | { |
---|
[339] | 1778 | if( $x_first ) |
---|
| 1779 | { |
---|
| 1780 | $n = sscanf( $a, $skan_str, $a_x, $a_y ); |
---|
| 1781 | $n = sscanf( $b, $skan_str, $b_x, $b_y ); |
---|
| 1782 | } |
---|
| 1783 | else if( $y_first ) |
---|
| 1784 | { |
---|
| 1785 | $n = sscanf( $a, $skan_str, $a_y, $a_x ); |
---|
| 1786 | $n = sscanf( $b, $skan_str, $b_y, $b_x ); |
---|
| 1787 | } |
---|
| 1788 | } |
---|
| 1789 | else if( $x_present && !$y_present ) |
---|
| 1790 | { |
---|
| 1791 | $n = sscanf( $a, $skan_str, $a_x ); |
---|
| 1792 | $n = sscanf( $b, $skan_str, $b_x ); |
---|
[329] | 1793 | } |
---|
[339] | 1794 | else if( $y_present && !$x_present ) |
---|
[329] | 1795 | { |
---|
[339] | 1796 | $n = sscanf( $a, $skan_str, $a_y ); |
---|
| 1797 | $n = sscanf( $b, $skan_str, $b_y ); |
---|
[329] | 1798 | } |
---|
| 1799 | |
---|
| 1800 | if ( $SORT_ORDER=="desc" ) |
---|
| 1801 | { |
---|
| 1802 | |
---|
[339] | 1803 | if( $x_present && $y_present ) |
---|
[329] | 1804 | { |
---|
[339] | 1805 | // 1 = a < b |
---|
| 1806 | // -1 = a > b |
---|
| 1807 | // |
---|
| 1808 | if ($a_x == $b_x) |
---|
[329] | 1809 | { |
---|
[339] | 1810 | if ($a_y < $b_y) |
---|
| 1811 | { |
---|
| 1812 | return 1; |
---|
| 1813 | } |
---|
| 1814 | else if ($a_y > $b_y) |
---|
| 1815 | { |
---|
| 1816 | return -1; |
---|
| 1817 | } |
---|
| 1818 | } |
---|
| 1819 | else if ($a_x < $b_x) |
---|
| 1820 | { |
---|
[329] | 1821 | return 1; |
---|
| 1822 | } |
---|
[339] | 1823 | else if ($a_x > $b_x) |
---|
[329] | 1824 | { |
---|
| 1825 | return -1; |
---|
| 1826 | } |
---|
[339] | 1827 | } |
---|
| 1828 | else if( $x_present && !$y_present ) |
---|
[329] | 1829 | { |
---|
[339] | 1830 | if ($a_x < $b_x) |
---|
| 1831 | { |
---|
| 1832 | return 1; |
---|
| 1833 | } |
---|
| 1834 | else if ($a_x > $b_x) |
---|
| 1835 | { |
---|
| 1836 | return -1; |
---|
| 1837 | } |
---|
[329] | 1838 | } |
---|
[339] | 1839 | else if( $y_present && !$x_present ) |
---|
[329] | 1840 | { |
---|
[339] | 1841 | if ($a_y < $b_y) |
---|
| 1842 | { |
---|
| 1843 | return 1; |
---|
| 1844 | } |
---|
| 1845 | else if ($a_y > $b_y) |
---|
| 1846 | { |
---|
| 1847 | return -1; |
---|
| 1848 | } |
---|
[329] | 1849 | } |
---|
| 1850 | } |
---|
| 1851 | else if ( $SORT_ORDER == "asc" ) |
---|
| 1852 | { |
---|
| 1853 | |
---|
[339] | 1854 | if( $x_present && $y_present ) |
---|
[329] | 1855 | { |
---|
[339] | 1856 | // 1 = a > b |
---|
| 1857 | // -1 = a < b |
---|
| 1858 | // |
---|
| 1859 | if ($a_x == $b_x) |
---|
[329] | 1860 | { |
---|
[339] | 1861 | if ($a_y > $b_y) |
---|
| 1862 | { |
---|
| 1863 | return 1; |
---|
| 1864 | } |
---|
| 1865 | else if ($a_y < $b_y) |
---|
| 1866 | { |
---|
| 1867 | return -1; |
---|
| 1868 | } |
---|
| 1869 | } |
---|
| 1870 | else if ($a_x > $b_x) |
---|
| 1871 | { |
---|
[329] | 1872 | return 1; |
---|
| 1873 | } |
---|
[339] | 1874 | else if ($a_x < $b_x) |
---|
[329] | 1875 | { |
---|
| 1876 | return -1; |
---|
| 1877 | } |
---|
| 1878 | } |
---|
[339] | 1879 | else if( $x_present && !$y_present ) |
---|
[329] | 1880 | { |
---|
[339] | 1881 | if ($a_x > $b_x) |
---|
| 1882 | { |
---|
| 1883 | return 1; |
---|
| 1884 | } |
---|
| 1885 | else if ($a_x < $b_x) |
---|
| 1886 | { |
---|
| 1887 | return -1; |
---|
| 1888 | } |
---|
[329] | 1889 | } |
---|
[339] | 1890 | else if( $y_present && !$x_present ) |
---|
[329] | 1891 | { |
---|
[339] | 1892 | if ($a_y > $b_y) |
---|
| 1893 | { |
---|
| 1894 | return 1; |
---|
| 1895 | } |
---|
| 1896 | else if ($a_y < $b_y) |
---|
| 1897 | { |
---|
| 1898 | return -1; |
---|
| 1899 | } |
---|
[329] | 1900 | } |
---|
| 1901 | } |
---|
| 1902 | } |
---|
[303] | 1903 | function makeTime( $time ) { |
---|
| 1904 | |
---|
| 1905 | $days = intval( $time / 86400 ); |
---|
| 1906 | $time = ($days>0) ? $time % ($days * 86400) : $time; |
---|
| 1907 | |
---|
| 1908 | //printf( "time = %s, days = %s\n", $time, $days ); |
---|
| 1909 | |
---|
| 1910 | $date_str = ''; |
---|
| 1911 | $day_str = ''; |
---|
| 1912 | |
---|
| 1913 | if( $days > 0 ) { |
---|
| 1914 | if( $days > 1 ) |
---|
| 1915 | $day_str .= $days . ' days'; |
---|
| 1916 | else |
---|
| 1917 | $day_str .= $days . ' day'; |
---|
| 1918 | } |
---|
| 1919 | |
---|
| 1920 | $hours = intval( $time / 3600 ); |
---|
| 1921 | $time = $hours ? $time % ($hours * 3600) : $time; |
---|
| 1922 | |
---|
| 1923 | //printf( "time = %s, days = %s, hours = %s\n", $time, $days, $hours ); |
---|
| 1924 | if( $hours > 0 ) { |
---|
| 1925 | $date_str .= $hours . ':'; |
---|
| 1926 | $date_unit = 'hours'; |
---|
| 1927 | } |
---|
| 1928 | |
---|
| 1929 | $minutes = intval( $time / 60 ); |
---|
| 1930 | $seconds = $minutes ? $time % ($minutes * 60) : $time; |
---|
| 1931 | |
---|
| 1932 | if( $minutes > 0 ) { |
---|
| 1933 | |
---|
| 1934 | if( $minutes >= 10 ) |
---|
| 1935 | $date_str .= $minutes . ':'; |
---|
| 1936 | else |
---|
| 1937 | $date_str .= '0' . $minutes . ':'; |
---|
| 1938 | |
---|
| 1939 | $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit; |
---|
| 1940 | } else { |
---|
| 1941 | if($hours > 0 ) { |
---|
| 1942 | $date_str .= '00:'; |
---|
| 1943 | $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit; |
---|
| 1944 | } |
---|
| 1945 | } |
---|
| 1946 | |
---|
| 1947 | |
---|
| 1948 | $date_unit = (!isset($date_unit)) ? 'seconds' : $date_unit; |
---|
| 1949 | |
---|
| 1950 | if( $seconds > 0 ) { |
---|
| 1951 | |
---|
| 1952 | if( $seconds >= 10 ) |
---|
| 1953 | $date_str .= $seconds . ' ' . $date_unit; |
---|
| 1954 | else |
---|
| 1955 | $date_str .= '0' . $seconds . ' ' . $date_unit; |
---|
| 1956 | |
---|
| 1957 | } else if ( $hours > 0 or $minutes > 0 ) |
---|
| 1958 | |
---|
| 1959 | $date_str .= '00 ' . $date_unit; |
---|
| 1960 | |
---|
| 1961 | if( $days > 0) { |
---|
| 1962 | |
---|
| 1963 | if( $hours > 0 or $minutes > 0 or $seconds > 0 ) |
---|
| 1964 | $date_str = $day_str . ' - ' . $date_str; |
---|
| 1965 | else |
---|
| 1966 | $date_str = $day_str; |
---|
| 1967 | } |
---|
| 1968 | |
---|
| 1969 | return $date_str; |
---|
| 1970 | } |
---|
[102] | 1971 | ?> |
---|