[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 315 2007-04-18 09:11:43Z 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; |
---|
[114] | 27 | |
---|
[163] | 28 | $data_gatherer = new DataGatherer( $clustername ); |
---|
[114] | 29 | |
---|
[116] | 30 | $tpl->assign( "clustername", $clustername ); |
---|
| 31 | |
---|
[206] | 32 | if( $JOB_ARCHIVE ) |
---|
[129] | 33 | $tpl->assign( "cluster_url", rawurlencode($clustername) ); |
---|
| 34 | |
---|
[114] | 35 | $data_gatherer->parseXML(); |
---|
[117] | 36 | |
---|
[114] | 37 | $heartbeat = $data_gatherer->getHeartbeat(); |
---|
| 38 | $jobs = $data_gatherer->getJobs(); |
---|
[126] | 39 | $gnodes = $data_gatherer->getNodes(); |
---|
[124] | 40 | $cpus = $data_gatherer->getCpus(); |
---|
[114] | 41 | |
---|
[263] | 42 | function setupFilterSettings() { |
---|
| 43 | global $tpl, $filter, $clustername, $piefilter; |
---|
[122] | 44 | |
---|
[263] | 45 | $filter_image_url = ""; |
---|
[119] | 46 | |
---|
[263] | 47 | $tpl->gotoBlock( "_ROOT" ); |
---|
[122] | 48 | |
---|
[263] | 49 | foreach( $filter as $filtername => $filtervalue ) { |
---|
| 50 | $tpl->assign( "f_".$filtername, $filtervalue ); |
---|
| 51 | $filter_image_url .= "&$filtername=$filtervalue"; |
---|
| 52 | } |
---|
[114] | 53 | |
---|
[263] | 54 | $tpl->assign( "clusterimage", "./image.php?c=".rawurlencode($clustername)."&view=big-clusterimage".$filter_image_url ); |
---|
| 55 | $tpl->assign( "f_order", $filterorder ); |
---|
[114] | 56 | |
---|
[263] | 57 | if( array_key_exists( "id", $filter ) ) |
---|
| 58 | $piefilter = 'id'; |
---|
| 59 | else if( array_key_exists( "user", $filter ) ) |
---|
| 60 | $piefilter = 'user'; |
---|
| 61 | else if( array_key_exists( "queue", $filter ) ) |
---|
| 62 | $piefilter = 'queue'; |
---|
[122] | 63 | |
---|
[263] | 64 | $pie = drawPie(); |
---|
| 65 | $tpl->assign("pie", $pie ); |
---|
| 66 | } |
---|
[122] | 67 | |
---|
[120] | 68 | function timeToEpoch( $time ) { |
---|
| 69 | |
---|
| 70 | $time_fields = explode( ':', $time ); |
---|
| 71 | |
---|
| 72 | if( count($time_fields) == 3 ) { |
---|
| 73 | |
---|
| 74 | $hours = $time_fields[0]; |
---|
| 75 | $minutes = $time_fields[1]; |
---|
| 76 | $seconds = $time_fields[2]; |
---|
| 77 | |
---|
[128] | 78 | } else if( count($time_fields) == 2 ) { |
---|
| 79 | |
---|
| 80 | $hours = 0; |
---|
| 81 | $minutes = $time_fields[0]; |
---|
| 82 | $seconds = $time_fields[1]; |
---|
| 83 | |
---|
| 84 | } else if( count($time_fields) == 1 ) { |
---|
| 85 | |
---|
| 86 | $hours = 0; |
---|
| 87 | $minutes = 0; |
---|
| 88 | $seconds = $time_fields[0]; |
---|
[120] | 89 | } |
---|
[128] | 90 | |
---|
| 91 | $myepoch = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) ); |
---|
| 92 | |
---|
| 93 | return $myepoch; |
---|
[120] | 94 | } |
---|
| 95 | |
---|
[246] | 96 | //function makeDate( $time ) { |
---|
| 97 | // return strftime( "%a %d %b %Y %H:%M:%S", $time ); |
---|
| 98 | //} |
---|
[114] | 99 | |
---|
| 100 | function colorRed( $color ) { |
---|
| 101 | return substr( $color, 0, 2 ); |
---|
| 102 | } |
---|
| 103 | function colorGreen( $color ) { |
---|
| 104 | return substr( $color, 2, 2 ); |
---|
| 105 | } |
---|
| 106 | function colorBlue( $color ) { |
---|
| 107 | return substr( $color, 4, 2 ); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | function colorDiffer( $first, $second ) { |
---|
| 111 | |
---|
| 112 | // Make sure these two colors differ atleast 50 R/G/B |
---|
| 113 | $min_diff = 50; |
---|
| 114 | |
---|
[147] | 115 | $c1r = hexDec( colorRed( $first ) ); |
---|
| 116 | $c1g = hexDec( colorGreen( $first ) ); |
---|
| 117 | $c1b = hexDec( colorBlue( $first ) ); |
---|
[114] | 118 | |
---|
[147] | 119 | $c2r = hexDec( colorRed( $second ) ); |
---|
| 120 | $c2g = hexDec( colorGreen( $second ) ); |
---|
| 121 | $c2b = hexDec( colorBlue( $second ) ); |
---|
[114] | 122 | |
---|
| 123 | $rdiff = ($c1r >= $c2r) ? $c1r - $c2r : $c2r - $c1r; |
---|
| 124 | $gdiff = ($c1g >= $c2g) ? $c1g - $c2g : $c2g - $c1g; |
---|
| 125 | $bdiff = ($c1b >= $c2b) ? $c1b - $c2b : $c2b - $c1b; |
---|
| 126 | |
---|
| 127 | if( $rdiff >= $min_diff or $gdiff >= $min_diff or $bdiff >= $min_diff ) |
---|
| 128 | return TRUE; |
---|
| 129 | else |
---|
| 130 | return FALSE; |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | function randomColor( $known_colors ) { |
---|
| 134 | |
---|
[147] | 135 | $start = "004E00"; |
---|
| 136 | |
---|
| 137 | $start_red = colorRed( $start ); |
---|
| 138 | $start_green = colorGreen( $start ); |
---|
| 139 | $start_blue = colorBlue( $start ); |
---|
| 140 | |
---|
| 141 | $end = "FFFFFF"; |
---|
[114] | 142 | |
---|
[147] | 143 | $end_red = colorRed( $end ); |
---|
| 144 | $end_green = colorGreen( $end ); |
---|
| 145 | $end_blue = colorBlue( $end ); |
---|
[114] | 146 | |
---|
[147] | 147 | $change_color = TRUE; |
---|
[114] | 148 | |
---|
[147] | 149 | while( $change_color ) { |
---|
[114] | 150 | |
---|
[147] | 151 | $change_color = FALSE; |
---|
[114] | 152 | |
---|
[147] | 153 | $new_red = rand( hexDec( $start_red ), hexDec( $end_red ) ); |
---|
| 154 | $new_green = rand( hexDec( $start_green ), hexDec( $end_green ) ); |
---|
| 155 | $new_blue = rand( hexDec( $start_blue ), hexDec( $end_blue ) ); |
---|
[114] | 156 | |
---|
[147] | 157 | $new = decHex( $new_red ) . decHex( $new_green ) . decHex( $new_blue ); |
---|
[114] | 158 | |
---|
[147] | 159 | foreach( $known_colors as $old ) |
---|
[114] | 160 | |
---|
[147] | 161 | if( !colorDiffer( $new, $old ) ) |
---|
[114] | 162 | |
---|
[147] | 163 | $change_color = TRUE; |
---|
[114] | 164 | } |
---|
| 165 | |
---|
| 166 | // Whoa! Actually found a good color ;) |
---|
[147] | 167 | return $new; |
---|
[114] | 168 | } |
---|
| 169 | |
---|
[126] | 170 | function drawJobPie() { |
---|
| 171 | } |
---|
[114] | 172 | |
---|
[126] | 173 | function drawUserPie() { |
---|
[124] | 174 | |
---|
[126] | 175 | } |
---|
| 176 | |
---|
| 177 | function drawQueuePie() { |
---|
| 178 | |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | |
---|
[127] | 182 | function drawPie() { |
---|
[124] | 183 | |
---|
[315] | 184 | global $jobs, $gnodes, $piefilter, $filter, $metrics; |
---|
[114] | 185 | |
---|
[315] | 186 | $nodes = $gnodes; |
---|
[127] | 187 | |
---|
| 188 | if( isset($piefilter) ) |
---|
[315] | 189 | $pie_args = "title=" . rawurlencode("Cluster ".$piefilter." usage"); |
---|
[127] | 190 | else |
---|
[315] | 191 | $pie_args = "title=" . rawurlencode("Cluster queue usage"); |
---|
[127] | 192 | |
---|
[315] | 193 | $pie_args .= "&size=250x150"; |
---|
[114] | 194 | |
---|
[315] | 195 | $queues = array(); |
---|
| 196 | $nr_jobs = count( $jobs ); |
---|
| 197 | $nr_nodes = count( $nodes ); |
---|
[114] | 198 | |
---|
[315] | 199 | $nr_cpus = cluster_sum("cpu_num", $metrics); |
---|
[114] | 200 | |
---|
[315] | 201 | $empty_cpus = 0; |
---|
| 202 | $used_cpus = 0; |
---|
[123] | 203 | |
---|
[315] | 204 | $job_weight = array(); |
---|
| 205 | |
---|
[114] | 206 | foreach( $nodes as $node ) { |
---|
| 207 | |
---|
[315] | 208 | $myjobs = $node->getJobs(); |
---|
| 209 | $myhost = $node->getHostname(); |
---|
| 210 | $node_cpus = $metrics[$myhost]["cpu_num"][VAL]; |
---|
| 211 | $job_cpu = 0; |
---|
[114] | 212 | |
---|
[315] | 213 | foreach( $myjobs as $myjob ) { |
---|
| 214 | |
---|
| 215 | $job_cpu += (int) $jobs[$myjob][ppn] ? $jobs[$myjob][ppn] : 1; |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | $node_freecpu = $node_cpus - $job_cpu; |
---|
| 219 | |
---|
| 220 | $empty_cpus += $node_freecpu; |
---|
[114] | 221 | } |
---|
| 222 | |
---|
[315] | 223 | $used_cpus = $nr_cpus - $empty_cpus; |
---|
[114] | 224 | |
---|
[315] | 225 | $empty_percentage = ($empty_cpus / $nr_cpus) * 100; |
---|
[114] | 226 | |
---|
[315] | 227 | $qcolors = array(); |
---|
| 228 | $color = randomColor( $qcolors ); |
---|
| 229 | $qcolors[] = $color; |
---|
| 230 | $pie_args .= "&free=$empty_percentage,$color"; |
---|
| 231 | |
---|
[127] | 232 | if( isset( $piefilter ) ) |
---|
| 233 | $filterpie = array(); |
---|
| 234 | |
---|
[123] | 235 | foreach( $nodes as $node ) { |
---|
[114] | 236 | |
---|
[315] | 237 | $node_jobs = $node->getJobs(); |
---|
| 238 | $nr_node_jobs = count( $node_jobs ); |
---|
| 239 | $myhost = $node->getHostname(); |
---|
| 240 | $node_cpus = $metrics[$myhost]["cpu_num"][VAL]; |
---|
[114] | 241 | |
---|
[123] | 242 | foreach( $node_jobs as $myjob ) { |
---|
[114] | 243 | |
---|
[315] | 244 | $job_cpu = (int) $jobs[$myjob][ppn] ? $jobs[$myjob][ppn] : 1; |
---|
| 245 | |
---|
| 246 | // Determine the weight of this job |
---|
| 247 | // - what percentage of the cpus is in use by this job |
---|
[123] | 248 | // |
---|
[315] | 249 | $job_weight[$myjob] = ( $job_cpu / $nr_cpus ); |
---|
[123] | 250 | |
---|
[315] | 251 | |
---|
[127] | 252 | if( isset($piefilter) ) { |
---|
| 253 | $countjob = 1; |
---|
| 254 | if( $piefilter == 'id' ) { |
---|
| 255 | if( $myjob != $filter[$piefilter] ) |
---|
| 256 | $countjob = 0; |
---|
| 257 | } else if( $piefilter == 'user' ) { |
---|
| 258 | if( $jobs[$myjob][owner] != $filter[$piefilter] ) |
---|
| 259 | $countjob = 0; |
---|
| 260 | } else { |
---|
| 261 | if( $jobs[$myjob][$piefilter] != $filter[$piefilter] ) |
---|
| 262 | $countjob = 0; |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | if( $countjob ) { |
---|
| 266 | |
---|
| 267 | if( !isset( $filterpie[$filter[$piefilter]] ) ) |
---|
| 268 | $filterpie[$filter[$piefilter]] = $job_weight[$myjob]; |
---|
| 269 | else |
---|
| 270 | $filterpie[$filter[$piefilter]] = $filterpie[$filter[$piefilter]] + $job_weight[$myjob]; |
---|
| 271 | } else { |
---|
| 272 | if( !isset( $filterpie["other"] ) ) |
---|
| 273 | $filterpie["other"] = $job_weight[$myjob]; |
---|
| 274 | else |
---|
| 275 | $filterpie["other"] = $filterpie["other"] + $job_weight[$myjob]; |
---|
| 276 | |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | } else { |
---|
| 280 | |
---|
[315] | 281 | $qname = $jobs[$myjob][queue]; |
---|
| 282 | |
---|
[127] | 283 | if( !isset( $queues[$qname] ) ) |
---|
| 284 | $queues[$qname] = $job_weight[$myjob]; |
---|
| 285 | else |
---|
| 286 | $queues[$qname] = $queues[$qname] + $job_weight[$myjob]; |
---|
| 287 | } |
---|
[114] | 288 | } |
---|
| 289 | } |
---|
| 290 | |
---|
[127] | 291 | if( isset( $piefilter ) ) |
---|
| 292 | $graphvals = $filterpie; |
---|
| 293 | else |
---|
| 294 | $graphvals = $queues; |
---|
[114] | 295 | |
---|
[127] | 296 | foreach( $graphvals as $name => $totalweight) { |
---|
| 297 | |
---|
[315] | 298 | $percentage = ( $totalweight * 100 ); |
---|
[123] | 299 | |
---|
[315] | 300 | $color = randomColor( $qcolors ); |
---|
| 301 | $qcolors[] = $color; |
---|
| 302 | $pie_args .= "&$name=$percentage,$color"; |
---|
[114] | 303 | } |
---|
| 304 | $pie = "../../pie.php?$pie_args"; |
---|
| 305 | |
---|
| 306 | return $pie; |
---|
| 307 | } |
---|
| 308 | |
---|
| 309 | |
---|
[117] | 310 | function sortJobs( $jobs, $sortby, $sortorder ) { |
---|
[114] | 311 | |
---|
[117] | 312 | $sorted = array(); |
---|
[114] | 313 | |
---|
[117] | 314 | $cmp = create_function( '$a, $b', |
---|
| 315 | "global \$sortby, \$sortorder;". |
---|
[116] | 316 | |
---|
[117] | 317 | "if( \$a == \$b ) return 0;". |
---|
[116] | 318 | |
---|
[117] | 319 | "if (\$sortorder==\"desc\")". |
---|
| 320 | "return ( \$a < \$b ) ? 1 : -1;". |
---|
| 321 | "else if (\$sortorder==\"asc\")". |
---|
| 322 | "return ( \$a > \$b ) ? 1 : -1;" ); |
---|
| 323 | |
---|
[301] | 324 | if( isset( $jobs ) && count( $jobs ) > 0 ) { |
---|
[117] | 325 | |
---|
[301] | 326 | foreach( $jobs as $jobid => $jobattrs ) { |
---|
[135] | 327 | |
---|
[301] | 328 | $state = $jobattrs[status]; |
---|
| 329 | $user = $jobattrs[owner]; |
---|
| 330 | $queue = $jobattrs[queue]; |
---|
| 331 | $name = $jobattrs[name]; |
---|
| 332 | $req_cpu = $jobattrs[requested_time]; |
---|
| 333 | $req_memory = $jobattrs[requested_memory]; |
---|
[135] | 334 | |
---|
[301] | 335 | if( $state == 'R' ) |
---|
| 336 | $nodes = count( $jobattrs[nodes] ); |
---|
| 337 | else |
---|
| 338 | $nodes = $jobattrs[nodes]; |
---|
[117] | 339 | |
---|
[301] | 340 | $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1; |
---|
| 341 | $cpus = $nodes * $ppn; |
---|
| 342 | $queued_time = (int) $jobattrs[queued_timestamp]; |
---|
| 343 | $start_time = (int) $jobattrs[start_timestamp]; |
---|
| 344 | $runningtime = $report_time - $start_time; |
---|
[117] | 345 | |
---|
[301] | 346 | switch( $sortby ) { |
---|
| 347 | case "id": |
---|
| 348 | $sorted[$jobid] = $jobid; |
---|
| 349 | break; |
---|
[117] | 350 | |
---|
[301] | 351 | case "state": |
---|
| 352 | $sorted[$jobid] = $state; |
---|
| 353 | break; |
---|
[117] | 354 | |
---|
[301] | 355 | case "user": |
---|
| 356 | $sorted[$jobid] = $user; |
---|
| 357 | break; |
---|
[117] | 358 | |
---|
[301] | 359 | case "queue": |
---|
| 360 | $sorted[$jobid] = $queue; |
---|
| 361 | break; |
---|
[117] | 362 | |
---|
[301] | 363 | case "name": |
---|
| 364 | $sorted[$jobid] = $name; |
---|
| 365 | break; |
---|
[117] | 366 | |
---|
[301] | 367 | case "req_cpu": |
---|
| 368 | $sorted[$jobid] = timeToEpoch( $req_cpu ); |
---|
| 369 | break; |
---|
[117] | 370 | |
---|
[301] | 371 | case "req_mem": |
---|
| 372 | $sorted[$jobid] = $req_memory; |
---|
| 373 | break; |
---|
[117] | 374 | |
---|
[301] | 375 | case "nodes": |
---|
| 376 | $sorted[$jobid] = $nodes; |
---|
| 377 | break; |
---|
[117] | 378 | |
---|
[301] | 379 | case "cpus": |
---|
| 380 | $sorted[$jobid] = $cpus; |
---|
| 381 | break; |
---|
[245] | 382 | |
---|
[301] | 383 | case "queued": |
---|
| 384 | $sorted[$jobid] = $queued_time; |
---|
| 385 | break; |
---|
[117] | 386 | |
---|
[301] | 387 | case "start": |
---|
| 388 | $sorted[$jobid] = $start_time; |
---|
| 389 | break; |
---|
[117] | 390 | |
---|
[301] | 391 | case "runningtime": |
---|
| 392 | $sorted[$jobid] = $runningtime; |
---|
| 393 | break; |
---|
[117] | 394 | |
---|
[301] | 395 | default: |
---|
| 396 | break; |
---|
[117] | 397 | |
---|
[301] | 398 | } |
---|
| 399 | } |
---|
| 400 | } |
---|
| 401 | |
---|
[128] | 402 | //uasort( $sorted, $cmp ); |
---|
| 403 | if( $sortorder == "asc" ) |
---|
| 404 | arsort( $sorted ); |
---|
| 405 | else if( $sortorder == "desc" ) |
---|
| 406 | asort( $sorted ); |
---|
[117] | 407 | |
---|
| 408 | return $sorted; |
---|
| 409 | } |
---|
| 410 | |
---|
| 411 | function makeOverview() { |
---|
| 412 | |
---|
| 413 | global $jobs, $nodes, $heartbeat, $clustername, $tpl; |
---|
[126] | 414 | global $sortorder, $sortby, $filter, $sh, $hc, $m; |
---|
| 415 | global $cluster_url, $get_metric_string, $host_url, $metrics; |
---|
[129] | 416 | global $start, $end, $reports, $gnodes, $default_showhosts; |
---|
[299] | 417 | global $COLUMN_QUEUED, $COLUMN_REQUESTED_MEMORY, $COLUMN_NODES, $hostname; |
---|
[126] | 418 | $metricname = $m; |
---|
| 419 | |
---|
[117] | 420 | $tpl->assign("sortorder", $sortorder ); |
---|
| 421 | $tpl->assign("sortby", $sortby ); |
---|
| 422 | |
---|
| 423 | $sorted_jobs = sortJobs( $jobs, $sortby, $sortorder ); |
---|
| 424 | |
---|
[118] | 425 | $even = 1; |
---|
| 426 | |
---|
[135] | 427 | $used_jobs = 0; |
---|
| 428 | $used_cpus = 0; |
---|
| 429 | $used_nodes = 0; |
---|
[124] | 430 | |
---|
[208] | 431 | $queued_jobs = 0; |
---|
| 432 | $queued_nodes = 0; |
---|
| 433 | $queued_cpus = 0; |
---|
| 434 | |
---|
| 435 | $total_nodes = 0; |
---|
| 436 | $total_cpus = 0; |
---|
| 437 | $total_jobs = 0; |
---|
| 438 | |
---|
[135] | 439 | $all_used_nodes = array(); |
---|
[208] | 440 | $total_used_nodes = array(); |
---|
[124] | 441 | |
---|
[208] | 442 | $running_name_nodes = array(); |
---|
| 443 | |
---|
| 444 | $running_nodes = 0; |
---|
| 445 | $running_jobs = 0; |
---|
| 446 | $running_cpus = 0; |
---|
| 447 | |
---|
[135] | 448 | $avail_nodes = count( $gnodes ); |
---|
| 449 | $avail_cpus = cluster_sum("cpu_num", $metrics); |
---|
| 450 | |
---|
| 451 | $view_cpus = 0; |
---|
| 452 | $view_jobs = 0; |
---|
| 453 | $view_nodes = 0; |
---|
| 454 | |
---|
[208] | 455 | $all_nodes = 0; |
---|
| 456 | $all_jobs = 0; |
---|
| 457 | $all_cpus = 0; |
---|
[135] | 458 | |
---|
[208] | 459 | $view_name_nodes = array(); |
---|
| 460 | |
---|
[241] | 461 | if( $COLUMN_REQUESTED_MEMORY ) { |
---|
[242] | 462 | $tpl->newBlock( "column_header_req_mem" ); |
---|
[241] | 463 | } |
---|
| 464 | |
---|
[299] | 465 | if( $COLUMN_NODES ) { |
---|
| 466 | $tpl->newBlock( "column_header_nodes" ); |
---|
| 467 | } |
---|
| 468 | |
---|
[242] | 469 | if( $COLUMN_QUEUED ) { |
---|
| 470 | $tpl->newBlock( "column_header_queued" ); |
---|
| 471 | } |
---|
| 472 | |
---|
[263] | 473 | $last_displayed_job = null; |
---|
| 474 | |
---|
[117] | 475 | foreach( $sorted_jobs as $jobid => $sortdec ) { |
---|
| 476 | |
---|
| 477 | $report_time = $jobs[$jobid][reported]; |
---|
| 478 | |
---|
[208] | 479 | if( $jobs[$jobid][status] == 'R' ) |
---|
| 480 | $nodes = count( $jobs[$jobid][nodes] ); |
---|
| 481 | else if( $jobs[$jobid][status] == 'Q' ) |
---|
| 482 | $nodes = $jobs[$jobid][nodes]; |
---|
| 483 | |
---|
[124] | 484 | $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1; |
---|
| 485 | $cpus = $nodes * $ppn; |
---|
| 486 | |
---|
[208] | 487 | if( $report_time == $heartbeat ) { |
---|
[124] | 488 | |
---|
[208] | 489 | $display_job = 1; |
---|
| 490 | |
---|
[300] | 491 | if( $jobs[$jobid][status] == 'R' ) { |
---|
| 492 | foreach( $jobs[$jobid][nodes] as $tempnode ) { |
---|
| 493 | $all_used_nodes[] = $tempnode; |
---|
| 494 | } |
---|
| 495 | } |
---|
[208] | 496 | |
---|
[135] | 497 | $used_cpus += $cpus; |
---|
| 498 | |
---|
[208] | 499 | if( $jobs[$jobid][status] == 'R' ) { |
---|
| 500 | $running_cpus += $cpus; |
---|
| 501 | $running_jobs++; |
---|
[117] | 502 | |
---|
[268] | 503 | $found_node_job = 0; |
---|
| 504 | |
---|
[263] | 505 | foreach( $jobs[$jobid][nodes] as $tempnode ) { |
---|
[208] | 506 | $running_name_nodes[] = $tempnode; |
---|
[263] | 507 | |
---|
[297] | 508 | if( isset( $hostname ) && $hostname != '' ) { |
---|
[263] | 509 | //$filter[host] = $hostname; |
---|
| 510 | |
---|
| 511 | $domain_len = 0 - strlen( $jobs[$jobid][domain] ); |
---|
| 512 | $hostnode = $tempnode; |
---|
| 513 | if( substr( $hostnode, $domain_len ) != $jobs[$jobid][domain] ) { |
---|
| 514 | $hostnode = $hostnode. '.'. $jobs[$jobid][domain]; |
---|
| 515 | } |
---|
| 516 | |
---|
[268] | 517 | if( $hostname == $hostnode ) { |
---|
| 518 | $found_node_job = 1; |
---|
| 519 | $display_job = 1; |
---|
| 520 | } else if( !$found_node_job ) { |
---|
[263] | 521 | $display_job = 0; |
---|
[268] | 522 | } |
---|
[297] | 523 | } |
---|
[263] | 524 | } |
---|
[208] | 525 | } |
---|
[117] | 526 | |
---|
[208] | 527 | if( $jobs[$jobid][status] == 'Q' ) { |
---|
[263] | 528 | if( isset( $hostname ) && $hostname != '' ) |
---|
| 529 | $display_job = 0; |
---|
| 530 | |
---|
[208] | 531 | $queued_cpus += $cpus; |
---|
| 532 | $queued_nodes += $nodes; |
---|
| 533 | $queued_jobs++; |
---|
| 534 | } |
---|
| 535 | |
---|
[119] | 536 | foreach( $filter as $filtername=>$filtervalue ) { |
---|
[118] | 537 | |
---|
[124] | 538 | if( $filtername == 'id' && $jobid != $filtervalue ) |
---|
| 539 | $display_job = 0; |
---|
| 540 | else if( $filtername == 'state' && $jobs[$jobid][status] != $filtervalue ) |
---|
| 541 | $display_job = 0; |
---|
| 542 | else if( $filtername == 'queue' && $jobs[$jobid][queue] != $filtervalue ) |
---|
| 543 | $display_job = 0; |
---|
| 544 | else if( $filtername == 'user' && $jobs[$jobid][owner] != $filtervalue ) |
---|
| 545 | $display_job = 0; |
---|
[118] | 546 | } |
---|
| 547 | |
---|
[119] | 548 | if( $display_job ) { |
---|
[117] | 549 | |
---|
[119] | 550 | $tpl->newBlock("node"); |
---|
| 551 | $tpl->assign( "clustername", $clustername ); |
---|
| 552 | $tpl->assign("id", $jobid ); |
---|
[263] | 553 | |
---|
| 554 | $last_displayed_job = $jobid; |
---|
| 555 | |
---|
[119] | 556 | $tpl->assign("state", $jobs[$jobid][status] ); |
---|
[240] | 557 | |
---|
| 558 | $fullstate = ''; |
---|
| 559 | if( $jobs[$jobid][status] == 'R' ) { |
---|
| 560 | $fullstate = "Running"; |
---|
| 561 | } else if( $jobs[$jobid][status] == 'Q' ) { |
---|
| 562 | $fullstate = "Queued"; |
---|
| 563 | } |
---|
| 564 | |
---|
| 565 | $tpl->assign("fullstate", $fullstate ); |
---|
| 566 | |
---|
[119] | 567 | $tpl->assign("user", $jobs[$jobid][owner] ); |
---|
| 568 | $tpl->assign("queue", $jobs[$jobid][queue] ); |
---|
[240] | 569 | |
---|
| 570 | $fulljobname = $jobs[$jobid][name]; |
---|
| 571 | $shortjobname = ''; |
---|
| 572 | |
---|
| 573 | $tpl->assign("fulljobname", $fulljobname ); |
---|
| 574 | |
---|
[311] | 575 | $fulljobname_fields = explode( ' ', $fulljobname ); |
---|
| 576 | |
---|
| 577 | $capjobname = 0; |
---|
| 578 | |
---|
| 579 | if( strlen( $fulljobname_fields[0] ) > 10 ) |
---|
| 580 | $capjobname = 1; |
---|
| 581 | |
---|
| 582 | if( $capjobname ) { |
---|
[240] | 583 | $tpl->newBlock("jobname_hint_start"); |
---|
| 584 | $tpl->gotoBlock("node"); |
---|
| 585 | |
---|
[311] | 586 | $shortjobname = substr( $fulljobname, 0, 10 ) . '..'; |
---|
[240] | 587 | } else { |
---|
| 588 | $shortjobname = $fulljobname; |
---|
| 589 | } |
---|
| 590 | |
---|
| 591 | $tpl->assign("name", $shortjobname ); |
---|
| 592 | |
---|
[311] | 593 | if( $capjobname ) { |
---|
[240] | 594 | $tpl->newBlock("jobname_hint_end"); |
---|
| 595 | $tpl->gotoBlock("node"); |
---|
| 596 | } |
---|
| 597 | |
---|
[126] | 598 | $domain = $jobs[$jobid][domain]; |
---|
[120] | 599 | $tpl->assign("req_cpu", makeTime( timeToEpoch( $jobs[$jobid][requested_time] ) ) ); |
---|
[135] | 600 | |
---|
[241] | 601 | if( $COLUMN_REQUESTED_MEMORY ) { |
---|
| 602 | $tpl->newBlock( "column_req_mem" ); |
---|
| 603 | $tpl->assign( "req_memory", $jobs[$jobid][requested_memory] ); |
---|
| 604 | $tpl->gotoBlock( "node" ); |
---|
| 605 | } |
---|
[135] | 606 | |
---|
[299] | 607 | |
---|
[242] | 608 | if( $COLUMN_QUEUED ) { |
---|
| 609 | $tpl->newBlock( "column_queued" ); |
---|
[243] | 610 | $tpl->assign( "queued", makeDate( $jobs[$jobid][queued_timestamp] ) ); |
---|
[242] | 611 | $tpl->gotoBlock( "node" ); |
---|
| 612 | } |
---|
| 613 | |
---|
[119] | 614 | $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1; |
---|
| 615 | $cpus = $nodes * $ppn; |
---|
| 616 | $tpl->assign("nodes", $nodes ); |
---|
| 617 | $tpl->assign("cpus", $cpus ); |
---|
| 618 | $start_time = (int) $jobs[$jobid][start_timestamp]; |
---|
[126] | 619 | $job_start = $start_time; |
---|
[119] | 620 | |
---|
[135] | 621 | $view_cpus += $cpus; |
---|
| 622 | $view_jobs++; |
---|
[124] | 623 | |
---|
[299] | 624 | if( $jobs[$jobid][status] == 'R' ) { |
---|
[135] | 625 | foreach( $jobs[$jobid][nodes] as $tempnode ) |
---|
[208] | 626 | $view_name_nodes[] = $tempnode; |
---|
[299] | 627 | |
---|
| 628 | if( $COLUMN_NODES ) { |
---|
| 629 | $tpl->newBlock( "column_nodes" ); |
---|
[302] | 630 | $mynodehosts = array(); |
---|
| 631 | foreach( $jobs[$jobid][nodes] as $mynode ) { |
---|
| 632 | $myhost_href = "./?c=".$clustername."&h=".$mynode.".".$jobs[$jobid][domain]; |
---|
| 633 | $mynodehosts[] = "<A HREF=\"".$myhost_href."\">".$mynode."</A>"; |
---|
| 634 | } |
---|
| 635 | $nodes_hostnames = implode( " ", $mynodehosts ); |
---|
[299] | 636 | $tpl->assign( "nodes_hostnames", $nodes_hostnames ); |
---|
| 637 | $tpl->gotoBlock( "node" ); |
---|
| 638 | } |
---|
| 639 | } else if( $jobs[$jobid][status] == 'Q' ) { |
---|
[208] | 640 | $view_nodes += (int) $jobs[$jobid][nodes]; |
---|
[299] | 641 | } |
---|
[135] | 642 | |
---|
[119] | 643 | if( $even ) { |
---|
| 644 | |
---|
| 645 | $tpl->assign("nodeclass", "even"); |
---|
| 646 | $even = 0; |
---|
| 647 | } else { |
---|
| 648 | |
---|
| 649 | $tpl->assign("nodeclass", "odd"); |
---|
| 650 | $even = 1; |
---|
| 651 | } |
---|
| 652 | |
---|
| 653 | if( $start_time ) { |
---|
| 654 | |
---|
| 655 | $runningtime = makeTime( $report_time - $start_time ); |
---|
[126] | 656 | $job_runningtime = $report_time - $start_time; |
---|
[119] | 657 | $tpl->assign("started", makeDate( $start_time ) ); |
---|
| 658 | $tpl->assign("runningtime", $runningtime ); |
---|
| 659 | } |
---|
[117] | 660 | } |
---|
[116] | 661 | } |
---|
[114] | 662 | } |
---|
[250] | 663 | $all_used_nodes = array_unique( $all_used_nodes ); |
---|
| 664 | $view_name_nodes = array_unique( $view_name_nodes ); |
---|
| 665 | $running_name_nodes = array_unique( $running_name_nodes ); |
---|
[208] | 666 | |
---|
[135] | 667 | $used_nodes = count( $all_used_nodes ); |
---|
[208] | 668 | $view_nodes += count( $view_name_nodes ); |
---|
| 669 | $running_nodes += count( $running_name_nodes ); |
---|
[124] | 670 | |
---|
[208] | 671 | $total_nodes = $queued_nodes + $running_nodes; |
---|
| 672 | $total_cpus = $queued_cpus + $running_cpus; |
---|
| 673 | $total_jobs = $queued_jobs + $running_jobs; |
---|
| 674 | |
---|
[135] | 675 | $tpl->assignGlobal("avail_nodes", $avail_nodes ); |
---|
| 676 | $tpl->assignGlobal("avail_cpus", $avail_cpus ); |
---|
| 677 | |
---|
[208] | 678 | $tpl->assignGlobal("queued_nodes", $queued_nodes ); |
---|
| 679 | $tpl->assignGlobal("queued_jobs", $queued_jobs ); |
---|
| 680 | $tpl->assignGlobal("queued_cpus", $queued_cpus ); |
---|
| 681 | |
---|
| 682 | $tpl->assignGlobal("total_nodes", $total_nodes ); |
---|
| 683 | $tpl->assignGlobal("total_jobs", $total_jobs ); |
---|
| 684 | $tpl->assignGlobal("total_cpus", $total_cpus ); |
---|
| 685 | |
---|
| 686 | $tpl->assignGlobal("running_nodes", $running_nodes ); |
---|
| 687 | $tpl->assignGlobal("running_jobs", $running_jobs ); |
---|
| 688 | $tpl->assignGlobal("running_cpus", $running_cpus ); |
---|
| 689 | |
---|
[135] | 690 | $tpl->assignGlobal("used_nodes", $used_nodes ); |
---|
| 691 | $tpl->assignGlobal("used_jobs", $used_jobs ); |
---|
| 692 | $tpl->assignGlobal("used_cpus", $used_cpus ); |
---|
| 693 | |
---|
[209] | 694 | $free_nodes = $avail_nodes - $running_nodes; |
---|
| 695 | $free_cpus = $avail_cpus - $running_cpus; |
---|
[208] | 696 | |
---|
| 697 | $tpl->assignGlobal("free_nodes", $free_nodes ); |
---|
| 698 | $tpl->assignGlobal("free_cpus", $free_cpus ); |
---|
| 699 | |
---|
[135] | 700 | $tpl->assignGlobal("view_nodes", $view_nodes ); |
---|
| 701 | $tpl->assignGlobal("view_jobs", $view_jobs ); |
---|
| 702 | $tpl->assignGlobal("view_cpus", $view_cpus ); |
---|
| 703 | |
---|
[124] | 704 | $tpl->assignGlobal("report_time", makeDate( $heartbeat)); |
---|
[126] | 705 | |
---|
[266] | 706 | if( intval($view_jobs) == 1 and $start_time ) |
---|
| 707 | if( $last_displayed_job != null ) |
---|
| 708 | $filter[id] = $last_displayed_job; |
---|
[263] | 709 | |
---|
[266] | 710 | makeHeader( 'overview' ); |
---|
[263] | 711 | setupFilterSettings(); |
---|
| 712 | |
---|
[188] | 713 | if( intval($view_jobs) == 1 and $start_time ) { |
---|
[263] | 714 | |
---|
[126] | 715 | $tpl->newBlock( "showhosts" ); |
---|
| 716 | |
---|
| 717 | # Present a width list |
---|
| 718 | $cols_menu = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n"; |
---|
| 719 | |
---|
[263] | 720 | |
---|
[126] | 721 | $hostcols = ($hc) ? $hc : 4; |
---|
| 722 | |
---|
| 723 | foreach(range(1,25) as $cols) { |
---|
| 724 | $cols_menu .= "<OPTION VALUE=$cols "; |
---|
| 725 | if ($cols == $hostcols) |
---|
| 726 | $cols_menu .= "SELECTED"; |
---|
| 727 | $cols_menu .= ">$cols\n"; |
---|
| 728 | } |
---|
| 729 | $cols_menu .= "</SELECT>\n"; |
---|
| 730 | |
---|
| 731 | //$tpl->assign("cluster", $clustername); |
---|
| 732 | $tpl->assign("metric","$metricname $units"); |
---|
[127] | 733 | $tpl->assign("id", $filter[id]); |
---|
[126] | 734 | # Host columns menu defined in header.php |
---|
| 735 | $tpl->assign("cols_menu", $cols_menu); |
---|
| 736 | |
---|
[129] | 737 | $showhosts = isset($sh) ? $sh : $default_showhosts; |
---|
| 738 | //if( !$showhosts) $showhosts = $default_showhosts; |
---|
[126] | 739 | $tpl->assign("checked$showhosts", "checked"); |
---|
| 740 | |
---|
| 741 | if( $showhosts ) { |
---|
| 742 | //----- |
---|
| 743 | |
---|
| 744 | if( !isset($start) ) $start="jobstart"; |
---|
| 745 | if( !isset($stop) ) $stop="now"; |
---|
| 746 | //$tpl->assign("start", $start); |
---|
| 747 | //$tpl->assign("stop", $stop); |
---|
| 748 | |
---|
| 749 | $sorted_hosts = array(); |
---|
| 750 | $hosts_up = $jobs[$filter[id]][nodes]; |
---|
| 751 | |
---|
| 752 | $r = intval($job_runningtime * 1.25); |
---|
| 753 | |
---|
| 754 | $jobrange = ($job_runningtime < 3600) ? -3600 : -$r ; |
---|
| 755 | $jobstart = $report_time - $job_runningtime; |
---|
| 756 | |
---|
| 757 | if ($reports[$metricname]) |
---|
| 758 | $metricval = "g"; |
---|
| 759 | else |
---|
| 760 | $metricval = "m"; |
---|
[263] | 761 | |
---|
[126] | 762 | foreach ($hosts_up as $host ) { |
---|
[195] | 763 | |
---|
| 764 | $domain_len = 0 - strlen( $domain ); |
---|
| 765 | if( substr( $host, $domain_len ) != $domain ) { |
---|
| 766 | $host = $host. '.'.$domain; |
---|
| 767 | } |
---|
[126] | 768 | $cpus = $metrics[$host]["cpu_num"][VAL]; |
---|
| 769 | if (!$cpus) $cpus=1; |
---|
| 770 | $load_one = $metrics[$host]["load_one"][VAL]; |
---|
| 771 | $load = ((float) $load_one)/$cpus; |
---|
| 772 | $host_load[$host] = $load; |
---|
| 773 | $percent_hosts[load_color($load)] += 1; |
---|
| 774 | if ($metricname=="load_one") |
---|
| 775 | $sorted_hosts[$host] = $load; |
---|
| 776 | else |
---|
| 777 | $sorted_hosts[$host] = $metrics[$host][$metricname][VAL]; |
---|
| 778 | } |
---|
| 779 | switch ($sort) { |
---|
| 780 | case "descending": |
---|
| 781 | arsort($sorted_hosts); |
---|
| 782 | break; |
---|
| 783 | case "by hostname": |
---|
| 784 | ksort($sorted_hosts); |
---|
| 785 | break; |
---|
| 786 | default: |
---|
| 787 | case "ascending": |
---|
| 788 | asort($sorted_hosts); |
---|
| 789 | break; |
---|
| 790 | } |
---|
| 791 | |
---|
| 792 | //$sorted_hosts = array_merge($down_hosts, $sorted_hosts); |
---|
| 793 | |
---|
| 794 | # First pass to find the max value in all graphs for this |
---|
| 795 | # metric. The $start,$end variables comes from get_context.php, |
---|
| 796 | # included in index.php. |
---|
| 797 | list($min, $max) = find_limits($sorted_hosts, $metricname); |
---|
| 798 | |
---|
| 799 | # Second pass to output the graphs or metrics. |
---|
| 800 | $i = 1; |
---|
| 801 | foreach ( $sorted_hosts as $host=>$value ) { |
---|
| 802 | $tpl->newBlock ("sorted_list"); |
---|
| 803 | //$host = $host. '.'.$domain; |
---|
| 804 | $host_url = rawurlencode($host); |
---|
| 805 | $cluster_url = rawurlencode($clustername); |
---|
| 806 | |
---|
| 807 | $textval = ""; |
---|
| 808 | //printf("host = %s, value = %s", $host, $value); |
---|
| 809 | //echo "$host: $value, "; |
---|
| 810 | $val = $metrics[$host][$metricname]; |
---|
| 811 | $class = "metric"; |
---|
[148] | 812 | $host_link="\"../../?c=$cluster_url&h=$host_url&r=job&jr=$jobrange&js=$jobstart\""; |
---|
[126] | 813 | |
---|
| 814 | if ($val[TYPE]=="timestamp" or $always_timestamp[$metricname]) { |
---|
| 815 | $textval = date("r", $val[VAL]); |
---|
| 816 | } elseif ($val[TYPE]=="string" or $val[SLOPE]=="zero" or $always_constant[$metricname] or ($max_graphs > 0 and $i > $max_graphs )) { |
---|
| 817 | $textval = "$val[VAL] $val[UNITS]"; |
---|
| 818 | } else { |
---|
| 819 | $load_color = load_color($host_load[$host]); |
---|
| 820 | $graphargs = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&"; |
---|
[193] | 821 | $graphargs .= "z=small&c=$cluster_url&h=$host_url&l=$load_color" ."&v=$val[VAL]&r=job&jr=$jobrange&js=$jobstart"; |
---|
| 822 | if( $max > 0 ) { |
---|
| 823 | |
---|
| 824 | $graphargs .= "&x=$max&n=$min"; |
---|
| 825 | } |
---|
[126] | 826 | } |
---|
| 827 | if ($textval) { |
---|
| 828 | $cell="<td class=$class>". "<b><a href=$host_link>$host</a></b><br>". "<i>$metricname:</i> <b>$textval</b></td>"; |
---|
| 829 | } else { |
---|
[239] | 830 | $cell="<td><a href=$host_link>". "<img src=\"../../graph.php?$graphargs\" ". "alt=\"$host\" border=0></a></td>"; |
---|
[126] | 831 | } |
---|
| 832 | |
---|
| 833 | $tpl->assign("metric_image", $cell); |
---|
| 834 | if (! ($i++ % $hostcols) ) |
---|
| 835 | $tpl->assign ("br", "</tr><tr>"); |
---|
| 836 | } |
---|
| 837 | } |
---|
| 838 | //--- |
---|
| 839 | } |
---|
[114] | 840 | } |
---|
[113] | 841 | ?> |
---|