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