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