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