[532] | 1 | <?php |
---|
| 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 | * |
---|
| 22 | * SVN $Id: overview.php 530 2008-07-02 11:17:49Z ramonb $ |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | global $GANGLIA_PATH, $clustername, $tpl, $filter, $cluster, $get_metric_string, $cluster_url, $sh; |
---|
| 26 | global $hosts_up, $m, $start, $end, $filterorder, $COLUMN_REQUESTED_MEMORY, $COLUMN_QUEUED, $COLUMN_NODES, $hostname, $piefilter; |
---|
| 27 | global $longtitle, $title, $range; |
---|
| 28 | |
---|
| 29 | $tpl->assign( "clustername", $clustername ); |
---|
| 30 | |
---|
| 31 | if( $JOB_ARCHIVE ) |
---|
| 32 | { |
---|
| 33 | $tpl->assign( "cluster_url", rawurlencode($clustername) ); |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | $ds = new DataSource(); |
---|
| 37 | $myxml_data = $ds->getData(); |
---|
| 38 | |
---|
| 39 | $data_gatherer = new DataGatherer( $clustername ); |
---|
| 40 | $data_gatherer->parseXML( $myxml_data ); |
---|
| 41 | |
---|
| 42 | $heartbeat = $data_gatherer->getHeartbeat(); |
---|
| 43 | $jobs = $data_gatherer->getJobs(); |
---|
| 44 | $gnodes = $data_gatherer->getNodes(); |
---|
| 45 | $cpus = $data_gatherer->getCpus(); |
---|
| 46 | $use_fqdn = $data_gatherer->getUsingFQDN(); |
---|
| 47 | |
---|
| 48 | include("./lib/pchart/pData.class"); |
---|
| 49 | include("./lib/pchart/pChart.class"); |
---|
| 50 | |
---|
| 51 | function setupFilterSettings() |
---|
| 52 | { |
---|
| 53 | |
---|
| 54 | global $tpl, $filter, $clustername, $piefilter, $data_gatherer, $myxml_data, $filterorder; |
---|
| 55 | |
---|
| 56 | $filter_image_url = ""; |
---|
| 57 | |
---|
| 58 | $tpl->gotoBlock( "_ROOT" ); |
---|
| 59 | |
---|
| 60 | foreach( $filter as $filtername => $filtervalue ) |
---|
| 61 | { |
---|
| 62 | $tpl->assign( "f_".$filtername, $filtervalue ); |
---|
| 63 | |
---|
| 64 | $filter_image_url .= "&$filtername=$filtervalue"; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | session_start(); |
---|
| 68 | |
---|
| 69 | unset( $_SESSION["data"] ); |
---|
| 70 | $_SESSION["data"] = &$myxml_data; |
---|
| 71 | |
---|
| 72 | $ic = new ClusterImage( $myxml_data, $clustername ); |
---|
| 73 | |
---|
| 74 | $ic->setBig(); |
---|
| 75 | $ic->setNoimage(); |
---|
| 76 | $ic->draw(); |
---|
| 77 | |
---|
| 78 | $tpl->assign( "clusterimage", "./image.php?". session_name() . "=" . session_id() ."&c=".rawurlencode($clustername)."&view=big-clusterimage".$filter_image_url ); |
---|
| 79 | |
---|
| 80 | //$tpl->assign( "clusterimage_width", $ic->getWidth() ); |
---|
| 81 | //$tpl->assign( "clusterimage_height", $ic->getHeight() ); |
---|
| 82 | |
---|
| 83 | $tpl->newBlock( "node_clustermap" ); |
---|
| 84 | $tpl->assign( "node_area_map", $ic->getImagemapArea() ); |
---|
| 85 | $tpl->gotoBlock( "_ROOT" ); |
---|
| 86 | |
---|
| 87 | $tpl->assign( "f_order", $filterorder ); |
---|
| 88 | |
---|
| 89 | if( array_key_exists( "id", $filter ) ) |
---|
| 90 | { |
---|
| 91 | $piefilter = 'id'; |
---|
| 92 | } |
---|
| 93 | else if( array_key_exists( "user", $filter ) ) |
---|
| 94 | { |
---|
| 95 | $piefilter = 'user'; |
---|
| 96 | } |
---|
| 97 | else if( array_key_exists( "queue", $filter ) ) |
---|
| 98 | { |
---|
| 99 | $piefilter = 'queue'; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | $pie = drawPie(); |
---|
| 103 | |
---|
| 104 | $tpl->assign("pie", $pie ); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | function timeToEpoch( $time ) |
---|
| 108 | { |
---|
| 109 | $time_fields = explode( ':', $time ); |
---|
| 110 | |
---|
| 111 | if( count( $time_fields ) == 3 ) |
---|
| 112 | { |
---|
| 113 | $hours = $time_fields[0]; |
---|
| 114 | $minutes = $time_fields[1]; |
---|
| 115 | $seconds = $time_fields[2]; |
---|
| 116 | |
---|
| 117 | } |
---|
| 118 | else if( count( $time_fields ) == 2 ) |
---|
| 119 | { |
---|
| 120 | $hours = 0; |
---|
| 121 | $minutes = $time_fields[0]; |
---|
| 122 | $seconds = $time_fields[1]; |
---|
| 123 | |
---|
| 124 | } |
---|
| 125 | else if( count( $time_fields ) == 1 ) |
---|
| 126 | { |
---|
| 127 | $hours = 0; |
---|
| 128 | $minutes = 0; |
---|
| 129 | $seconds = $time_fields[0]; |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | $myepoch = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) ); |
---|
| 133 | |
---|
| 134 | return $myepoch; |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | function colorRed( $color ) |
---|
| 138 | { |
---|
| 139 | return substr( $color, 0, 2 ); |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | function colorGreen( $color ) |
---|
| 143 | { |
---|
| 144 | return substr( $color, 2, 2 ); |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | function colorBlue( $color ) |
---|
| 148 | { |
---|
| 149 | return substr( $color, 4, 2 ); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | function colorDiffer( $first, $second ) |
---|
| 153 | { |
---|
| 154 | // Make sure these two colors differ atleast 50 R/G/B |
---|
| 155 | $min_diff = 50; |
---|
| 156 | |
---|
| 157 | $c1r = hexDec( colorRed( $first ) ); |
---|
| 158 | $c1g = hexDec( colorGreen( $first ) ); |
---|
| 159 | $c1b = hexDec( colorBlue( $first ) ); |
---|
| 160 | |
---|
| 161 | $c2r = hexDec( colorRed( $second ) ); |
---|
| 162 | $c2g = hexDec( colorGreen( $second ) ); |
---|
| 163 | $c2b = hexDec( colorBlue( $second ) ); |
---|
| 164 | |
---|
| 165 | $rdiff = ($c1r >= $c2r) ? $c1r - $c2r : $c2r - $c1r; |
---|
| 166 | $gdiff = ($c1g >= $c2g) ? $c1g - $c2g : $c2g - $c1g; |
---|
| 167 | $bdiff = ($c1b >= $c2b) ? $c1b - $c2b : $c2b - $c1b; |
---|
| 168 | |
---|
| 169 | if( $rdiff >= $min_diff or $gdiff >= $min_diff or $bdiff >= $min_diff ) |
---|
| 170 | { |
---|
| 171 | return TRUE; |
---|
| 172 | |
---|
| 173 | } |
---|
| 174 | else |
---|
| 175 | { |
---|
| 176 | return FALSE; |
---|
| 177 | } |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | function randomColor( $known_colors ) |
---|
| 181 | { |
---|
| 182 | // White (000000) would be invisible |
---|
| 183 | $start = "004E00"; |
---|
| 184 | |
---|
| 185 | $start_red = colorRed( $start ); |
---|
| 186 | $start_green = colorGreen( $start ); |
---|
| 187 | $start_blue = colorBlue( $start ); |
---|
| 188 | |
---|
| 189 | $end = "FFFFFF"; |
---|
| 190 | |
---|
| 191 | $end_red = colorRed( $end ); |
---|
| 192 | $end_green = colorGreen( $end ); |
---|
| 193 | $end_blue = colorBlue( $end ); |
---|
| 194 | |
---|
| 195 | $change_color = TRUE; |
---|
| 196 | |
---|
| 197 | while( $change_color ) |
---|
| 198 | { |
---|
| 199 | $change_color = FALSE; |
---|
| 200 | |
---|
| 201 | $new_red = rand( hexDec( $start_red ), hexDec( $end_red ) ); |
---|
| 202 | $new_green = rand( hexDec( $start_green ), hexDec( $end_green ) ); |
---|
| 203 | $new_blue = rand( hexDec( $start_blue ), hexDec( $end_blue ) ); |
---|
| 204 | |
---|
| 205 | $new = decHex( $new_red ) . decHex( $new_green ) . decHex( $new_blue ); |
---|
| 206 | |
---|
| 207 | foreach( $known_colors as $old ) |
---|
| 208 | { |
---|
| 209 | if( !colorDiffer( $new, $old ) ) |
---|
| 210 | { |
---|
| 211 | $change_color = TRUE; |
---|
| 212 | } |
---|
| 213 | } |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | // Whoa! Actually found a good color ;) |
---|
| 217 | return $new; |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | // Code these some day |
---|
| 221 | function drawJobPie() { } |
---|
| 222 | |
---|
| 223 | function drawUserPie() { } |
---|
| 224 | |
---|
| 225 | function drawQueuePie() { } |
---|
| 226 | |
---|
| 227 | |
---|
| 228 | function drawPie() |
---|
| 229 | { |
---|
| 230 | global $jobs, $gnodes, $piefilter, $filter, $metrics; |
---|
| 231 | |
---|
| 232 | $nodes = $gnodes; |
---|
| 233 | |
---|
| 234 | if( isset($piefilter) ) |
---|
| 235 | { |
---|
| 236 | $pie_args = "title=" . rawurlencode("Cluster ".$piefilter." usage"); |
---|
| 237 | } |
---|
| 238 | else |
---|
| 239 | { |
---|
| 240 | $pie_args = "title=" . rawurlencode("Cluster queue usage"); |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | $pie_args .= "&size=250x150"; |
---|
| 244 | |
---|
| 245 | $queues = array(); |
---|
| 246 | $nr_jobs = count( $jobs ); |
---|
| 247 | $nr_nodes = count( $nodes ); |
---|
| 248 | |
---|
| 249 | $nr_cpus = cluster_sum("cpu_num", $metrics); |
---|
| 250 | |
---|
| 251 | $empty_cpus = 0; |
---|
| 252 | $used_cpus = 0; |
---|
| 253 | |
---|
| 254 | $job_weight = array(); |
---|
| 255 | |
---|
| 256 | foreach( $nodes as $node ) |
---|
| 257 | { |
---|
| 258 | $myjobs = $node->getJobs(); |
---|
| 259 | $myhost = $node->getHostname(); |
---|
| 260 | $node_cpus = $metrics[$myhost]["cpu_num"][VAL]; |
---|
| 261 | $job_cpu = 0; |
---|
| 262 | |
---|
| 263 | foreach( $myjobs as $myjob ) |
---|
| 264 | { |
---|
| 265 | $job_cpu += (int) $jobs[$myjob][ppn] ? $jobs[$myjob][ppn] : 1; |
---|
| 266 | } |
---|
| 267 | |
---|
| 268 | $node_freecpu = $node_cpus - $job_cpu; |
---|
| 269 | |
---|
| 270 | $empty_cpus += $node_freecpu; |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | $empty_cpus = ( $empty_cpus >= 0 ) ? $empty_cpus : 0; |
---|
| 274 | $used_cpus = $nr_cpus - $empty_cpus; |
---|
| 275 | |
---|
| 276 | //$empty_percentage = ($empty_cpus / $nr_cpus) * 100; |
---|
| 277 | $empty_percentage = $empty_cpus; |
---|
| 278 | |
---|
| 279 | $qcolors = array(); |
---|
| 280 | $color = randomColor( $qcolors ); |
---|
| 281 | $qcolors[] = $color; |
---|
| 282 | $pie_args .= "&free=$empty_percentage,$color"; |
---|
| 283 | |
---|
| 284 | if( isset( $piefilter ) ) |
---|
| 285 | { |
---|
| 286 | $filterpie = array(); |
---|
| 287 | } |
---|
| 288 | |
---|
| 289 | foreach( $nodes as $node ) |
---|
| 290 | { |
---|
| 291 | $node_jobs = $node->getJobs(); |
---|
| 292 | $nr_node_jobs = count( $node_jobs ); |
---|
| 293 | $myhost = $node->getHostname(); |
---|
| 294 | $node_cpus = $metrics[$myhost]["cpu_num"][VAL]; |
---|
| 295 | |
---|
| 296 | foreach( $node_jobs as $myjob ) |
---|
| 297 | { |
---|
| 298 | $job_cpu = (int) $jobs[$myjob][ppn] ? $jobs[$myjob][ppn] : 1; |
---|
| 299 | |
---|
| 300 | // Determine the weight of this job |
---|
| 301 | // - what percentage of the cpus is in use by this job |
---|
| 302 | // |
---|
| 303 | //$job_weight[$myjob] = ( $job_cpu / $nr_cpus ); |
---|
| 304 | $job_weight[$myjob] = $job_cpu; |
---|
| 305 | |
---|
| 306 | if( isset( $piefilter ) ) { |
---|
| 307 | |
---|
| 308 | $countjob = 1; |
---|
| 309 | |
---|
| 310 | if( $piefilter == 'id' ) |
---|
| 311 | { |
---|
| 312 | if( $myjob != $filter[$piefilter] ) |
---|
| 313 | { |
---|
| 314 | $countjob = 0; |
---|
| 315 | } |
---|
| 316 | } |
---|
| 317 | else if( $piefilter == 'user' ) |
---|
| 318 | { |
---|
| 319 | if( $jobs[$myjob][owner] != $filter[$piefilter] ) |
---|
| 320 | { |
---|
| 321 | $countjob = 0; |
---|
| 322 | } |
---|
| 323 | } |
---|
| 324 | else |
---|
| 325 | { |
---|
| 326 | if( $jobs[$myjob][$piefilter] != $filter[$piefilter] ) |
---|
| 327 | { |
---|
| 328 | $countjob = 0; |
---|
| 329 | } |
---|
| 330 | } |
---|
| 331 | |
---|
| 332 | if( $countjob ) |
---|
| 333 | { |
---|
| 334 | |
---|
| 335 | if( !isset( $filterpie[$filter[$piefilter]] ) ) |
---|
| 336 | { |
---|
| 337 | $filterpie[$filter[$piefilter]] = $job_weight[$myjob]; |
---|
| 338 | } |
---|
| 339 | else |
---|
| 340 | { |
---|
| 341 | |
---|
| 342 | $filterpie[$filter[$piefilter]] = $filterpie[$filter[$piefilter]] + $job_weight[$myjob]; |
---|
| 343 | } |
---|
| 344 | } |
---|
| 345 | else |
---|
| 346 | { |
---|
| 347 | if( !isset( $filterpie["other"] ) ) |
---|
| 348 | { |
---|
| 349 | $filterpie["other"] = $job_weight[$myjob]; |
---|
| 350 | } |
---|
| 351 | else |
---|
| 352 | { |
---|
| 353 | $filterpie["other"] = $filterpie["other"] + $job_weight[$myjob]; |
---|
| 354 | } |
---|
| 355 | |
---|
| 356 | } |
---|
| 357 | |
---|
| 358 | } |
---|
| 359 | else |
---|
| 360 | { |
---|
| 361 | |
---|
| 362 | $qname = $jobs[$myjob][queue]; |
---|
| 363 | |
---|
| 364 | if( !isset( $queues[$qname] ) ) |
---|
| 365 | { |
---|
| 366 | $queues[$qname] = $job_weight[$myjob]; |
---|
| 367 | } |
---|
| 368 | else |
---|
| 369 | { |
---|
| 370 | $queues[$qname] = $queues[$qname] + $job_weight[$myjob]; |
---|
| 371 | } |
---|
| 372 | } |
---|
| 373 | } |
---|
| 374 | } |
---|
| 375 | |
---|
| 376 | if( isset( $piefilter ) ) |
---|
| 377 | { |
---|
| 378 | $graphvals = $filterpie; |
---|
| 379 | } |
---|
| 380 | else |
---|
| 381 | { |
---|
| 382 | $graphvals = $queues; |
---|
| 383 | } |
---|
| 384 | |
---|
| 385 | //$percentage = 0; |
---|
| 386 | //$slice_count = 0; |
---|
| 387 | |
---|
| 388 | // Find rounding errors: total has to be 100 |
---|
| 389 | // |
---|
| 390 | //foreach( $graphvals as $name => $totalweight) |
---|
| 391 | //{ |
---|
| 392 | // $percentage = $percentage + $totalweight; |
---|
| 393 | // $slice_count = $slice_count + 1; |
---|
| 394 | //} |
---|
| 395 | |
---|
| 396 | //$round_offset = ( 100 - $percentage ) / $slice_count; |
---|
| 397 | |
---|
| 398 | foreach( $graphvals as $name => $totalweight) |
---|
| 399 | { |
---|
| 400 | //$percentage = ( $totalweight * 100 ) + $round_offset; |
---|
| 401 | $percentage = $totalweight; |
---|
| 402 | |
---|
| 403 | $color = randomColor( $qcolors ); |
---|
| 404 | $qcolors[] = $color; |
---|
| 405 | $pie_args .= "&$name=$percentage,$color"; |
---|
| 406 | } |
---|
| 407 | $pie = "./chart.php?$pie_args"; |
---|
| 408 | |
---|
| 409 | return $pie; |
---|
| 410 | } |
---|
| 411 | |
---|
| 412 | |
---|
| 413 | function sortJobs( $jobs, $sortby, $sortorder ) |
---|
| 414 | { |
---|
| 415 | $sorted = array(); |
---|
| 416 | |
---|
| 417 | $cmp = create_function( '$a, $b', |
---|
| 418 | "global \$sortby, \$sortorder;". |
---|
| 419 | |
---|
| 420 | "if( \$a == \$b ) return 0;". |
---|
| 421 | |
---|
| 422 | "if (\$sortorder==\"desc\")". |
---|
| 423 | "return ( \$a < \$b ) ? 1 : -1;". |
---|
| 424 | "else if (\$sortorder==\"asc\")". |
---|
| 425 | "return ( \$a > \$b ) ? 1 : -1;" ); |
---|
| 426 | |
---|
| 427 | if( isset( $jobs ) && count( $jobs ) > 0 ) |
---|
| 428 | { |
---|
| 429 | foreach( $jobs as $jobid => $jobattrs ) |
---|
| 430 | { |
---|
| 431 | $state = $jobattrs[status]; |
---|
| 432 | $user = $jobattrs[owner]; |
---|
| 433 | $queue = $jobattrs[queue]; |
---|
| 434 | $name = $jobattrs[name]; |
---|
| 435 | $req_cpu = $jobattrs[requested_time]; |
---|
| 436 | $req_memory = $jobattrs[requested_memory]; |
---|
| 437 | |
---|
| 438 | if( $state == 'R' ) |
---|
| 439 | { |
---|
| 440 | $nodes = count( $jobattrs[nodes] ); |
---|
| 441 | } |
---|
| 442 | else |
---|
| 443 | { |
---|
| 444 | $nodes = $jobattrs[nodes]; |
---|
| 445 | } |
---|
| 446 | |
---|
| 447 | $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1; |
---|
| 448 | $cpus = $nodes * $ppn; |
---|
| 449 | $queued_time = (int) $jobattrs[queued_timestamp]; |
---|
| 450 | $start_time = (int) $jobattrs[start_timestamp]; |
---|
| 451 | $runningtime = $report_time - $start_time; |
---|
| 452 | |
---|
| 453 | switch( $sortby ) |
---|
| 454 | { |
---|
| 455 | case "id": |
---|
| 456 | $sorted[$jobid] = $jobid; |
---|
| 457 | break; |
---|
| 458 | |
---|
| 459 | case "state": |
---|
| 460 | $sorted[$jobid] = $state; |
---|
| 461 | break; |
---|
| 462 | |
---|
| 463 | case "user": |
---|
| 464 | $sorted[$jobid] = $user; |
---|
| 465 | break; |
---|
| 466 | |
---|
| 467 | case "queue": |
---|
| 468 | $sorted[$jobid] = $queue; |
---|
| 469 | break; |
---|
| 470 | |
---|
| 471 | case "name": |
---|
| 472 | $sorted[$jobid] = $name; |
---|
| 473 | break; |
---|
| 474 | |
---|
| 475 | case "req_cpu": |
---|
| 476 | $sorted[$jobid] = timeToEpoch( $req_cpu ); |
---|
| 477 | break; |
---|
| 478 | |
---|
| 479 | case "req_mem": |
---|
| 480 | $sorted[$jobid] = $req_memory; |
---|
| 481 | break; |
---|
| 482 | |
---|
| 483 | case "nodes": |
---|
| 484 | $sorted[$jobid] = $nodes; |
---|
| 485 | break; |
---|
| 486 | |
---|
| 487 | case "cpus": |
---|
| 488 | $sorted[$jobid] = $cpus; |
---|
| 489 | break; |
---|
| 490 | |
---|
| 491 | case "queued": |
---|
| 492 | $sorted[$jobid] = $queued_time; |
---|
| 493 | break; |
---|
| 494 | |
---|
| 495 | case "start": |
---|
| 496 | $sorted[$jobid] = $start_time; |
---|
| 497 | break; |
---|
| 498 | |
---|
| 499 | case "runningtime": |
---|
| 500 | $sorted[$jobid] = $runningtime; |
---|
| 501 | break; |
---|
| 502 | |
---|
| 503 | default: |
---|
| 504 | break; |
---|
| 505 | } |
---|
| 506 | } |
---|
| 507 | } |
---|
| 508 | |
---|
| 509 | if( $sortorder == "asc" ) |
---|
| 510 | { |
---|
| 511 | arsort( $sorted ); |
---|
| 512 | } |
---|
| 513 | else if( $sortorder == "desc" ) |
---|
| 514 | { |
---|
| 515 | asort( $sorted ); |
---|
| 516 | } |
---|
| 517 | |
---|
| 518 | return $sorted; |
---|
| 519 | } |
---|
| 520 | |
---|
| 521 | function makeOverview() |
---|
| 522 | { |
---|
| 523 | global $jobs, $nodes, $heartbeat, $clustername, $tpl; |
---|
| 524 | global $sortorder, $sortby, $filter, $sh, $hc, $m, $range; |
---|
| 525 | global $cluster_url, $get_metric_string, $host_url, $metrics; |
---|
| 526 | global $start, $end, $reports, $gnodes, $default_showhosts; |
---|
| 527 | global $COLUMN_QUEUED, $COLUMN_REQUESTED_MEMORY, $COLUMN_NODES, $hostname; |
---|
| 528 | global $cluster, $use_fqdn; |
---|
| 529 | |
---|
| 530 | $metricname = $m; |
---|
| 531 | |
---|
| 532 | $tpl->assign("sortorder", $sortorder ); |
---|
| 533 | $tpl->assign("sortby", $sortby ); |
---|
| 534 | |
---|
| 535 | $sorted_jobs = sortJobs( $jobs, $sortby, $sortorder ); |
---|
| 536 | |
---|
| 537 | $even = 1; |
---|
| 538 | |
---|
| 539 | $used_jobs = 0; |
---|
| 540 | $used_cpus = 0; |
---|
| 541 | $used_nodes = 0; |
---|
| 542 | |
---|
| 543 | $queued_jobs = 0; |
---|
| 544 | $queued_nodes = 0; |
---|
| 545 | $queued_cpus = 0; |
---|
| 546 | |
---|
| 547 | $total_nodes = 0; |
---|
| 548 | $total_cpus = 0; |
---|
| 549 | $total_jobs = 0; |
---|
| 550 | |
---|
| 551 | $all_used_nodes = array(); |
---|
| 552 | $total_used_nodes = array(); |
---|
| 553 | |
---|
| 554 | $running_name_nodes = array(); |
---|
| 555 | |
---|
| 556 | $running_nodes = 0; |
---|
| 557 | $running_jobs = 0; |
---|
| 558 | $running_cpus = 0; |
---|
| 559 | |
---|
| 560 | $avail_nodes = count( $gnodes ); |
---|
| 561 | $avail_cpus = cluster_sum("cpu_num", $metrics); |
---|
| 562 | |
---|
| 563 | $view_cpus = 0; |
---|
| 564 | $view_jobs = 0; |
---|
| 565 | $view_nodes = 0; |
---|
| 566 | |
---|
| 567 | $all_nodes = 0; |
---|
| 568 | $all_jobs = 0; |
---|
| 569 | $all_cpus = 0; |
---|
| 570 | |
---|
| 571 | $view_name_nodes = array(); |
---|
| 572 | |
---|
| 573 | // Is the "requested memory" column enabled in the config |
---|
| 574 | // |
---|
| 575 | if( $COLUMN_REQUESTED_MEMORY ) |
---|
| 576 | { |
---|
| 577 | $tpl->newBlock( "column_header_req_mem" ); |
---|
| 578 | } |
---|
| 579 | |
---|
| 580 | // Is the "nodes hostnames" column enabled in the config |
---|
| 581 | // |
---|
| 582 | if( $COLUMN_NODES ) |
---|
| 583 | { |
---|
| 584 | $tpl->newBlock( "column_header_nodes" ); |
---|
| 585 | } |
---|
| 586 | |
---|
| 587 | // Is the "queued time" column enabled in the config |
---|
| 588 | // |
---|
| 589 | if( $COLUMN_QUEUED ) |
---|
| 590 | { |
---|
| 591 | $tpl->newBlock( "column_header_queued" ); |
---|
| 592 | } |
---|
| 593 | |
---|
| 594 | $last_displayed_job = null; |
---|
| 595 | |
---|
| 596 | $rjqj_host = null; |
---|
| 597 | |
---|
| 598 | $na_nodes = 0; |
---|
| 599 | $na_cpus = 0; |
---|
| 600 | |
---|
| 601 | foreach( $metrics as $bhost => $bmetric ) |
---|
| 602 | { |
---|
| 603 | foreach( $bmetric as $mname => $mval ) |
---|
| 604 | { |
---|
| 605 | if( ( $mname == 'MONARCH-RJ' ) || ($mname == 'MONARCH-QJ') ) |
---|
| 606 | { |
---|
| 607 | $rjqj_host = $bhost; |
---|
| 608 | } |
---|
| 609 | } |
---|
| 610 | } |
---|
| 611 | |
---|
| 612 | foreach( $gnodes as $ghost => $gnode ) |
---|
| 613 | { |
---|
| 614 | if( $gnode->isDown() || $gnode->isOffline() ) |
---|
| 615 | { |
---|
| 616 | $na_nodes += 1; |
---|
| 617 | $na_cpus += $metrics[$ghost]['cpu_num']['VAL']; |
---|
| 618 | } |
---|
| 619 | } |
---|
| 620 | |
---|
| 621 | // Running / queued amount jobs graph |
---|
| 622 | // |
---|
| 623 | if( $rjqj_host != null ) |
---|
| 624 | { |
---|
| 625 | |
---|
| 626 | $rjqj_str = "<A HREF=\"./graph.php?z=large&c=$clustername&g=job_report&r=$range&st=$cluster[LOCALTIME]\">"; |
---|
| 627 | $rjqj_str .= "<IMG BORDER=0 SRC=\"./graph.php?z=small&c=$clustername&g=job_report&r=$range&st=$cluster[LOCALTIME]\">"; |
---|
| 628 | $rjqj_str .= "</A>"; |
---|
| 629 | |
---|
| 630 | $tpl->gotoBlock( "_ROOT" ); |
---|
| 631 | |
---|
| 632 | $tpl->assign( "rjqj_graph", $rjqj_str ); |
---|
| 633 | } |
---|
| 634 | |
---|
| 635 | foreach( $sorted_jobs as $jobid => $sortdec ) |
---|
| 636 | { |
---|
| 637 | $report_time = $jobs[$jobid][reported]; |
---|
| 638 | |
---|
| 639 | if( $jobs[$jobid][status] == 'R' ) |
---|
| 640 | { |
---|
| 641 | $nodes = count( $jobs[$jobid][nodes] ); |
---|
| 642 | } |
---|
| 643 | else if( $jobs[$jobid][status] == 'Q' ) |
---|
| 644 | { |
---|
| 645 | $nodes = $jobs[$jobid][nodes]; |
---|
| 646 | } |
---|
| 647 | |
---|
| 648 | $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1; |
---|
| 649 | $cpus = $nodes * $ppn; |
---|
| 650 | |
---|
| 651 | if( $report_time == $heartbeat ) |
---|
| 652 | { |
---|
| 653 | $display_job = 1; |
---|
| 654 | |
---|
| 655 | if( $jobs[$jobid][status] == 'R' ) |
---|
| 656 | { |
---|
| 657 | foreach( $jobs[$jobid][nodes] as $tempnode ) |
---|
| 658 | { |
---|
| 659 | $all_used_nodes[] = $tempnode; |
---|
| 660 | } |
---|
| 661 | } |
---|
| 662 | |
---|
| 663 | $used_cpus += $cpus; |
---|
| 664 | |
---|
| 665 | if( $jobs[$jobid][status] == 'R' ) |
---|
| 666 | { |
---|
| 667 | $running_cpus += $cpus; |
---|
| 668 | |
---|
| 669 | $running_jobs++; |
---|
| 670 | |
---|
| 671 | $found_node_job = 0; |
---|
| 672 | |
---|
| 673 | foreach( $jobs[$jobid][nodes] as $tempnode ) |
---|
| 674 | { |
---|
| 675 | $running_name_nodes[] = $tempnode; |
---|
| 676 | |
---|
| 677 | if( isset( $hostname ) && $hostname != '' ) |
---|
| 678 | { |
---|
| 679 | //$filter[host] = $hostname; |
---|
| 680 | |
---|
| 681 | $domain_len = 0 - strlen( $jobs[$jobid][domain] ); |
---|
| 682 | $hostnode = $tempnode; |
---|
| 683 | |
---|
| 684 | if( $use_fqdn == 1) |
---|
| 685 | { |
---|
| 686 | if( substr( $hostnode, $domain_len ) != $jobs[$jobid][domain] ) |
---|
| 687 | { |
---|
| 688 | $hostnode = $hostnode. '.'. $jobs[$jobid][domain]; |
---|
| 689 | } |
---|
| 690 | } |
---|
| 691 | |
---|
| 692 | if( $hostname == $hostnode ) |
---|
| 693 | { |
---|
| 694 | $found_node_job = 1; |
---|
| 695 | $display_job = 1; |
---|
| 696 | } |
---|
| 697 | else if( !$found_node_job ) |
---|
| 698 | { |
---|
| 699 | $display_job = 0; |
---|
| 700 | } |
---|
| 701 | } |
---|
| 702 | } |
---|
| 703 | } |
---|
| 704 | |
---|
| 705 | if( $jobs[$jobid][status] == 'Q' ) |
---|
| 706 | { |
---|
| 707 | if( isset( $hostname ) && $hostname != '' ) |
---|
| 708 | { |
---|
| 709 | $display_job = 0; |
---|
| 710 | } |
---|
| 711 | |
---|
| 712 | $queued_cpus += $cpus; |
---|
| 713 | $queued_nodes += $nodes; |
---|
| 714 | |
---|
| 715 | $queued_jobs++; |
---|
| 716 | } |
---|
| 717 | |
---|
| 718 | foreach( $filter as $filtername=>$filtervalue ) |
---|
| 719 | { |
---|
| 720 | if( $filtername == 'id' && $jobid != $filtervalue ) |
---|
| 721 | { |
---|
| 722 | $display_job = 0; |
---|
| 723 | } |
---|
| 724 | else if( $filtername == 'state' && $jobs[$jobid][status] != $filtervalue ) |
---|
| 725 | { |
---|
| 726 | $display_job = 0; |
---|
| 727 | } |
---|
| 728 | else if( $filtername == 'queue' && $jobs[$jobid][queue] != $filtervalue ) |
---|
| 729 | { |
---|
| 730 | $display_job = 0; |
---|
| 731 | } |
---|
| 732 | else if( $filtername == 'user' && $jobs[$jobid][owner] != $filtervalue ) |
---|
| 733 | { |
---|
| 734 | $display_job = 0; |
---|
| 735 | } |
---|
| 736 | } |
---|
| 737 | |
---|
| 738 | if( $display_job ) |
---|
| 739 | { |
---|
| 740 | $tpl->newBlock( "node" ); |
---|
| 741 | $tpl->assign( "clustername", $clustername ); |
---|
| 742 | $tpl->assign( "id", $jobid ); |
---|
| 743 | |
---|
| 744 | $last_displayed_job = $jobid; |
---|
| 745 | |
---|
| 746 | $tpl->assign( "state", $jobs[$jobid][status] ); |
---|
| 747 | |
---|
| 748 | $fullstate = ''; |
---|
| 749 | |
---|
| 750 | if( $jobs[$jobid][status] == 'R' ) |
---|
| 751 | { |
---|
| 752 | $fullstate = "Running"; |
---|
| 753 | } |
---|
| 754 | else if( $jobs[$jobid][status] == 'Q' ) |
---|
| 755 | { |
---|
| 756 | $fullstate = "Queued"; |
---|
| 757 | } |
---|
| 758 | |
---|
| 759 | $tpl->assign( "fullstate", $fullstate ); |
---|
| 760 | |
---|
| 761 | $tpl->assign( "user", $jobs[$jobid][owner] ); |
---|
| 762 | $tpl->assign( "queue", $jobs[$jobid][queue] ); |
---|
| 763 | |
---|
| 764 | $fulljobname = $jobs[$jobid][name]; |
---|
| 765 | $shortjobname = ''; |
---|
| 766 | |
---|
| 767 | $tpl->assign( "fulljobname", $fulljobname ); |
---|
| 768 | |
---|
| 769 | $fulljobname_fields = explode( ' ', $fulljobname ); |
---|
| 770 | |
---|
| 771 | $capjobname = 0; |
---|
| 772 | |
---|
| 773 | if( strlen( $fulljobname_fields[0] ) > 10 ) |
---|
| 774 | { |
---|
| 775 | $capjobname = 1; |
---|
| 776 | } |
---|
| 777 | |
---|
| 778 | if( $capjobname ) |
---|
| 779 | { |
---|
| 780 | $tpl->newBlock( "jobname_hint_start" ); |
---|
| 781 | $tpl->gotoBlock( "node" ); |
---|
| 782 | |
---|
| 783 | $shortjobname = substr( $fulljobname, 0, 10 ) . '..'; |
---|
| 784 | } |
---|
| 785 | else |
---|
| 786 | { |
---|
| 787 | $shortjobname = $fulljobname; |
---|
| 788 | } |
---|
| 789 | |
---|
| 790 | $tpl->assign( "name", $shortjobname ); |
---|
| 791 | |
---|
| 792 | if( $capjobname ) |
---|
| 793 | { |
---|
| 794 | $tpl->newBlock( "jobname_hint_end" ); |
---|
| 795 | $tpl->gotoBlock( "node" ); |
---|
| 796 | } |
---|
| 797 | |
---|
| 798 | $domain = $jobs[$jobid][domain]; |
---|
| 799 | |
---|
| 800 | $tpl->assign( "req_cpu", makeTime( timeToEpoch( $jobs[$jobid][requested_time] ) ) ); |
---|
| 801 | |
---|
| 802 | if( $COLUMN_REQUESTED_MEMORY ) |
---|
| 803 | { |
---|
| 804 | $tpl->newBlock( "column_req_mem" ); |
---|
| 805 | $tpl->assign( "req_memory", $jobs[$jobid][requested_memory] ); |
---|
| 806 | $tpl->gotoBlock( "node" ); |
---|
| 807 | } |
---|
| 808 | |
---|
| 809 | |
---|
| 810 | if( $COLUMN_QUEUED ) |
---|
| 811 | { |
---|
| 812 | $tpl->newBlock( "column_queued" ); |
---|
| 813 | $tpl->assign( "queued", makeDate( $jobs[$jobid][queued_timestamp] ) ); |
---|
| 814 | $tpl->gotoBlock( "node" ); |
---|
| 815 | } |
---|
| 816 | if( $COLUMN_NODES ) |
---|
| 817 | { |
---|
| 818 | $tpl->newBlock( "column_nodes" ); |
---|
| 819 | $tpl->gotoBlock( "node" ); |
---|
| 820 | } |
---|
| 821 | |
---|
| 822 | $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1; |
---|
| 823 | $cpus = $nodes * $ppn; |
---|
| 824 | |
---|
| 825 | $tpl->assign( "nodes", $nodes ); |
---|
| 826 | $tpl->assign( "cpus", $cpus ); |
---|
| 827 | |
---|
| 828 | $start_time = (int) $jobs[$jobid][start_timestamp]; |
---|
| 829 | $job_start = $start_time; |
---|
| 830 | |
---|
| 831 | $view_cpus += $cpus; |
---|
| 832 | |
---|
| 833 | $view_jobs++; |
---|
| 834 | |
---|
| 835 | if( $jobs[$jobid][status] == 'R' ) |
---|
| 836 | { |
---|
| 837 | foreach( $jobs[$jobid][nodes] as $tempnode ) |
---|
| 838 | { |
---|
| 839 | $view_name_nodes[] = $tempnode; |
---|
| 840 | } |
---|
| 841 | |
---|
| 842 | if( $COLUMN_NODES ) |
---|
| 843 | { |
---|
| 844 | $tpl->gotoBlock( "column_nodes" ); |
---|
| 845 | |
---|
| 846 | $mynodehosts = array(); |
---|
| 847 | |
---|
| 848 | foreach( $jobs[$jobid][nodes] as $mynode ) |
---|
| 849 | { |
---|
| 850 | if( $use_fqdn == 1) |
---|
| 851 | { |
---|
| 852 | $mynode = $mynode.".".$jobs[$jobid][domain]; |
---|
| 853 | } |
---|
| 854 | $myhost_href = "./?c=".$clustername."&h=".$mynode; |
---|
| 855 | $mynodehosts[] = "<A HREF=\"".$myhost_href."\">".$mynode."</A>"; |
---|
| 856 | } |
---|
| 857 | |
---|
| 858 | $nodes_hostnames = implode( " ", $mynodehosts ); |
---|
| 859 | |
---|
| 860 | $tpl->assign( "nodes_hostnames", $nodes_hostnames ); |
---|
| 861 | $tpl->gotoBlock( "node" ); |
---|
| 862 | } |
---|
| 863 | } |
---|
| 864 | else if( $jobs[$jobid][status] == 'Q' ) |
---|
| 865 | { |
---|
| 866 | $view_nodes += (int) $jobs[$jobid][nodes]; |
---|
| 867 | } |
---|
| 868 | |
---|
| 869 | if( $even ) |
---|
| 870 | { |
---|
| 871 | $tpl->assign( "nodeclass", "even" ); |
---|
| 872 | |
---|
| 873 | $even = 0; |
---|
| 874 | } |
---|
| 875 | else |
---|
| 876 | { |
---|
| 877 | $tpl->assign( "nodeclass", "odd" ); |
---|
| 878 | |
---|
| 879 | $even = 1; |
---|
| 880 | } |
---|
| 881 | |
---|
| 882 | if( $start_time ) |
---|
| 883 | { |
---|
| 884 | $runningtime = makeTime( $report_time - $start_time ); |
---|
| 885 | //$job_runningtime = $report_time - $start_time; |
---|
| 886 | $job_runningtime = $heartbeat - $start_time; |
---|
| 887 | |
---|
| 888 | $tpl->assign( "started", makeDate( $start_time ) ); |
---|
| 889 | $tpl->assign( "runningtime", $runningtime ); |
---|
| 890 | } |
---|
| 891 | } |
---|
| 892 | } |
---|
| 893 | } |
---|
| 894 | |
---|
| 895 | $all_used_nodes = array_unique( $all_used_nodes ); |
---|
| 896 | $view_name_nodes = array_unique( $view_name_nodes ); |
---|
| 897 | $running_name_nodes = array_unique( $running_name_nodes ); |
---|
| 898 | |
---|
| 899 | $used_nodes = count( $all_used_nodes ); |
---|
| 900 | $view_nodes += count( $view_name_nodes ); |
---|
| 901 | $running_nodes += count( $running_name_nodes ); |
---|
| 902 | |
---|
| 903 | $total_nodes = $queued_nodes + $running_nodes; |
---|
| 904 | $total_cpus = $queued_cpus + $running_cpus; |
---|
| 905 | $total_jobs = $queued_jobs + $running_jobs; |
---|
| 906 | |
---|
| 907 | $free_nodes = $avail_nodes - $running_nodes - $na_nodes; |
---|
| 908 | $free_nodes = ( $free_nodes >= 0 ) ? $free_nodes : 0; |
---|
| 909 | $free_cpus = $avail_cpus - $running_cpus - $na_cpus; |
---|
| 910 | $free_cpus = ( $free_cpus >= 0 ) ? $free_cpus : 0; |
---|
| 911 | |
---|
| 912 | $tpl->assignGlobal( "avail_nodes", $avail_nodes ); |
---|
| 913 | $tpl->assignGlobal( "avail_cpus", $avail_cpus ); |
---|
| 914 | |
---|
| 915 | $tpl->assignGlobal( "queued_nodes", $queued_nodes ); |
---|
| 916 | $tpl->assignGlobal( "queued_jobs", $queued_jobs ); |
---|
| 917 | $tpl->assignGlobal( "queued_cpus", $queued_cpus ); |
---|
| 918 | |
---|
| 919 | // Only display "Unavailable" in count overview there are any |
---|
| 920 | // |
---|
| 921 | if( $na_nodes > 0 ) |
---|
| 922 | { |
---|
| 923 | $tpl->newBlock( "na_nodes" ); |
---|
| 924 | |
---|
| 925 | $tpl->assignGlobal( "na_nodes", $na_nodes ); |
---|
| 926 | $tpl->assignGlobal( "na_cpus", $na_cpus ); |
---|
| 927 | |
---|
| 928 | $tpl->gotoBlock( "_ROOT" ); |
---|
| 929 | } |
---|
| 930 | |
---|
| 931 | $tpl->assignGlobal( "total_nodes", $total_nodes ); |
---|
| 932 | $tpl->assignGlobal( "total_jobs", $total_jobs ); |
---|
| 933 | $tpl->assignGlobal( "total_cpus", $total_cpus ); |
---|
| 934 | |
---|
| 935 | $tpl->assignGlobal( "running_nodes", $running_nodes ); |
---|
| 936 | $tpl->assignGlobal( "running_jobs", $running_jobs ); |
---|
| 937 | $tpl->assignGlobal( "running_cpus", $running_cpus ); |
---|
| 938 | |
---|
| 939 | $tpl->assignGlobal( "used_nodes", $used_nodes ); |
---|
| 940 | $tpl->assignGlobal( "used_jobs", $used_jobs ); |
---|
| 941 | $tpl->assignGlobal( "used_cpus", $used_cpus ); |
---|
| 942 | |
---|
| 943 | $tpl->assignGlobal( "free_nodes", $free_nodes ); |
---|
| 944 | $tpl->assignGlobal( "free_cpus", $free_cpus ); |
---|
| 945 | |
---|
| 946 | $tpl->assignGlobal( "view_nodes", $view_nodes ); |
---|
| 947 | $tpl->assignGlobal( "view_jobs", $view_jobs ); |
---|
| 948 | $tpl->assignGlobal( "view_cpus", $view_cpus ); |
---|
| 949 | |
---|
| 950 | $tpl->assignGlobal( "report_time", makeDate( $heartbeat) ); |
---|
| 951 | |
---|
| 952 | if( intval($view_jobs) == 1 and $start_time ) |
---|
| 953 | { |
---|
| 954 | if( $last_displayed_job != null ) |
---|
| 955 | { |
---|
| 956 | $filter[id] = $last_displayed_job; |
---|
| 957 | } |
---|
| 958 | } |
---|
| 959 | |
---|
| 960 | //print_r( $metrics ); |
---|
| 961 | |
---|
| 962 | global $longtitle, $title; |
---|
| 963 | |
---|
| 964 | $longtitle = "Batch Report :: Powered by Job Monarch!"; |
---|
| 965 | $title = "Batch Report"; |
---|
| 966 | |
---|
| 967 | makeHeader( 'overview', $title, $longtitle ); |
---|
| 968 | |
---|
| 969 | setupFilterSettings(); |
---|
| 970 | |
---|
| 971 | if( intval($view_jobs) == 1 and $start_time ) |
---|
| 972 | { |
---|
| 973 | $tpl->newBlock( "showhosts" ); |
---|
| 974 | |
---|
| 975 | # Present a width list |
---|
| 976 | $cols_menu = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n"; |
---|
| 977 | |
---|
| 978 | $hostcols = ($hc) ? $hc : 4; |
---|
| 979 | |
---|
| 980 | foreach( range( 1, 25 ) as $cols ) |
---|
| 981 | { |
---|
| 982 | $cols_menu .= "<OPTION VALUE=$cols "; |
---|
| 983 | |
---|
| 984 | if ($cols == $hostcols) |
---|
| 985 | { |
---|
| 986 | $cols_menu .= "SELECTED"; |
---|
| 987 | } |
---|
| 988 | $cols_menu .= ">$cols\n"; |
---|
| 989 | } |
---|
| 990 | $cols_menu .= "</SELECT>\n"; |
---|
| 991 | |
---|
| 992 | $tpl->assign( "metric","$metricname $units" ); |
---|
| 993 | $tpl->assign( "id", $filter[id] ); |
---|
| 994 | |
---|
| 995 | # Host columns menu defined in header.php |
---|
| 996 | $tpl->assign( "cols_menu", $cols_menu ); |
---|
| 997 | |
---|
| 998 | $showhosts = isset($sh) ? $sh : $default_showhosts; |
---|
| 999 | |
---|
| 1000 | $tpl->assign( "checked$showhosts", "checked" ); |
---|
| 1001 | |
---|
| 1002 | if( $showhosts ) |
---|
| 1003 | { |
---|
| 1004 | if( !isset( $start ) ) |
---|
| 1005 | { |
---|
| 1006 | $start ="jobstart"; |
---|
| 1007 | } |
---|
| 1008 | if( !isset( $stop ) ) |
---|
| 1009 | { |
---|
| 1010 | $stop ="now"; |
---|
| 1011 | } |
---|
| 1012 | |
---|
| 1013 | $sorted_hosts = array(); |
---|
| 1014 | $hosts_up = $jobs[$filter[id]][nodes]; |
---|
| 1015 | |
---|
| 1016 | //printf( "r %s\n", $job_runningtime ); |
---|
| 1017 | |
---|
| 1018 | $r = intval($job_runningtime * 1.2); |
---|
| 1019 | |
---|
| 1020 | //$jobrange = ($job_runningtime < 3600) ? -3600 : -$r ; |
---|
| 1021 | $jobrange = -$r ; |
---|
| 1022 | //$jobstart = $report_time - $job_runningtime; |
---|
| 1023 | $jobstart = $start_time; |
---|
| 1024 | |
---|
| 1025 | //printf( "jr %s\n", $jobrange ); |
---|
| 1026 | //printf( "js %s\n", $jobstart); |
---|
| 1027 | |
---|
| 1028 | if ( $reports[$metricname] ) |
---|
| 1029 | { |
---|
| 1030 | $metricval = "g"; |
---|
| 1031 | } |
---|
| 1032 | else |
---|
| 1033 | { |
---|
| 1034 | $metricval = "m"; |
---|
| 1035 | } |
---|
| 1036 | |
---|
| 1037 | foreach ( $hosts_up as $host ) |
---|
| 1038 | { |
---|
| 1039 | $domain_len = 0 - strlen( $domain ); |
---|
| 1040 | |
---|
| 1041 | if( $use_fqdn ) |
---|
| 1042 | { |
---|
| 1043 | if( substr( $host, $domain_len ) != $domain ) |
---|
| 1044 | { |
---|
| 1045 | $host = $host . '.' . $domain; |
---|
| 1046 | } |
---|
| 1047 | } |
---|
| 1048 | |
---|
| 1049 | $cpus = $metrics[$host]["cpu_num"]["VAL"]; |
---|
| 1050 | |
---|
| 1051 | if ( !$cpus ) |
---|
| 1052 | { |
---|
| 1053 | $cpus = 1; |
---|
| 1054 | } |
---|
| 1055 | |
---|
| 1056 | $load_one = $metrics[$host]["load_one"][VAL]; |
---|
| 1057 | $load = ((float) $load_one) / $cpus; |
---|
| 1058 | $host_load[$host] = $load; |
---|
| 1059 | |
---|
| 1060 | $percent_hosts[load_color($load)] ++; |
---|
| 1061 | |
---|
| 1062 | if ($metricname=="load_one") |
---|
| 1063 | { |
---|
| 1064 | $sorted_hosts[$host] = $load; |
---|
| 1065 | } |
---|
| 1066 | else |
---|
| 1067 | { |
---|
| 1068 | $sorted_hosts[$host] = $metrics[$host][$metricname][VAL]; |
---|
| 1069 | } |
---|
| 1070 | } |
---|
| 1071 | |
---|
| 1072 | switch ( $sort ) |
---|
| 1073 | { |
---|
| 1074 | case "descending": |
---|
| 1075 | arsort( $sorted_hosts ); |
---|
| 1076 | break; |
---|
| 1077 | |
---|
| 1078 | case "by hostname": |
---|
| 1079 | ksort( $sorted_hosts ); |
---|
| 1080 | break; |
---|
| 1081 | |
---|
| 1082 | case "ascending": |
---|
| 1083 | asort( $sorted_hosts ); |
---|
| 1084 | break; |
---|
| 1085 | |
---|
| 1086 | default: |
---|
| 1087 | break; |
---|
| 1088 | } |
---|
| 1089 | |
---|
| 1090 | // First pass to find the max value in all graphs for this |
---|
| 1091 | // metric. The $start,$end variables comes from get_context.php, |
---|
| 1092 | // included in index.php. |
---|
| 1093 | // |
---|
| 1094 | list($min, $max) = find_limits($sorted_hosts, $metricname); |
---|
| 1095 | |
---|
| 1096 | // Second pass to output the graphs or metrics. |
---|
| 1097 | $i = 1; |
---|
| 1098 | |
---|
| 1099 | foreach ( $sorted_hosts as $host=>$value ) |
---|
| 1100 | { |
---|
| 1101 | $tpl->newBlock( "sorted_list" ); |
---|
| 1102 | |
---|
| 1103 | $host_url = rawurlencode( $host ); |
---|
| 1104 | $cluster_url = rawurlencode( $clustername ); |
---|
| 1105 | |
---|
| 1106 | $textval = ""; |
---|
| 1107 | |
---|
| 1108 | $val = $metrics[$host][$metricname]; |
---|
| 1109 | $class = "metric"; |
---|
| 1110 | $host_link = "\"../../?c=$cluster_url&h=$host_url&r=job&jr=$jobrange&js=$jobstart\""; |
---|
| 1111 | |
---|
| 1112 | if ( $val["TYPE"] == "timestamp" || $always_timestamp[$metricname] ) |
---|
| 1113 | { |
---|
| 1114 | $textval = date( "r", $val["VAL"] ); |
---|
| 1115 | } |
---|
| 1116 | elseif ( $val["TYPE"] == "string" || $val["SLOPE"] == "zero" || $always_constant[$metricname] || ($max_graphs > 0 and $i > $max_graphs )) |
---|
| 1117 | { |
---|
| 1118 | $textval = $val["VAL"] . " " . $val["UNITS"]; |
---|
| 1119 | } |
---|
| 1120 | else |
---|
| 1121 | { |
---|
| 1122 | $load_color = load_color($host_load[$host]); |
---|
| 1123 | $graphargs = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&"; |
---|
| 1124 | $graphargs .= "z=small&c=$cluster_url&h=$host_url&l=$load_color" . "&v=$val[VAL]&r=job&jr=$jobrange&js=$jobstart"; |
---|
| 1125 | if( $max > 0 ) |
---|
| 1126 | { |
---|
| 1127 | $graphargs .= "&x=$max&n=$min"; |
---|
| 1128 | } |
---|
| 1129 | } |
---|
| 1130 | if ($textval) |
---|
| 1131 | { |
---|
| 1132 | $cell = "<td class=$class>". "<b><a href=$host_link>$host</a></b><br>". "<i>$metricname:</i> <b>$textval</b></td>"; |
---|
| 1133 | } else { |
---|
| 1134 | $cell = "<td><a href=$host_link>" . "<img src=\"../../graph.php?$graphargs\" " . "alt=\"$host\" border=0></a></td>"; |
---|
| 1135 | } |
---|
| 1136 | |
---|
| 1137 | $tpl->assign( "metric_image", $cell ); |
---|
| 1138 | |
---|
| 1139 | if(! ($i++ % $hostcols) ) |
---|
| 1140 | { |
---|
| 1141 | $tpl->assign( "br", "</tr><tr>" ); |
---|
| 1142 | } |
---|
| 1143 | } |
---|
| 1144 | } |
---|
| 1145 | } |
---|
| 1146 | } |
---|
| 1147 | ?> |
---|