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