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