[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 731 2013-03-24 01:07:26Z 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; |
---|
[731] | 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; |
---|
[731] | 510 | if( isset($conf['default_metric']) and ($metricname =='') ) |
---|
| 511 | $metricname = $conf['default_metric']; |
---|
| 512 | else |
---|
| 513 | if( isset( $m ) ) |
---|
| 514 | $metricname = $m; |
---|
| 515 | else |
---|
| 516 | $metricname = "load_one"; |
---|
[328] | 517 | |
---|
[719] | 518 | $tpl->assign("sortorder", $sortorder ); |
---|
| 519 | $tpl->assign("sortby", $sortby ); |
---|
[117] | 520 | |
---|
[719] | 521 | $sorted_jobs = sortJobs( $jobs, $sortby, $sortorder ); |
---|
[117] | 522 | |
---|
[719] | 523 | $even = 1; |
---|
[118] | 524 | |
---|
[719] | 525 | $used_jobs = 0; |
---|
| 526 | $used_cpus = 0; |
---|
| 527 | $used_nodes = 0; |
---|
[124] | 528 | |
---|
[719] | 529 | $queued_jobs = 0; |
---|
| 530 | $queued_nodes = 0; |
---|
| 531 | $queued_cpus = 0; |
---|
[208] | 532 | |
---|
[719] | 533 | $total_nodes = 0; |
---|
| 534 | $total_cpus = 0; |
---|
| 535 | $total_jobs = 0; |
---|
[208] | 536 | |
---|
[719] | 537 | $all_used_nodes = array(); |
---|
| 538 | $total_used_nodes = array(); |
---|
[124] | 539 | |
---|
[719] | 540 | $running_name_nodes = array(); |
---|
[208] | 541 | |
---|
[719] | 542 | $running_nodes = 0; |
---|
| 543 | $running_jobs = 0; |
---|
| 544 | $running_cpus = 0; |
---|
[208] | 545 | |
---|
[719] | 546 | $avail_nodes = count( $gnodes ); |
---|
| 547 | $avail_cpus = cluster_sum("cpu_num", $metrics); |
---|
[135] | 548 | |
---|
[719] | 549 | $view_cpus = 0; |
---|
| 550 | $view_jobs = 0; |
---|
| 551 | $view_nodes = 0; |
---|
[135] | 552 | |
---|
[719] | 553 | $all_nodes = 0; |
---|
| 554 | $all_jobs = 0; |
---|
| 555 | $all_cpus = 0; |
---|
[135] | 556 | |
---|
[719] | 557 | $view_name_nodes = array(); |
---|
[208] | 558 | |
---|
[719] | 559 | // Is the "requested memory" column enabled in the config |
---|
| 560 | // |
---|
| 561 | if( $COLUMN_REQUESTED_MEMORY ) |
---|
| 562 | { |
---|
| 563 | $tpl->newBlock( "column_header_req_mem" ); |
---|
| 564 | } |
---|
[241] | 565 | |
---|
[719] | 566 | // Is the "nodes hostnames" column enabled in the config |
---|
| 567 | // |
---|
| 568 | if( $COLUMN_NODES ) |
---|
| 569 | { |
---|
| 570 | $tpl->newBlock( "column_header_nodes" ); |
---|
| 571 | } |
---|
[299] | 572 | |
---|
[719] | 573 | // Is the "queued time" column enabled in the config |
---|
| 574 | // |
---|
| 575 | if( $COLUMN_QUEUED ) |
---|
| 576 | { |
---|
| 577 | $tpl->newBlock( "column_header_queued" ); |
---|
| 578 | } |
---|
[242] | 579 | |
---|
[719] | 580 | $last_displayed_job = null; |
---|
[263] | 581 | |
---|
[719] | 582 | $rjqj_host = null; |
---|
[406] | 583 | |
---|
[719] | 584 | $na_nodes = 0; |
---|
| 585 | $na_cpus = 0; |
---|
[512] | 586 | |
---|
[719] | 587 | foreach( $metrics as $bhost => $bmetric ) |
---|
| 588 | { |
---|
| 589 | foreach( $bmetric as $mname => $mval ) |
---|
| 590 | { |
---|
[726] | 591 | if( ( $mname == 'zplugin_monarch_rj' ) || ($mname == 'zplugin_monarch_qj') ) |
---|
[719] | 592 | { |
---|
| 593 | $rjqj_host = $bhost; |
---|
| 594 | } |
---|
| 595 | } |
---|
| 596 | } |
---|
[409] | 597 | |
---|
[719] | 598 | foreach( $gnodes as $ghost => $gnode ) |
---|
| 599 | { |
---|
| 600 | if( $gnode->isDown() || $gnode->isOffline() ) |
---|
| 601 | { |
---|
| 602 | $na_nodes += 1; |
---|
| 603 | $na_cpus += $metrics[$ghost]['cpu_num']['VAL']; |
---|
| 604 | } |
---|
| 605 | } |
---|
[516] | 606 | |
---|
[719] | 607 | // Running / queued amount jobs graph |
---|
| 608 | // |
---|
| 609 | if( $rjqj_host != null ) |
---|
| 610 | { |
---|
[409] | 611 | |
---|
[719] | 612 | $rjqj_str = "<A HREF=\"./graph.php?z=large&c=$clustername&g=job_report&r=$range&st=$cluster[LOCALTIME]\">"; |
---|
| 613 | $rjqj_str .= "<IMG BORDER=0 SRC=\"./graph.php?z=small&c=$clustername&g=job_report&r=$range&st=$cluster[LOCALTIME]\">"; |
---|
| 614 | $rjqj_str .= "</A>"; |
---|
[416] | 615 | |
---|
[719] | 616 | $tpl->gotoBlock( "_ROOT" ); |
---|
[416] | 617 | |
---|
[719] | 618 | $tpl->assign( "rjqj_graph", $rjqj_str ); |
---|
| 619 | } |
---|
[416] | 620 | |
---|
[719] | 621 | foreach( $sorted_jobs as $jobid => $sortdec ) |
---|
| 622 | { |
---|
| 623 | $report_time = $jobs[$jobid]['reported']; |
---|
[117] | 624 | |
---|
[719] | 625 | if( $jobs[$jobid]['status'] == 'R' ) |
---|
| 626 | { |
---|
| 627 | $nodes = count( $jobs[$jobid]['nodes'] ); |
---|
| 628 | } |
---|
| 629 | else if( $jobs[$jobid]['status'] == 'Q' ) |
---|
| 630 | { |
---|
| 631 | $nodes = $jobs[$jobid]['nodes']; |
---|
| 632 | } |
---|
[208] | 633 | |
---|
[719] | 634 | $ppn = isset( $jobs[$jobid]['ppn'] ) ? $jobs[$jobid]['ppn'] : 1; |
---|
| 635 | $cpus = $nodes * $ppn; |
---|
[124] | 636 | |
---|
[719] | 637 | if( $report_time == $heartbeat ) |
---|
| 638 | { |
---|
| 639 | $display_job = 1; |
---|
[124] | 640 | |
---|
[719] | 641 | if( $jobs[$jobid]['status'] == 'R' ) |
---|
| 642 | { |
---|
| 643 | foreach( $jobs[$jobid]['nodes'] as $tempnode ) |
---|
| 644 | { |
---|
| 645 | $all_used_nodes[] = $tempnode; |
---|
| 646 | } |
---|
| 647 | } |
---|
[208] | 648 | |
---|
[719] | 649 | $used_cpus += $cpus; |
---|
[135] | 650 | |
---|
[719] | 651 | if( $jobs[$jobid]['status'] == 'R' ) |
---|
| 652 | { |
---|
| 653 | $running_cpus += $cpus; |
---|
[328] | 654 | |
---|
[719] | 655 | $running_jobs++; |
---|
[117] | 656 | |
---|
[719] | 657 | $found_node_job = 0; |
---|
[268] | 658 | |
---|
[719] | 659 | foreach( $jobs[$jobid]['nodes'] as $tempnode ) |
---|
| 660 | { |
---|
| 661 | $running_name_nodes[] = $tempnode; |
---|
[263] | 662 | |
---|
[719] | 663 | if( isset( $hostname ) && $hostname != '' ) |
---|
| 664 | { |
---|
| 665 | $domain_len = 0 - strlen( $jobs[$jobid]['domain'] ); |
---|
| 666 | $hostnode = $tempnode; |
---|
[328] | 667 | |
---|
[719] | 668 | if( $use_fqdn == 1) |
---|
| 669 | { |
---|
| 670 | if( substr( $hostnode, $domain_len ) != $jobs[$jobid]['domain'] ) |
---|
| 671 | { |
---|
| 672 | $hostnode = $hostnode. '.'. $jobs[$jobid]['domain']; |
---|
| 673 | } |
---|
| 674 | } |
---|
[263] | 675 | |
---|
[719] | 676 | if( $hostname == $hostnode ) |
---|
| 677 | { |
---|
| 678 | $found_node_job = 1; |
---|
| 679 | $display_job = 1; |
---|
| 680 | } |
---|
| 681 | else if( !$found_node_job ) |
---|
| 682 | { |
---|
| 683 | $display_job = 0; |
---|
| 684 | } |
---|
| 685 | } |
---|
| 686 | } |
---|
| 687 | } |
---|
[117] | 688 | |
---|
[719] | 689 | if( $jobs[$jobid]['status'] == 'Q' ) |
---|
| 690 | { |
---|
| 691 | if( isset( $hostname ) && $hostname != '' ) |
---|
| 692 | { |
---|
| 693 | $display_job = 0; |
---|
| 694 | } |
---|
[263] | 695 | |
---|
[719] | 696 | $queued_cpus += $cpus; |
---|
| 697 | $queued_nodes += $nodes; |
---|
[328] | 698 | |
---|
[719] | 699 | $queued_jobs++; |
---|
| 700 | } |
---|
[208] | 701 | |
---|
[719] | 702 | foreach( $filter as $filtername=>$filtervalue ) |
---|
| 703 | { |
---|
| 704 | if( $filtername == 'id' && $jobid != $filtervalue ) |
---|
| 705 | { |
---|
| 706 | $display_job = 0; |
---|
| 707 | } |
---|
| 708 | else if( $filtername == 'state' && $jobs[$jobid]['status'] != $filtervalue ) |
---|
| 709 | { |
---|
| 710 | $display_job = 0; |
---|
| 711 | } |
---|
| 712 | else if( $filtername == 'queue' && $jobs[$jobid]['queue'] != $filtervalue ) |
---|
| 713 | { |
---|
| 714 | $display_job = 0; |
---|
| 715 | } |
---|
| 716 | else if( $filtername == 'owner' && $jobs[$jobid]['owner'] != $filtervalue ) |
---|
| 717 | { |
---|
| 718 | $display_job = 0; |
---|
| 719 | } |
---|
| 720 | } |
---|
[118] | 721 | |
---|
[719] | 722 | if( $display_job ) |
---|
| 723 | { |
---|
| 724 | $tpl->newBlock( "node" ); |
---|
| 725 | $tpl->assign( "clustername", $clustername ); |
---|
| 726 | $tpl->assign( "id", $jobid ); |
---|
[263] | 727 | |
---|
[719] | 728 | $last_displayed_job = $jobid; |
---|
[263] | 729 | |
---|
[719] | 730 | $tpl->assign( "state", $jobs[$jobid]['status'] ); |
---|
[240] | 731 | |
---|
[719] | 732 | $fullstate = ''; |
---|
[328] | 733 | |
---|
[719] | 734 | if( $jobs[$jobid]['status'] == 'R' ) |
---|
| 735 | { |
---|
| 736 | $fullstate = "Running"; |
---|
| 737 | } |
---|
| 738 | else if( $jobs[$jobid]['status'] == 'Q' ) |
---|
| 739 | { |
---|
| 740 | $fullstate = "Queued"; |
---|
| 741 | } |
---|
[240] | 742 | |
---|
[719] | 743 | $tpl->assign( "fullstate", $fullstate ); |
---|
| 744 | |
---|
| 745 | $tpl->assign( "owner", $jobs[$jobid]['owner'] ); |
---|
| 746 | $tpl->assign( "queue", $jobs[$jobid]['queue'] ); |
---|
[240] | 747 | |
---|
[719] | 748 | $fulljobname = $jobs[$jobid]['name']; |
---|
| 749 | $shortjobname = ''; |
---|
[240] | 750 | |
---|
[719] | 751 | $tpl->assign( "fulljobname", $fulljobname ); |
---|
[240] | 752 | |
---|
[719] | 753 | $fulljobname_fields = explode( ' ', $fulljobname ); |
---|
[311] | 754 | |
---|
[719] | 755 | $capjobname = 0; |
---|
[311] | 756 | |
---|
[719] | 757 | if( strlen( $fulljobname_fields[0] ) > 10 ) |
---|
| 758 | { |
---|
| 759 | $capjobname = 1; |
---|
| 760 | } |
---|
[311] | 761 | |
---|
[719] | 762 | if( $capjobname ) |
---|
| 763 | { |
---|
| 764 | $tpl->newBlock( "jobname_hint_start" ); |
---|
| 765 | $tpl->gotoBlock( "node" ); |
---|
[240] | 766 | |
---|
[719] | 767 | $shortjobname = substr( $fulljobname, 0, 10 ) . '..'; |
---|
| 768 | } |
---|
| 769 | else |
---|
| 770 | { |
---|
| 771 | $shortjobname = $fulljobname; |
---|
| 772 | } |
---|
| 773 | |
---|
| 774 | $tpl->assign( "name", $shortjobname ); |
---|
[240] | 775 | |
---|
[719] | 776 | if( $capjobname ) |
---|
| 777 | { |
---|
| 778 | $tpl->newBlock( "jobname_hint_end" ); |
---|
| 779 | $tpl->gotoBlock( "node" ); |
---|
| 780 | } |
---|
[240] | 781 | |
---|
[719] | 782 | $domain = $jobs[$jobid]['domain']; |
---|
[135] | 783 | |
---|
[719] | 784 | $tpl->assign( "req_cpu", makeTime( timeToEpoch( $jobs[$jobid]['requested_time'] ) ) ); |
---|
[328] | 785 | |
---|
[719] | 786 | if( $COLUMN_REQUESTED_MEMORY ) |
---|
| 787 | { |
---|
| 788 | $tpl->newBlock( "column_req_mem" ); |
---|
| 789 | $tpl->assign( "req_memory", $jobs[$jobid]['requested_memory'] ); |
---|
| 790 | $tpl->gotoBlock( "node" ); |
---|
| 791 | } |
---|
[135] | 792 | |
---|
[299] | 793 | |
---|
[719] | 794 | if( $COLUMN_QUEUED ) |
---|
| 795 | { |
---|
| 796 | $tpl->newBlock( "column_queued" ); |
---|
| 797 | $tpl->assign( "queued", makeDate( $jobs[$jobid]['queued_timestamp'] ) ); |
---|
| 798 | $tpl->gotoBlock( "node" ); |
---|
| 799 | } |
---|
| 800 | if( $COLUMN_NODES ) |
---|
| 801 | { |
---|
| 802 | $tpl->newBlock( "column_nodes" ); |
---|
| 803 | $tpl->gotoBlock( "node" ); |
---|
| 804 | } |
---|
[242] | 805 | |
---|
[719] | 806 | $ppn = isset( $jobs[$jobid]['ppn'] ) ? $jobs[$jobid]['ppn'] : 1; |
---|
| 807 | $cpus = $nodes * $ppn; |
---|
[119] | 808 | |
---|
[719] | 809 | $tpl->assign( "nodes", $nodes ); |
---|
| 810 | $tpl->assign( "cpus", $cpus ); |
---|
[328] | 811 | |
---|
[719] | 812 | $start_time = (int) $jobs[$jobid]['start_timestamp']; |
---|
| 813 | $job_start = $start_time; |
---|
[328] | 814 | |
---|
[719] | 815 | $view_cpus += $cpus; |
---|
[328] | 816 | |
---|
[719] | 817 | $view_jobs++; |
---|
[124] | 818 | |
---|
[719] | 819 | if( $jobs[$jobid]['status'] == 'R' ) |
---|
| 820 | { |
---|
| 821 | foreach( $jobs[$jobid]['nodes'] as $tempnode ) |
---|
| 822 | { |
---|
| 823 | $view_name_nodes[] = $tempnode; |
---|
| 824 | } |
---|
[299] | 825 | |
---|
[719] | 826 | if( $COLUMN_NODES ) |
---|
| 827 | { |
---|
| 828 | $tpl->gotoBlock( "column_nodes" ); |
---|
[328] | 829 | |
---|
[719] | 830 | $mynodehosts = array(); |
---|
[328] | 831 | |
---|
[730] | 832 | foreach( $jobs[$jobid]['nodes'] as $shortnode ) |
---|
[719] | 833 | { |
---|
| 834 | if( $use_fqdn == 1) |
---|
| 835 | { |
---|
[730] | 836 | $mynode = $shortnode.".".$jobs[$jobid]['domain']; |
---|
[719] | 837 | } |
---|
| 838 | $myhost_href = "./?c=".$clustername."&h=".$mynode; |
---|
[730] | 839 | $mynodehosts[] = "<A HREF=\"".$myhost_href."\">".$shortnode."</A>"; |
---|
[719] | 840 | } |
---|
[328] | 841 | |
---|
[719] | 842 | $nodes_hostnames = implode( " ", $mynodehosts ); |
---|
[328] | 843 | |
---|
[719] | 844 | $tpl->assign( "nodes_hostnames", $nodes_hostnames ); |
---|
| 845 | $tpl->gotoBlock( "node" ); |
---|
| 846 | } |
---|
| 847 | } |
---|
| 848 | else if( $jobs[$jobid]['status'] == 'Q' ) |
---|
| 849 | { |
---|
| 850 | $view_nodes += (int) $jobs[$jobid]['nodes']; |
---|
| 851 | } |
---|
[135] | 852 | |
---|
[719] | 853 | if( $even ) |
---|
| 854 | { |
---|
| 855 | $tpl->assign( "nodeclass", "even" ); |
---|
[119] | 856 | |
---|
[719] | 857 | $even = 0; |
---|
| 858 | } |
---|
| 859 | else |
---|
| 860 | { |
---|
| 861 | $tpl->assign( "nodeclass", "odd" ); |
---|
[119] | 862 | |
---|
[719] | 863 | $even = 1; |
---|
| 864 | } |
---|
[119] | 865 | |
---|
[719] | 866 | if( $start_time ) |
---|
| 867 | { |
---|
| 868 | $runningtime = makeTime( $report_time - $start_time ); |
---|
| 869 | $job_runningtime = $heartbeat - $start_time; |
---|
[119] | 870 | |
---|
[719] | 871 | $tpl->assign( "started", makeDate( $start_time ) ); |
---|
| 872 | $tpl->assign( "runningtime", $runningtime ); |
---|
| 873 | } |
---|
| 874 | } |
---|
| 875 | } |
---|
| 876 | } |
---|
[208] | 877 | |
---|
[719] | 878 | $all_used_nodes = array_unique( $all_used_nodes ); |
---|
| 879 | $view_name_nodes = array_unique( $view_name_nodes ); |
---|
| 880 | $running_name_nodes = array_unique( $running_name_nodes ); |
---|
[124] | 881 | |
---|
[719] | 882 | $used_nodes = count( $all_used_nodes ); |
---|
| 883 | $view_nodes += count( $view_name_nodes ); |
---|
| 884 | $running_nodes += count( $running_name_nodes ); |
---|
[208] | 885 | |
---|
[719] | 886 | $total_nodes = $queued_nodes + $running_nodes; |
---|
| 887 | $total_cpus = $queued_cpus + $running_cpus; |
---|
| 888 | $total_jobs = $queued_jobs + $running_jobs; |
---|
[135] | 889 | |
---|
[719] | 890 | $free_nodes = $avail_nodes - $running_nodes - $na_nodes; |
---|
| 891 | $free_nodes = ( $free_nodes >= 0 ) ? $free_nodes : 0; |
---|
| 892 | $free_cpus = $avail_cpus - $running_cpus - $na_cpus; |
---|
| 893 | $free_cpus = ( $free_cpus >= 0 ) ? $free_cpus : 0; |
---|
[208] | 894 | |
---|
[719] | 895 | $tpl->assignGlobal( "avail_nodes", $avail_nodes ); |
---|
| 896 | $tpl->assignGlobal( "avail_cpus", $avail_cpus ); |
---|
[208] | 897 | |
---|
[719] | 898 | $tpl->assignGlobal( "queued_nodes", $queued_nodes ); |
---|
| 899 | $tpl->assignGlobal( "queued_jobs", $queued_jobs ); |
---|
| 900 | $tpl->assignGlobal( "queued_cpus", $queued_cpus ); |
---|
[208] | 901 | |
---|
[719] | 902 | // Only display "Unavailable" in count overview there are any |
---|
| 903 | // |
---|
| 904 | if( $na_nodes > 0 ) |
---|
| 905 | { |
---|
| 906 | $tpl->newBlock( "na_nodes" ); |
---|
[512] | 907 | |
---|
[719] | 908 | $tpl->assignGlobal( "na_nodes", $na_nodes ); |
---|
| 909 | $tpl->assignGlobal( "na_cpus", $na_cpus ); |
---|
[517] | 910 | |
---|
[719] | 911 | $tpl->gotoBlock( "_ROOT" ); |
---|
| 912 | } |
---|
[517] | 913 | |
---|
[719] | 914 | $tpl->assignGlobal( "total_nodes", $total_nodes ); |
---|
| 915 | $tpl->assignGlobal( "total_jobs", $total_jobs ); |
---|
| 916 | $tpl->assignGlobal( "total_cpus", $total_cpus ); |
---|
[135] | 917 | |
---|
[719] | 918 | $tpl->assignGlobal( "running_nodes", $running_nodes ); |
---|
| 919 | $tpl->assignGlobal( "running_jobs", $running_jobs ); |
---|
| 920 | $tpl->assignGlobal( "running_cpus", $running_cpus ); |
---|
[208] | 921 | |
---|
[719] | 922 | $tpl->assignGlobal( "used_nodes", $used_nodes ); |
---|
| 923 | $tpl->assignGlobal( "used_jobs", $used_jobs ); |
---|
| 924 | $tpl->assignGlobal( "used_cpus", $used_cpus ); |
---|
[208] | 925 | |
---|
[719] | 926 | $tpl->assignGlobal( "free_nodes", $free_nodes ); |
---|
| 927 | $tpl->assignGlobal( "free_cpus", $free_cpus ); |
---|
[135] | 928 | |
---|
[719] | 929 | $tpl->assignGlobal( "view_nodes", $view_nodes ); |
---|
| 930 | $tpl->assignGlobal( "view_jobs", $view_jobs ); |
---|
| 931 | $tpl->assignGlobal( "view_cpus", $view_cpus ); |
---|
[126] | 932 | |
---|
[719] | 933 | $tpl->assignGlobal( "report_time", makeDate( $heartbeat) ); |
---|
[328] | 934 | |
---|
[719] | 935 | if( intval($view_jobs) == 1 and $start_time ) |
---|
| 936 | { |
---|
| 937 | if( $last_displayed_job != null ) |
---|
| 938 | { |
---|
| 939 | $filter['id'] = $last_displayed_job; |
---|
| 940 | } |
---|
| 941 | } |
---|
[263] | 942 | |
---|
[719] | 943 | global $longtitle, $title; |
---|
[406] | 944 | |
---|
[719] | 945 | $longtitle = "Batch Report :: Powered by Job Monarch!"; |
---|
| 946 | $title = "Batch Report"; |
---|
[406] | 947 | |
---|
[719] | 948 | makeHeader( 'overview', $title, $longtitle ); |
---|
[406] | 949 | |
---|
[719] | 950 | setupFilterSettings(); |
---|
[263] | 951 | |
---|
[719] | 952 | if( intval($view_jobs) == 1 and $start_time ) |
---|
| 953 | { |
---|
| 954 | $tpl->newBlock( "showhosts" ); |
---|
[126] | 955 | |
---|
[719] | 956 | # Present a width list |
---|
| 957 | $cols_menu = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n"; |
---|
[126] | 958 | |
---|
[719] | 959 | $hostcols = ($hc) ? $hc : 4; |
---|
[263] | 960 | |
---|
[719] | 961 | foreach( range( 1, 25 ) as $cols ) |
---|
| 962 | { |
---|
| 963 | $cols_menu .= "<OPTION VALUE=$cols "; |
---|
[126] | 964 | |
---|
[719] | 965 | if ($cols == $hostcols) |
---|
| 966 | { |
---|
| 967 | $cols_menu .= "SELECTED"; |
---|
| 968 | } |
---|
| 969 | $cols_menu .= ">$cols\n"; |
---|
| 970 | } |
---|
| 971 | $cols_menu .= "</SELECT>\n"; |
---|
[126] | 972 | |
---|
[719] | 973 | $tpl->assign( "metric","$metricname $units" ); |
---|
| 974 | $tpl->assign( "id", $filter['id'] ); |
---|
[328] | 975 | |
---|
[719] | 976 | # Host columns menu defined in header.php |
---|
| 977 | $tpl->assign( "cols_menu", $cols_menu ); |
---|
[126] | 978 | |
---|
[719] | 979 | $showhosts = isset($sh) ? $sh : $default_showhosts; |
---|
[126] | 980 | |
---|
[719] | 981 | $tpl->assign( "checked$showhosts", "checked" ); |
---|
[126] | 982 | |
---|
[719] | 983 | if( $showhosts ) |
---|
| 984 | { |
---|
| 985 | if( !isset( $start ) ) |
---|
| 986 | { |
---|
| 987 | $start ="jobstart"; |
---|
| 988 | } |
---|
| 989 | if( !isset( $stop ) ) |
---|
| 990 | { |
---|
| 991 | $stop ="now"; |
---|
| 992 | } |
---|
[126] | 993 | |
---|
[731] | 994 | $sorted_hosts = array(); |
---|
[719] | 995 | $hosts_up = $jobs[$filter['id']]['nodes']; |
---|
[126] | 996 | |
---|
[731] | 997 | $r = intval($job_runningtime * 1.2); |
---|
[126] | 998 | |
---|
[719] | 999 | $jobrange = -$r ; |
---|
| 1000 | $jobstart = $start_time; |
---|
[402] | 1001 | |
---|
[719] | 1002 | if ( $reports[$metricname] ) |
---|
| 1003 | { |
---|
| 1004 | $metricval = "g"; |
---|
| 1005 | } |
---|
| 1006 | else |
---|
| 1007 | { |
---|
| 1008 | $metricval = "m"; |
---|
| 1009 | } |
---|
| 1010 | |
---|
| 1011 | foreach ( $hosts_up as $host ) |
---|
| 1012 | { |
---|
| 1013 | $domain_len = 0 - strlen( $domain ); |
---|
[195] | 1014 | |
---|
[719] | 1015 | if( $use_fqdn ) |
---|
| 1016 | { |
---|
| 1017 | if( substr( $host, $domain_len ) != $domain ) |
---|
| 1018 | { |
---|
| 1019 | $host = $host . '.' . $domain; |
---|
| 1020 | } |
---|
| 1021 | } |
---|
[328] | 1022 | |
---|
[719] | 1023 | $cpus = $metrics[$host]["cpu_num"]["VAL"]; |
---|
[328] | 1024 | |
---|
[719] | 1025 | if ( !$cpus ) |
---|
| 1026 | { |
---|
| 1027 | $cpus = 1; |
---|
| 1028 | } |
---|
[328] | 1029 | |
---|
[719] | 1030 | $load_one = $metrics[$host]["load_one"]['VAL']; |
---|
| 1031 | $load = ((float) $load_one) / $cpus; |
---|
[731] | 1032 | $host_load[$host] = $load; |
---|
[328] | 1033 | |
---|
[719] | 1034 | $percent_hosts[load_color($load)] ++; |
---|
[328] | 1035 | |
---|
[719] | 1036 | if ($metricname=="load_one") |
---|
| 1037 | { |
---|
| 1038 | $sorted_hosts[$host] = $load; |
---|
| 1039 | } |
---|
| 1040 | else |
---|
| 1041 | { |
---|
| 1042 | $sorted_hosts[$host] = $metrics[$host][$metricname]['VAL']; |
---|
| 1043 | } |
---|
| 1044 | } |
---|
[463] | 1045 | |
---|
[719] | 1046 | switch ( $sort ) |
---|
| 1047 | { |
---|
| 1048 | case "descending": |
---|
| 1049 | arsort( $sorted_hosts ); |
---|
| 1050 | break; |
---|
[328] | 1051 | |
---|
[719] | 1052 | case "by hostname": |
---|
| 1053 | ksort( $sorted_hosts ); |
---|
| 1054 | break; |
---|
[328] | 1055 | |
---|
[719] | 1056 | case "ascending": |
---|
| 1057 | asort( $sorted_hosts ); |
---|
| 1058 | break; |
---|
[328] | 1059 | |
---|
[719] | 1060 | default: |
---|
| 1061 | break; |
---|
| 1062 | } |
---|
[126] | 1063 | |
---|
[719] | 1064 | // First pass to find the max value in all graphs for this |
---|
| 1065 | // metric. The $start,$end variables comes from get_context.php, |
---|
| 1066 | // included in index.php. |
---|
| 1067 | // |
---|
| 1068 | list($min, $max) = find_limits($sorted_hosts, $metricname); |
---|
[126] | 1069 | |
---|
[719] | 1070 | // Second pass to output the graphs or metrics. |
---|
| 1071 | $i = 1; |
---|
[126] | 1072 | |
---|
[719] | 1073 | foreach ( $sorted_hosts as $host=>$value ) |
---|
| 1074 | { |
---|
| 1075 | $tpl->newBlock( "sorted_list" ); |
---|
[126] | 1076 | |
---|
[731] | 1077 | $host_url = rawurlencode( $host ); |
---|
| 1078 | $cluster_url = rawurlencode( $clustername ); |
---|
[193] | 1079 | |
---|
[719] | 1080 | $textval = ""; |
---|
[328] | 1081 | |
---|
[719] | 1082 | $val = $metrics[$host][$metricname]; |
---|
[731] | 1083 | $class = "metric"; |
---|
| 1084 | $host_link = "\"../../?c=$cluster_url&h=$host_url&r=job&jr=$jobrange&js=$jobstart\""; |
---|
[328] | 1085 | |
---|
[719] | 1086 | if ( $val["TYPE"] == "timestamp" || $always_timestamp[$metricname] ) |
---|
| 1087 | { |
---|
| 1088 | $textval = date( "r", $val["VAL"] ); |
---|
| 1089 | } |
---|
| 1090 | elseif ( $val["TYPE"] == "string" || $val["SLOPE"] == "zero" || $always_constant[$metricname] || ($max_graphs > 0 and $i > $max_graphs )) |
---|
| 1091 | { |
---|
| 1092 | $textval = $val["VAL"] . " " . $val["UNITS"]; |
---|
| 1093 | } |
---|
| 1094 | else |
---|
| 1095 | { |
---|
[731] | 1096 | $job_start = $jobs[$last_displayed_job]['start_timestamp']; |
---|
| 1097 | $period_end = time(); |
---|
| 1098 | $runningtime = time() - intval( $job_start ); |
---|
[719] | 1099 | $load_color = load_color($host_load[$host]); |
---|
[731] | 1100 | $period_start = intval( $job_start - (intval( $runningtime * 0.10 ) ) ); |
---|
| 1101 | //printf("last job %s job start %s runningtime %s period start %s", $last_displayed_job, $jobstart, $job_runningtime, $period_start); |
---|
[719] | 1102 | $graphargs = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&"; |
---|
[731] | 1103 | $graphargs .= "z=overview-medium&c=$cluster_url&h=$host_url&l=$load_color&v=".$val['VAL']."&job_start=$job_start&period_start=$period_start&period_stop=$period_end"; |
---|
[719] | 1104 | if( $max > 0 ) |
---|
| 1105 | { |
---|
| 1106 | $graphargs .= "&x=$max&n=$min"; |
---|
| 1107 | } |
---|
| 1108 | } |
---|
| 1109 | if ($textval) |
---|
| 1110 | { |
---|
| 1111 | $cell = "<td class=$class>". "<b><a href=$host_link>$host</a></b><br>". "<i>$metricname:</i> <b>$textval</b></td>"; |
---|
| 1112 | } else { |
---|
[731] | 1113 | $cell = "<td><a href=$host_link>" . "<img src=\"./graph.php?$graphargs\" " . "alt=\"$host\" border=0></a></td>"; |
---|
[719] | 1114 | } |
---|
[126] | 1115 | |
---|
[719] | 1116 | $tpl->assign( "metric_image", $cell ); |
---|
[328] | 1117 | |
---|
[719] | 1118 | if(! ($i++ % $hostcols) ) |
---|
| 1119 | { |
---|
| 1120 | $tpl->assign( "br", "</tr><tr>" ); |
---|
| 1121 | } |
---|
| 1122 | } |
---|
| 1123 | } |
---|
| 1124 | } |
---|
[114] | 1125 | } |
---|
[113] | 1126 | ?> |
---|