[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 463 2008-02-07 09:35:47Z bastiaans $ |
---|
[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(); |
---|
| 257 | $node_cpus = $metrics[$myhost]["cpu_num"][VAL]; |
---|
| 258 | $job_cpu = 0; |
---|
[114] | 259 | |
---|
[328] | 260 | foreach( $myjobs as $myjob ) |
---|
| 261 | { |
---|
[315] | 262 | $job_cpu += (int) $jobs[$myjob][ppn] ? $jobs[$myjob][ppn] : 1; |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | $node_freecpu = $node_cpus - $job_cpu; |
---|
| 266 | |
---|
| 267 | $empty_cpus += $node_freecpu; |
---|
[114] | 268 | } |
---|
| 269 | |
---|
[457] | 270 | $empty_cpus = ( $empty_cpus >= 0 ) ? $empy_cpus : 0; |
---|
[315] | 271 | $used_cpus = $nr_cpus - $empty_cpus; |
---|
[114] | 272 | |
---|
[315] | 273 | $empty_percentage = ($empty_cpus / $nr_cpus) * 100; |
---|
[114] | 274 | |
---|
[315] | 275 | $qcolors = array(); |
---|
| 276 | $color = randomColor( $qcolors ); |
---|
| 277 | $qcolors[] = $color; |
---|
| 278 | $pie_args .= "&free=$empty_percentage,$color"; |
---|
| 279 | |
---|
[127] | 280 | if( isset( $piefilter ) ) |
---|
[328] | 281 | { |
---|
[127] | 282 | $filterpie = array(); |
---|
[328] | 283 | } |
---|
[127] | 284 | |
---|
[328] | 285 | foreach( $nodes as $node ) |
---|
| 286 | { |
---|
[315] | 287 | $node_jobs = $node->getJobs(); |
---|
| 288 | $nr_node_jobs = count( $node_jobs ); |
---|
| 289 | $myhost = $node->getHostname(); |
---|
| 290 | $node_cpus = $metrics[$myhost]["cpu_num"][VAL]; |
---|
[114] | 291 | |
---|
[328] | 292 | foreach( $node_jobs as $myjob ) |
---|
| 293 | { |
---|
[315] | 294 | $job_cpu = (int) $jobs[$myjob][ppn] ? $jobs[$myjob][ppn] : 1; |
---|
| 295 | |
---|
| 296 | // Determine the weight of this job |
---|
| 297 | // - what percentage of the cpus is in use by this job |
---|
[123] | 298 | // |
---|
[315] | 299 | $job_weight[$myjob] = ( $job_cpu / $nr_cpus ); |
---|
[123] | 300 | |
---|
[315] | 301 | |
---|
[328] | 302 | if( isset( $piefilter ) ) { |
---|
| 303 | |
---|
[127] | 304 | $countjob = 1; |
---|
[328] | 305 | |
---|
| 306 | if( $piefilter == 'id' ) |
---|
| 307 | { |
---|
[127] | 308 | if( $myjob != $filter[$piefilter] ) |
---|
[328] | 309 | { |
---|
[127] | 310 | $countjob = 0; |
---|
[328] | 311 | } |
---|
| 312 | } |
---|
| 313 | else if( $piefilter == 'user' ) |
---|
| 314 | { |
---|
[127] | 315 | if( $jobs[$myjob][owner] != $filter[$piefilter] ) |
---|
[328] | 316 | { |
---|
[127] | 317 | $countjob = 0; |
---|
[328] | 318 | } |
---|
| 319 | } |
---|
| 320 | else |
---|
| 321 | { |
---|
[127] | 322 | if( $jobs[$myjob][$piefilter] != $filter[$piefilter] ) |
---|
[328] | 323 | { |
---|
[127] | 324 | $countjob = 0; |
---|
[328] | 325 | } |
---|
[127] | 326 | } |
---|
| 327 | |
---|
[328] | 328 | if( $countjob ) |
---|
| 329 | { |
---|
[127] | 330 | |
---|
| 331 | if( !isset( $filterpie[$filter[$piefilter]] ) ) |
---|
[328] | 332 | { |
---|
[127] | 333 | $filterpie[$filter[$piefilter]] = $job_weight[$myjob]; |
---|
[328] | 334 | } |
---|
[127] | 335 | else |
---|
[328] | 336 | { |
---|
| 337 | |
---|
[127] | 338 | $filterpie[$filter[$piefilter]] = $filterpie[$filter[$piefilter]] + $job_weight[$myjob]; |
---|
[328] | 339 | } |
---|
| 340 | } |
---|
| 341 | else |
---|
| 342 | { |
---|
[127] | 343 | if( !isset( $filterpie["other"] ) ) |
---|
[328] | 344 | { |
---|
[127] | 345 | $filterpie["other"] = $job_weight[$myjob]; |
---|
[328] | 346 | } |
---|
[127] | 347 | else |
---|
[328] | 348 | { |
---|
[127] | 349 | $filterpie["other"] = $filterpie["other"] + $job_weight[$myjob]; |
---|
[328] | 350 | } |
---|
[127] | 351 | |
---|
| 352 | } |
---|
| 353 | |
---|
[328] | 354 | } |
---|
| 355 | else |
---|
| 356 | { |
---|
[127] | 357 | |
---|
[315] | 358 | $qname = $jobs[$myjob][queue]; |
---|
| 359 | |
---|
[127] | 360 | if( !isset( $queues[$qname] ) ) |
---|
[328] | 361 | { |
---|
[127] | 362 | $queues[$qname] = $job_weight[$myjob]; |
---|
[328] | 363 | } |
---|
[127] | 364 | else |
---|
[328] | 365 | { |
---|
[127] | 366 | $queues[$qname] = $queues[$qname] + $job_weight[$myjob]; |
---|
[328] | 367 | } |
---|
[127] | 368 | } |
---|
[114] | 369 | } |
---|
| 370 | } |
---|
| 371 | |
---|
[127] | 372 | if( isset( $piefilter ) ) |
---|
[328] | 373 | { |
---|
[127] | 374 | $graphvals = $filterpie; |
---|
[328] | 375 | } |
---|
[127] | 376 | else |
---|
[328] | 377 | { |
---|
[127] | 378 | $graphvals = $queues; |
---|
[328] | 379 | } |
---|
[114] | 380 | |
---|
[328] | 381 | foreach( $graphvals as $name => $totalweight) |
---|
| 382 | { |
---|
[315] | 383 | $percentage = ( $totalweight * 100 ); |
---|
[123] | 384 | |
---|
[315] | 385 | $color = randomColor( $qcolors ); |
---|
| 386 | $qcolors[] = $color; |
---|
| 387 | $pie_args .= "&$name=$percentage,$color"; |
---|
[114] | 388 | } |
---|
| 389 | $pie = "../../pie.php?$pie_args"; |
---|
| 390 | |
---|
| 391 | return $pie; |
---|
| 392 | } |
---|
| 393 | |
---|
| 394 | |
---|
[328] | 395 | function sortJobs( $jobs, $sortby, $sortorder ) |
---|
| 396 | { |
---|
| 397 | $sorted = array(); |
---|
[114] | 398 | |
---|
[328] | 399 | $cmp = create_function( '$a, $b', |
---|
[117] | 400 | "global \$sortby, \$sortorder;". |
---|
[116] | 401 | |
---|
[117] | 402 | "if( \$a == \$b ) return 0;". |
---|
[116] | 403 | |
---|
[117] | 404 | "if (\$sortorder==\"desc\")". |
---|
| 405 | "return ( \$a < \$b ) ? 1 : -1;". |
---|
| 406 | "else if (\$sortorder==\"asc\")". |
---|
| 407 | "return ( \$a > \$b ) ? 1 : -1;" ); |
---|
| 408 | |
---|
[328] | 409 | if( isset( $jobs ) && count( $jobs ) > 0 ) |
---|
| 410 | { |
---|
| 411 | foreach( $jobs as $jobid => $jobattrs ) |
---|
| 412 | { |
---|
| 413 | $state = $jobattrs[status]; |
---|
| 414 | $user = $jobattrs[owner]; |
---|
| 415 | $queue = $jobattrs[queue]; |
---|
| 416 | $name = $jobattrs[name]; |
---|
| 417 | $req_cpu = $jobattrs[requested_time]; |
---|
| 418 | $req_memory = $jobattrs[requested_memory]; |
---|
[117] | 419 | |
---|
[301] | 420 | if( $state == 'R' ) |
---|
[328] | 421 | { |
---|
[301] | 422 | $nodes = count( $jobattrs[nodes] ); |
---|
[328] | 423 | } |
---|
[301] | 424 | else |
---|
[328] | 425 | { |
---|
[301] | 426 | $nodes = $jobattrs[nodes]; |
---|
[328] | 427 | } |
---|
[117] | 428 | |
---|
[328] | 429 | $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1; |
---|
| 430 | $cpus = $nodes * $ppn; |
---|
| 431 | $queued_time = (int) $jobattrs[queued_timestamp]; |
---|
| 432 | $start_time = (int) $jobattrs[start_timestamp]; |
---|
| 433 | $runningtime = $report_time - $start_time; |
---|
[117] | 434 | |
---|
[328] | 435 | switch( $sortby ) |
---|
| 436 | { |
---|
[301] | 437 | case "id": |
---|
| 438 | $sorted[$jobid] = $jobid; |
---|
| 439 | break; |
---|
[117] | 440 | |
---|
[301] | 441 | case "state": |
---|
| 442 | $sorted[$jobid] = $state; |
---|
| 443 | break; |
---|
[117] | 444 | |
---|
[301] | 445 | case "user": |
---|
| 446 | $sorted[$jobid] = $user; |
---|
| 447 | break; |
---|
[117] | 448 | |
---|
[301] | 449 | case "queue": |
---|
| 450 | $sorted[$jobid] = $queue; |
---|
| 451 | break; |
---|
[117] | 452 | |
---|
[301] | 453 | case "name": |
---|
| 454 | $sorted[$jobid] = $name; |
---|
| 455 | break; |
---|
[117] | 456 | |
---|
[301] | 457 | case "req_cpu": |
---|
| 458 | $sorted[$jobid] = timeToEpoch( $req_cpu ); |
---|
| 459 | break; |
---|
[117] | 460 | |
---|
[301] | 461 | case "req_mem": |
---|
| 462 | $sorted[$jobid] = $req_memory; |
---|
| 463 | break; |
---|
[117] | 464 | |
---|
[301] | 465 | case "nodes": |
---|
| 466 | $sorted[$jobid] = $nodes; |
---|
| 467 | break; |
---|
[117] | 468 | |
---|
[301] | 469 | case "cpus": |
---|
| 470 | $sorted[$jobid] = $cpus; |
---|
| 471 | break; |
---|
[245] | 472 | |
---|
[301] | 473 | case "queued": |
---|
| 474 | $sorted[$jobid] = $queued_time; |
---|
| 475 | break; |
---|
[117] | 476 | |
---|
[301] | 477 | case "start": |
---|
| 478 | $sorted[$jobid] = $start_time; |
---|
| 479 | break; |
---|
[117] | 480 | |
---|
[301] | 481 | case "runningtime": |
---|
| 482 | $sorted[$jobid] = $runningtime; |
---|
| 483 | break; |
---|
[117] | 484 | |
---|
[301] | 485 | default: |
---|
| 486 | break; |
---|
| 487 | } |
---|
| 488 | } |
---|
| 489 | } |
---|
| 490 | |
---|
[128] | 491 | if( $sortorder == "asc" ) |
---|
[328] | 492 | { |
---|
[128] | 493 | arsort( $sorted ); |
---|
[328] | 494 | } |
---|
[128] | 495 | else if( $sortorder == "desc" ) |
---|
[328] | 496 | { |
---|
[128] | 497 | asort( $sorted ); |
---|
[328] | 498 | } |
---|
[117] | 499 | |
---|
| 500 | return $sorted; |
---|
| 501 | } |
---|
| 502 | |
---|
[328] | 503 | function makeOverview() |
---|
| 504 | { |
---|
[117] | 505 | global $jobs, $nodes, $heartbeat, $clustername, $tpl; |
---|
[409] | 506 | global $sortorder, $sortby, $filter, $sh, $hc, $m, $range; |
---|
[126] | 507 | global $cluster_url, $get_metric_string, $host_url, $metrics; |
---|
[129] | 508 | global $start, $end, $reports, $gnodes, $default_showhosts; |
---|
[299] | 509 | global $COLUMN_QUEUED, $COLUMN_REQUESTED_MEMORY, $COLUMN_NODES, $hostname; |
---|
[463] | 510 | global $cluster, $use_fqdn; |
---|
[126] | 511 | |
---|
[328] | 512 | $metricname = $m; |
---|
| 513 | |
---|
[117] | 514 | $tpl->assign("sortorder", $sortorder ); |
---|
| 515 | $tpl->assign("sortby", $sortby ); |
---|
| 516 | |
---|
[328] | 517 | $sorted_jobs = sortJobs( $jobs, $sortby, $sortorder ); |
---|
[117] | 518 | |
---|
[328] | 519 | $even = 1; |
---|
[118] | 520 | |
---|
[328] | 521 | $used_jobs = 0; |
---|
| 522 | $used_cpus = 0; |
---|
| 523 | $used_nodes = 0; |
---|
[124] | 524 | |
---|
[328] | 525 | $queued_jobs = 0; |
---|
| 526 | $queued_nodes = 0; |
---|
| 527 | $queued_cpus = 0; |
---|
[208] | 528 | |
---|
[328] | 529 | $total_nodes = 0; |
---|
| 530 | $total_cpus = 0; |
---|
| 531 | $total_jobs = 0; |
---|
[208] | 532 | |
---|
[328] | 533 | $all_used_nodes = array(); |
---|
| 534 | $total_used_nodes = array(); |
---|
[124] | 535 | |
---|
[328] | 536 | $running_name_nodes = array(); |
---|
[208] | 537 | |
---|
[328] | 538 | $running_nodes = 0; |
---|
| 539 | $running_jobs = 0; |
---|
| 540 | $running_cpus = 0; |
---|
[208] | 541 | |
---|
[328] | 542 | $avail_nodes = count( $gnodes ); |
---|
| 543 | $avail_cpus = cluster_sum("cpu_num", $metrics); |
---|
[135] | 544 | |
---|
[328] | 545 | $view_cpus = 0; |
---|
| 546 | $view_jobs = 0; |
---|
| 547 | $view_nodes = 0; |
---|
[135] | 548 | |
---|
[328] | 549 | $all_nodes = 0; |
---|
| 550 | $all_jobs = 0; |
---|
| 551 | $all_cpus = 0; |
---|
[135] | 552 | |
---|
[328] | 553 | $view_name_nodes = array(); |
---|
[208] | 554 | |
---|
[463] | 555 | // Is the "requested memory" column enabled in the config |
---|
| 556 | // |
---|
[328] | 557 | if( $COLUMN_REQUESTED_MEMORY ) |
---|
| 558 | { |
---|
[242] | 559 | $tpl->newBlock( "column_header_req_mem" ); |
---|
[241] | 560 | } |
---|
| 561 | |
---|
[463] | 562 | // Is the "nodes hostnames" column enabled in the config |
---|
| 563 | // |
---|
[328] | 564 | if( $COLUMN_NODES ) |
---|
| 565 | { |
---|
[299] | 566 | $tpl->newBlock( "column_header_nodes" ); |
---|
| 567 | } |
---|
| 568 | |
---|
[463] | 569 | // Is the "queued time" column enabled in the config |
---|
| 570 | // |
---|
[328] | 571 | if( $COLUMN_QUEUED ) |
---|
| 572 | { |
---|
[242] | 573 | $tpl->newBlock( "column_header_queued" ); |
---|
| 574 | } |
---|
| 575 | |
---|
[328] | 576 | $last_displayed_job = null; |
---|
[263] | 577 | |
---|
[416] | 578 | $rjqj_host = null; |
---|
[406] | 579 | |
---|
[416] | 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 | |
---|
[463] | 591 | // Running / queued amount jobs graph |
---|
| 592 | // |
---|
[416] | 593 | if( $rjqj_host != null ) |
---|
| 594 | { |
---|
[409] | 595 | |
---|
[416] | 596 | $rjqj_str = "<IMG SRC=\"./graph.php?z=small&c=$clustername&g=job_report&r=$range&st=$cluster[LOCALTIME]\">"; |
---|
| 597 | |
---|
| 598 | $tpl->gotoBlock( "_ROOT" ); |
---|
| 599 | |
---|
| 600 | $tpl->assign( "rjqj_graph", $rjqj_str ); |
---|
| 601 | } |
---|
| 602 | |
---|
[328] | 603 | foreach( $sorted_jobs as $jobid => $sortdec ) |
---|
| 604 | { |
---|
| 605 | $report_time = $jobs[$jobid][reported]; |
---|
[117] | 606 | |
---|
[208] | 607 | if( $jobs[$jobid][status] == 'R' ) |
---|
[328] | 608 | { |
---|
[208] | 609 | $nodes = count( $jobs[$jobid][nodes] ); |
---|
[328] | 610 | } |
---|
[208] | 611 | else if( $jobs[$jobid][status] == 'Q' ) |
---|
[328] | 612 | { |
---|
[208] | 613 | $nodes = $jobs[$jobid][nodes]; |
---|
[328] | 614 | } |
---|
[208] | 615 | |
---|
[328] | 616 | $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1; |
---|
| 617 | $cpus = $nodes * $ppn; |
---|
[124] | 618 | |
---|
[328] | 619 | if( $report_time == $heartbeat ) |
---|
| 620 | { |
---|
| 621 | $display_job = 1; |
---|
[124] | 622 | |
---|
[328] | 623 | if( $jobs[$jobid][status] == 'R' ) |
---|
| 624 | { |
---|
| 625 | foreach( $jobs[$jobid][nodes] as $tempnode ) |
---|
| 626 | { |
---|
[300] | 627 | $all_used_nodes[] = $tempnode; |
---|
| 628 | } |
---|
| 629 | } |
---|
[208] | 630 | |
---|
[135] | 631 | $used_cpus += $cpus; |
---|
| 632 | |
---|
[328] | 633 | if( $jobs[$jobid][status] == 'R' ) |
---|
| 634 | { |
---|
| 635 | $running_cpus += $cpus; |
---|
| 636 | |
---|
[208] | 637 | $running_jobs++; |
---|
[117] | 638 | |
---|
[328] | 639 | $found_node_job = 0; |
---|
[268] | 640 | |
---|
[328] | 641 | foreach( $jobs[$jobid][nodes] as $tempnode ) |
---|
| 642 | { |
---|
[208] | 643 | $running_name_nodes[] = $tempnode; |
---|
[263] | 644 | |
---|
[328] | 645 | if( isset( $hostname ) && $hostname != '' ) |
---|
| 646 | { |
---|
[263] | 647 | //$filter[host] = $hostname; |
---|
| 648 | |
---|
[328] | 649 | $domain_len = 0 - strlen( $jobs[$jobid][domain] ); |
---|
| 650 | $hostnode = $tempnode; |
---|
| 651 | |
---|
[463] | 652 | if( $use_fqdn == 1) |
---|
| 653 | { |
---|
| 654 | if( substr( $hostnode, $domain_len ) != $jobs[$jobid][domain] ) |
---|
| 655 | { |
---|
| 656 | $hostnode = $hostnode. '.'. $jobs[$jobid][domain]; |
---|
| 657 | } |
---|
| 658 | } |
---|
[263] | 659 | |
---|
[328] | 660 | if( $hostname == $hostnode ) |
---|
| 661 | { |
---|
[268] | 662 | $found_node_job = 1; |
---|
| 663 | $display_job = 1; |
---|
[328] | 664 | } |
---|
| 665 | else if( !$found_node_job ) |
---|
| 666 | { |
---|
[263] | 667 | $display_job = 0; |
---|
[268] | 668 | } |
---|
[297] | 669 | } |
---|
[263] | 670 | } |
---|
[208] | 671 | } |
---|
[117] | 672 | |
---|
[328] | 673 | if( $jobs[$jobid][status] == 'Q' ) |
---|
| 674 | { |
---|
[263] | 675 | if( isset( $hostname ) && $hostname != '' ) |
---|
[328] | 676 | { |
---|
[263] | 677 | $display_job = 0; |
---|
[328] | 678 | } |
---|
[263] | 679 | |
---|
[328] | 680 | $queued_cpus += $cpus; |
---|
| 681 | $queued_nodes += $nodes; |
---|
| 682 | |
---|
[208] | 683 | $queued_jobs++; |
---|
| 684 | } |
---|
| 685 | |
---|
[328] | 686 | foreach( $filter as $filtername=>$filtervalue ) |
---|
| 687 | { |
---|
[124] | 688 | if( $filtername == 'id' && $jobid != $filtervalue ) |
---|
[328] | 689 | { |
---|
[124] | 690 | $display_job = 0; |
---|
[328] | 691 | } |
---|
[124] | 692 | else if( $filtername == 'state' && $jobs[$jobid][status] != $filtervalue ) |
---|
[328] | 693 | { |
---|
[124] | 694 | $display_job = 0; |
---|
[328] | 695 | } |
---|
[124] | 696 | else if( $filtername == 'queue' && $jobs[$jobid][queue] != $filtervalue ) |
---|
[328] | 697 | { |
---|
[124] | 698 | $display_job = 0; |
---|
[328] | 699 | } |
---|
[124] | 700 | else if( $filtername == 'user' && $jobs[$jobid][owner] != $filtervalue ) |
---|
[328] | 701 | { |
---|
[124] | 702 | $display_job = 0; |
---|
[328] | 703 | } |
---|
[118] | 704 | } |
---|
| 705 | |
---|
[328] | 706 | if( $display_job ) |
---|
| 707 | { |
---|
| 708 | $tpl->newBlock( "node" ); |
---|
[119] | 709 | $tpl->assign( "clustername", $clustername ); |
---|
[328] | 710 | $tpl->assign( "id", $jobid ); |
---|
[263] | 711 | |
---|
[328] | 712 | $last_displayed_job = $jobid; |
---|
[263] | 713 | |
---|
[328] | 714 | $tpl->assign( "state", $jobs[$jobid][status] ); |
---|
[240] | 715 | |
---|
[328] | 716 | $fullstate = ''; |
---|
| 717 | |
---|
| 718 | if( $jobs[$jobid][status] == 'R' ) |
---|
| 719 | { |
---|
| 720 | $fullstate = "Running"; |
---|
| 721 | } |
---|
| 722 | else if( $jobs[$jobid][status] == 'Q' ) |
---|
| 723 | { |
---|
| 724 | $fullstate = "Queued"; |
---|
[240] | 725 | } |
---|
| 726 | |
---|
[328] | 727 | $tpl->assign( "fullstate", $fullstate ); |
---|
[240] | 728 | |
---|
[328] | 729 | $tpl->assign( "user", $jobs[$jobid][owner] ); |
---|
| 730 | $tpl->assign( "queue", $jobs[$jobid][queue] ); |
---|
[240] | 731 | |
---|
[328] | 732 | $fulljobname = $jobs[$jobid][name]; |
---|
| 733 | $shortjobname = ''; |
---|
[240] | 734 | |
---|
[328] | 735 | $tpl->assign( "fulljobname", $fulljobname ); |
---|
[240] | 736 | |
---|
[311] | 737 | $fulljobname_fields = explode( ' ', $fulljobname ); |
---|
| 738 | |
---|
[328] | 739 | $capjobname = 0; |
---|
[311] | 740 | |
---|
| 741 | if( strlen( $fulljobname_fields[0] ) > 10 ) |
---|
[328] | 742 | { |
---|
[311] | 743 | $capjobname = 1; |
---|
[328] | 744 | } |
---|
[311] | 745 | |
---|
[328] | 746 | if( $capjobname ) |
---|
| 747 | { |
---|
| 748 | $tpl->newBlock( "jobname_hint_start" ); |
---|
| 749 | $tpl->gotoBlock( "node" ); |
---|
[240] | 750 | |
---|
[328] | 751 | $shortjobname = substr( $fulljobname, 0, 10 ) . '..'; |
---|
| 752 | } |
---|
| 753 | else |
---|
| 754 | { |
---|
| 755 | $shortjobname = $fulljobname; |
---|
[240] | 756 | } |
---|
| 757 | |
---|
[328] | 758 | $tpl->assign( "name", $shortjobname ); |
---|
[240] | 759 | |
---|
[328] | 760 | if( $capjobname ) |
---|
| 761 | { |
---|
| 762 | $tpl->newBlock( "jobname_hint_end" ); |
---|
| 763 | $tpl->gotoBlock( "node" ); |
---|
[240] | 764 | } |
---|
| 765 | |
---|
[328] | 766 | $domain = $jobs[$jobid][domain]; |
---|
[135] | 767 | |
---|
[328] | 768 | $tpl->assign( "req_cpu", makeTime( timeToEpoch( $jobs[$jobid][requested_time] ) ) ); |
---|
| 769 | |
---|
| 770 | if( $COLUMN_REQUESTED_MEMORY ) |
---|
| 771 | { |
---|
[241] | 772 | $tpl->newBlock( "column_req_mem" ); |
---|
| 773 | $tpl->assign( "req_memory", $jobs[$jobid][requested_memory] ); |
---|
| 774 | $tpl->gotoBlock( "node" ); |
---|
| 775 | } |
---|
[135] | 776 | |
---|
[299] | 777 | |
---|
[328] | 778 | if( $COLUMN_QUEUED ) |
---|
| 779 | { |
---|
[242] | 780 | $tpl->newBlock( "column_queued" ); |
---|
[243] | 781 | $tpl->assign( "queued", makeDate( $jobs[$jobid][queued_timestamp] ) ); |
---|
[242] | 782 | $tpl->gotoBlock( "node" ); |
---|
| 783 | } |
---|
[328] | 784 | if( $COLUMN_NODES ) |
---|
| 785 | { |
---|
[322] | 786 | $tpl->newBlock( "column_nodes" ); |
---|
| 787 | $tpl->gotoBlock( "node" ); |
---|
| 788 | } |
---|
[242] | 789 | |
---|
[328] | 790 | $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1; |
---|
| 791 | $cpus = $nodes * $ppn; |
---|
[119] | 792 | |
---|
[328] | 793 | $tpl->assign( "nodes", $nodes ); |
---|
| 794 | $tpl->assign( "cpus", $cpus ); |
---|
| 795 | |
---|
| 796 | $start_time = (int) $jobs[$jobid][start_timestamp]; |
---|
| 797 | $job_start = $start_time; |
---|
| 798 | |
---|
| 799 | $view_cpus += $cpus; |
---|
| 800 | |
---|
[135] | 801 | $view_jobs++; |
---|
[124] | 802 | |
---|
[328] | 803 | if( $jobs[$jobid][status] == 'R' ) |
---|
| 804 | { |
---|
[135] | 805 | foreach( $jobs[$jobid][nodes] as $tempnode ) |
---|
[328] | 806 | { |
---|
| 807 | $view_name_nodes[] = $tempnode; |
---|
| 808 | } |
---|
[299] | 809 | |
---|
[328] | 810 | if( $COLUMN_NODES ) |
---|
| 811 | { |
---|
[322] | 812 | $tpl->gotoBlock( "column_nodes" ); |
---|
[328] | 813 | |
---|
| 814 | $mynodehosts = array(); |
---|
| 815 | |
---|
| 816 | foreach( $jobs[$jobid][nodes] as $mynode ) |
---|
| 817 | { |
---|
[463] | 818 | if( $use_fqdn == 1) |
---|
| 819 | { |
---|
| 820 | $mynode = $mynode.".".$jobs[$jobid][domain]; |
---|
| 821 | } |
---|
[462] | 822 | $myhost_href = "./?c=".$clustername."&h=".$mynode; |
---|
[328] | 823 | $mynodehosts[] = "<A HREF=\"".$myhost_href."\">".$mynode."</A>"; |
---|
[302] | 824 | } |
---|
[328] | 825 | |
---|
| 826 | $nodes_hostnames = implode( " ", $mynodehosts ); |
---|
| 827 | |
---|
[299] | 828 | $tpl->assign( "nodes_hostnames", $nodes_hostnames ); |
---|
| 829 | $tpl->gotoBlock( "node" ); |
---|
| 830 | } |
---|
[328] | 831 | } |
---|
| 832 | else if( $jobs[$jobid][status] == 'Q' ) |
---|
| 833 | { |
---|
| 834 | $view_nodes += (int) $jobs[$jobid][nodes]; |
---|
[299] | 835 | } |
---|
[135] | 836 | |
---|
[328] | 837 | if( $even ) |
---|
| 838 | { |
---|
| 839 | $tpl->assign( "nodeclass", "even" ); |
---|
[119] | 840 | |
---|
[328] | 841 | $even = 0; |
---|
| 842 | } |
---|
| 843 | else |
---|
| 844 | { |
---|
| 845 | $tpl->assign( "nodeclass", "odd" ); |
---|
[119] | 846 | |
---|
[328] | 847 | $even = 1; |
---|
[119] | 848 | } |
---|
| 849 | |
---|
[328] | 850 | if( $start_time ) |
---|
| 851 | { |
---|
| 852 | $runningtime = makeTime( $report_time - $start_time ); |
---|
[402] | 853 | //$job_runningtime = $report_time - $start_time; |
---|
| 854 | $job_runningtime = $heartbeat - $start_time; |
---|
[119] | 855 | |
---|
[328] | 856 | $tpl->assign( "started", makeDate( $start_time ) ); |
---|
| 857 | $tpl->assign( "runningtime", $runningtime ); |
---|
[119] | 858 | } |
---|
[117] | 859 | } |
---|
[116] | 860 | } |
---|
[114] | 861 | } |
---|
[208] | 862 | |
---|
[328] | 863 | $all_used_nodes = array_unique( $all_used_nodes ); |
---|
| 864 | $view_name_nodes = array_unique( $view_name_nodes ); |
---|
| 865 | $running_name_nodes = array_unique( $running_name_nodes ); |
---|
[124] | 866 | |
---|
[328] | 867 | $used_nodes = count( $all_used_nodes ); |
---|
| 868 | $view_nodes += count( $view_name_nodes ); |
---|
| 869 | $running_nodes += count( $running_name_nodes ); |
---|
[208] | 870 | |
---|
[328] | 871 | $total_nodes = $queued_nodes + $running_nodes; |
---|
| 872 | $total_cpus = $queued_cpus + $running_cpus; |
---|
| 873 | $total_jobs = $queued_jobs + $running_jobs; |
---|
[135] | 874 | |
---|
[328] | 875 | $free_nodes = $avail_nodes - $running_nodes; |
---|
[457] | 876 | $free_nodes = ( $free_nodes >= 0 ) ? $free_nodes : 0; |
---|
[328] | 877 | $free_cpus = $avail_cpus - $running_cpus; |
---|
[457] | 878 | $free_cpus = ( $free_cpus >= 0 ) ? $free_cpus : 0; |
---|
[208] | 879 | |
---|
[328] | 880 | $tpl->assignGlobal( "avail_nodes", $avail_nodes ); |
---|
| 881 | $tpl->assignGlobal( "avail_cpus", $avail_cpus ); |
---|
[208] | 882 | |
---|
[328] | 883 | $tpl->assignGlobal( "queued_nodes", $queued_nodes ); |
---|
| 884 | $tpl->assignGlobal( "queued_jobs", $queued_jobs ); |
---|
| 885 | $tpl->assignGlobal( "queued_cpus", $queued_cpus ); |
---|
[208] | 886 | |
---|
[328] | 887 | $tpl->assignGlobal( "total_nodes", $total_nodes ); |
---|
| 888 | $tpl->assignGlobal( "total_jobs", $total_jobs ); |
---|
| 889 | $tpl->assignGlobal( "total_cpus", $total_cpus ); |
---|
[135] | 890 | |
---|
[328] | 891 | $tpl->assignGlobal( "running_nodes", $running_nodes ); |
---|
| 892 | $tpl->assignGlobal( "running_jobs", $running_jobs ); |
---|
| 893 | $tpl->assignGlobal( "running_cpus", $running_cpus ); |
---|
[208] | 894 | |
---|
[328] | 895 | $tpl->assignGlobal( "used_nodes", $used_nodes ); |
---|
| 896 | $tpl->assignGlobal( "used_jobs", $used_jobs ); |
---|
| 897 | $tpl->assignGlobal( "used_cpus", $used_cpus ); |
---|
[208] | 898 | |
---|
[328] | 899 | $tpl->assignGlobal( "free_nodes", $free_nodes ); |
---|
| 900 | $tpl->assignGlobal( "free_cpus", $free_cpus ); |
---|
[135] | 901 | |
---|
[328] | 902 | $tpl->assignGlobal( "view_nodes", $view_nodes ); |
---|
| 903 | $tpl->assignGlobal( "view_jobs", $view_jobs ); |
---|
| 904 | $tpl->assignGlobal( "view_cpus", $view_cpus ); |
---|
[126] | 905 | |
---|
[328] | 906 | $tpl->assignGlobal( "report_time", makeDate( $heartbeat) ); |
---|
| 907 | |
---|
[266] | 908 | if( intval($view_jobs) == 1 and $start_time ) |
---|
[328] | 909 | { |
---|
[266] | 910 | if( $last_displayed_job != null ) |
---|
[328] | 911 | { |
---|
[266] | 912 | $filter[id] = $last_displayed_job; |
---|
[328] | 913 | } |
---|
| 914 | } |
---|
[263] | 915 | |
---|
[406] | 916 | //print_r( $metrics ); |
---|
[328] | 917 | |
---|
[406] | 918 | global $longtitle, $title; |
---|
| 919 | |
---|
| 920 | $longtitle = "Batch Report :: Powered by Job Monarch!"; |
---|
| 921 | $title = "Batch Report"; |
---|
| 922 | |
---|
| 923 | makeHeader( 'overview', $title, $longtitle ); |
---|
| 924 | |
---|
[263] | 925 | setupFilterSettings(); |
---|
| 926 | |
---|
[328] | 927 | if( intval($view_jobs) == 1 and $start_time ) |
---|
| 928 | { |
---|
[126] | 929 | $tpl->newBlock( "showhosts" ); |
---|
| 930 | |
---|
| 931 | # Present a width list |
---|
[328] | 932 | $cols_menu = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n"; |
---|
[126] | 933 | |
---|
[328] | 934 | $hostcols = ($hc) ? $hc : 4; |
---|
[263] | 935 | |
---|
[328] | 936 | foreach( range( 1, 25 ) as $cols ) |
---|
| 937 | { |
---|
| 938 | $cols_menu .= "<OPTION VALUE=$cols "; |
---|
[126] | 939 | |
---|
| 940 | if ($cols == $hostcols) |
---|
[328] | 941 | { |
---|
| 942 | $cols_menu .= "SELECTED"; |
---|
| 943 | } |
---|
| 944 | $cols_menu .= ">$cols\n"; |
---|
[126] | 945 | } |
---|
[328] | 946 | $cols_menu .= "</SELECT>\n"; |
---|
[126] | 947 | |
---|
[328] | 948 | $tpl->assign( "metric","$metricname $units" ); |
---|
| 949 | $tpl->assign( "id", $filter[id] ); |
---|
| 950 | |
---|
[126] | 951 | # Host columns menu defined in header.php |
---|
[328] | 952 | $tpl->assign( "cols_menu", $cols_menu ); |
---|
[126] | 953 | |
---|
[328] | 954 | $showhosts = isset($sh) ? $sh : $default_showhosts; |
---|
[126] | 955 | |
---|
[328] | 956 | $tpl->assign( "checked$showhosts", "checked" ); |
---|
[126] | 957 | |
---|
[328] | 958 | if( $showhosts ) |
---|
| 959 | { |
---|
| 960 | if( !isset( $start ) ) |
---|
| 961 | { |
---|
| 962 | $start ="jobstart"; |
---|
| 963 | } |
---|
| 964 | if( !isset( $stop ) ) |
---|
| 965 | { |
---|
| 966 | $stop ="now"; |
---|
| 967 | } |
---|
[126] | 968 | |
---|
[328] | 969 | $sorted_hosts = array(); |
---|
| 970 | $hosts_up = $jobs[$filter[id]][nodes]; |
---|
[126] | 971 | |
---|
[402] | 972 | //printf( "r %s\n", $job_runningtime ); |
---|
[126] | 973 | |
---|
[402] | 974 | $r = intval($job_runningtime * 1.2); |
---|
[126] | 975 | |
---|
[402] | 976 | //$jobrange = ($job_runningtime < 3600) ? -3600 : -$r ; |
---|
| 977 | $jobrange = -$r ; |
---|
| 978 | //$jobstart = $report_time - $job_runningtime; |
---|
| 979 | $jobstart = $start_time; |
---|
| 980 | |
---|
| 981 | //printf( "jr %s\n", $jobrange ); |
---|
| 982 | //printf( "js %s\n", $jobstart); |
---|
| 983 | |
---|
[328] | 984 | if ( $reports[$metricname] ) |
---|
| 985 | { |
---|
| 986 | $metricval = "g"; |
---|
| 987 | } |
---|
[126] | 988 | else |
---|
[328] | 989 | { |
---|
| 990 | $metricval = "m"; |
---|
| 991 | } |
---|
[263] | 992 | |
---|
[328] | 993 | foreach ( $hosts_up as $host ) |
---|
| 994 | { |
---|
[463] | 995 | $domain_len = 0 - strlen( $domain ); |
---|
[195] | 996 | |
---|
[463] | 997 | if( $use_fqdn ) |
---|
| 998 | { |
---|
| 999 | if( substr( $host, $domain_len ) != $domain ) |
---|
| 1000 | { |
---|
| 1001 | $host = $host . '.' . $domain; |
---|
| 1002 | } |
---|
| 1003 | } |
---|
[328] | 1004 | |
---|
| 1005 | $cpus = $metrics[$host]["cpu_num"]["VAL"]; |
---|
| 1006 | |
---|
| 1007 | if ( !$cpus ) |
---|
| 1008 | { |
---|
| 1009 | $cpus = 1; |
---|
| 1010 | } |
---|
| 1011 | |
---|
| 1012 | $load_one = $metrics[$host]["load_one"][VAL]; |
---|
| 1013 | $load = ((float) $load_one) / $cpus; |
---|
| 1014 | $host_load[$host] = $load; |
---|
| 1015 | |
---|
| 1016 | $percent_hosts[load_color($load)] ++; |
---|
| 1017 | |
---|
[126] | 1018 | if ($metricname=="load_one") |
---|
[328] | 1019 | { |
---|
| 1020 | $sorted_hosts[$host] = $load; |
---|
| 1021 | } |
---|
[126] | 1022 | else |
---|
[328] | 1023 | { |
---|
| 1024 | $sorted_hosts[$host] = $metrics[$host][$metricname][VAL]; |
---|
| 1025 | } |
---|
[126] | 1026 | } |
---|
[463] | 1027 | |
---|
[328] | 1028 | switch ( $sort ) |
---|
| 1029 | { |
---|
[126] | 1030 | case "descending": |
---|
[328] | 1031 | arsort( $sorted_hosts ); |
---|
[126] | 1032 | break; |
---|
[328] | 1033 | |
---|
[126] | 1034 | case "by hostname": |
---|
[328] | 1035 | ksort( $sorted_hosts ); |
---|
[126] | 1036 | break; |
---|
[328] | 1037 | |
---|
[126] | 1038 | case "ascending": |
---|
[328] | 1039 | asort( $sorted_hosts ); |
---|
[126] | 1040 | break; |
---|
[328] | 1041 | |
---|
| 1042 | default: |
---|
| 1043 | break; |
---|
[126] | 1044 | } |
---|
| 1045 | |
---|
[328] | 1046 | // First pass to find the max value in all graphs for this |
---|
| 1047 | // metric. The $start,$end variables comes from get_context.php, |
---|
| 1048 | // included in index.php. |
---|
| 1049 | // |
---|
[126] | 1050 | list($min, $max) = find_limits($sorted_hosts, $metricname); |
---|
| 1051 | |
---|
[328] | 1052 | // Second pass to output the graphs or metrics. |
---|
[126] | 1053 | $i = 1; |
---|
| 1054 | |
---|
[328] | 1055 | foreach ( $sorted_hosts as $host=>$value ) |
---|
| 1056 | { |
---|
| 1057 | $tpl->newBlock( "sorted_list" ); |
---|
[126] | 1058 | |
---|
[328] | 1059 | $host_url = rawurlencode( $host ); |
---|
| 1060 | $cluster_url = rawurlencode( $clustername ); |
---|
[193] | 1061 | |
---|
[328] | 1062 | $textval = ""; |
---|
| 1063 | |
---|
| 1064 | $val = $metrics[$host][$metricname]; |
---|
| 1065 | $class = "metric"; |
---|
| 1066 | $host_link = "\"../../?c=$cluster_url&h=$host_url&r=job&jr=$jobrange&js=$jobstart\""; |
---|
| 1067 | |
---|
| 1068 | if ( $val["TYPE"] == "timestamp" || $always_timestamp[$metricname] ) |
---|
| 1069 | { |
---|
| 1070 | $textval = date( "r", $val["VAL"] ); |
---|
| 1071 | } |
---|
| 1072 | elseif ( $val["TYPE"] == "string" || $val["SLOPE"] == "zero" || $always_constant[$metricname] || ($max_graphs > 0 and $i > $max_graphs )) |
---|
| 1073 | { |
---|
| 1074 | $textval = $val["VAL"] . " " . $val["UNITS"]; |
---|
| 1075 | } |
---|
| 1076 | else |
---|
| 1077 | { |
---|
| 1078 | $load_color = load_color($host_load[$host]); |
---|
| 1079 | $graphargs = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&"; |
---|
| 1080 | $graphargs .= "z=small&c=$cluster_url&h=$host_url&l=$load_color" . "&v=$val[VAL]&r=job&jr=$jobrange&js=$jobstart"; |
---|
| 1081 | if( $max > 0 ) |
---|
| 1082 | { |
---|
| 1083 | $graphargs .= "&x=$max&n=$min"; |
---|
[193] | 1084 | } |
---|
[126] | 1085 | } |
---|
[328] | 1086 | if ($textval) |
---|
| 1087 | { |
---|
| 1088 | $cell = "<td class=$class>". "<b><a href=$host_link>$host</a></b><br>". "<i>$metricname:</i> <b>$textval</b></td>"; |
---|
[126] | 1089 | } else { |
---|
[328] | 1090 | $cell = "<td><a href=$host_link>" . "<img src=\"../../graph.php?$graphargs\" " . "alt=\"$host\" border=0></a></td>"; |
---|
[126] | 1091 | } |
---|
| 1092 | |
---|
[328] | 1093 | $tpl->assign( "metric_image", $cell ); |
---|
| 1094 | |
---|
| 1095 | if(! ($i++ % $hostcols) ) |
---|
| 1096 | { |
---|
| 1097 | $tpl->assign( "br", "</tr><tr>" ); |
---|
| 1098 | } |
---|
[126] | 1099 | } |
---|
| 1100 | } |
---|
| 1101 | } |
---|
[114] | 1102 | } |
---|
[113] | 1103 | ?> |
---|