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