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