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