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