[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 303 2007-04-16 14:28:06Z 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 | |
---|
[127] | 184 | global $jobs, $gnodes, $piefilter, $filter; |
---|
[114] | 185 | |
---|
[126] | 186 | $nodes = $gnodes; |
---|
[127] | 187 | |
---|
| 188 | if( isset($piefilter) ) |
---|
| 189 | $pie_args = "title=" . rawurlencode("Cluster ".$piefilter." usage"); |
---|
| 190 | else |
---|
| 191 | $pie_args = "title=" . rawurlencode("Cluster queue usage"); |
---|
| 192 | |
---|
[114] | 193 | $pie_args .= "&size=250x150"; |
---|
| 194 | |
---|
| 195 | $queues = array(); |
---|
| 196 | $nr_jobs = count( $jobs ); |
---|
| 197 | $nr_nodes = count( $nodes ); |
---|
| 198 | |
---|
| 199 | $emptynodes = 0; |
---|
| 200 | |
---|
[123] | 201 | $job_weight = array(); |
---|
| 202 | |
---|
[114] | 203 | foreach( $nodes as $node ) { |
---|
| 204 | |
---|
| 205 | $myjobs = $node->getJobs(); |
---|
| 206 | |
---|
| 207 | if( count( $myjobs ) == 0 ) |
---|
| 208 | $emptynodes++; |
---|
| 209 | } |
---|
[123] | 210 | $used_nodes = $nr_nodes - $emptynodes; |
---|
[114] | 211 | |
---|
| 212 | $empty_percentage = ($emptynodes / $nr_nodes) * 100; |
---|
| 213 | $job_percentage = 100 - $empty_percentage; |
---|
| 214 | |
---|
[127] | 215 | $qcolors = array(); |
---|
[114] | 216 | $color = randomColor( $qcolors ); |
---|
| 217 | $qcolors[] = $color; |
---|
| 218 | $pie_args .= "&free=$empty_percentage,$color"; |
---|
| 219 | |
---|
[127] | 220 | if( isset( $piefilter ) ) |
---|
| 221 | $filterpie = array(); |
---|
| 222 | |
---|
[123] | 223 | foreach( $nodes as $node ) { |
---|
[114] | 224 | |
---|
[123] | 225 | $node_jobs = $node->getJobs(); |
---|
| 226 | $nr_node_jobs = count( $node_jobs ); |
---|
| 227 | $myhost = $node->getHostname(); |
---|
[114] | 228 | |
---|
[123] | 229 | foreach( $node_jobs as $myjob ) { |
---|
[114] | 230 | |
---|
[123] | 231 | // Determine the weight of this job on the node it is running |
---|
| 232 | // - what percentage of the node is in use by this job |
---|
| 233 | // |
---|
| 234 | $job_weight[$myjob] = ( 100 / count( $node_jobs ) ) / 100; |
---|
| 235 | $qname = $jobs[$myjob][queue]; |
---|
| 236 | |
---|
[127] | 237 | if( isset($piefilter) ) { |
---|
| 238 | $countjob = 1; |
---|
| 239 | if( $piefilter == 'id' ) { |
---|
| 240 | if( $myjob != $filter[$piefilter] ) |
---|
| 241 | $countjob = 0; |
---|
| 242 | } else if( $piefilter == 'user' ) { |
---|
| 243 | if( $jobs[$myjob][owner] != $filter[$piefilter] ) |
---|
| 244 | $countjob = 0; |
---|
| 245 | } else { |
---|
| 246 | if( $jobs[$myjob][$piefilter] != $filter[$piefilter] ) |
---|
| 247 | $countjob = 0; |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | if( $countjob ) { |
---|
| 251 | |
---|
| 252 | if( !isset( $filterpie[$filter[$piefilter]] ) ) |
---|
| 253 | $filterpie[$filter[$piefilter]] = $job_weight[$myjob]; |
---|
| 254 | else |
---|
| 255 | $filterpie[$filter[$piefilter]] = $filterpie[$filter[$piefilter]] + $job_weight[$myjob]; |
---|
| 256 | } else { |
---|
| 257 | if( !isset( $filterpie["other"] ) ) |
---|
| 258 | $filterpie["other"] = $job_weight[$myjob]; |
---|
| 259 | else |
---|
| 260 | $filterpie["other"] = $filterpie["other"] + $job_weight[$myjob]; |
---|
| 261 | |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | } else { |
---|
| 265 | |
---|
| 266 | if( !isset( $queues[$qname] ) ) |
---|
| 267 | $queues[$qname] = $job_weight[$myjob]; |
---|
| 268 | else |
---|
| 269 | $queues[$qname] = $queues[$qname] + $job_weight[$myjob]; |
---|
| 270 | } |
---|
[114] | 271 | } |
---|
| 272 | } |
---|
| 273 | |
---|
[127] | 274 | //$qcolors = array(); |
---|
| 275 | if( isset( $piefilter ) ) |
---|
| 276 | $graphvals = $filterpie; |
---|
| 277 | else |
---|
| 278 | $graphvals = $queues; |
---|
[114] | 279 | |
---|
[127] | 280 | foreach( $graphvals as $name => $totalweight) { |
---|
| 281 | |
---|
[123] | 282 | $percentage = ( $totalweight / $used_nodes ) * $job_percentage; |
---|
| 283 | |
---|
[114] | 284 | $color = randomColor( $qcolors ); |
---|
| 285 | $qcolors[] = $color; |
---|
[127] | 286 | $pie_args .= "&$name=$percentage,$color"; |
---|
[114] | 287 | } |
---|
| 288 | $pie = "../../pie.php?$pie_args"; |
---|
| 289 | |
---|
| 290 | return $pie; |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | |
---|
[117] | 294 | function sortJobs( $jobs, $sortby, $sortorder ) { |
---|
[114] | 295 | |
---|
[117] | 296 | $sorted = array(); |
---|
[114] | 297 | |
---|
[117] | 298 | $cmp = create_function( '$a, $b', |
---|
| 299 | "global \$sortby, \$sortorder;". |
---|
[116] | 300 | |
---|
[117] | 301 | "if( \$a == \$b ) return 0;". |
---|
[116] | 302 | |
---|
[117] | 303 | "if (\$sortorder==\"desc\")". |
---|
| 304 | "return ( \$a < \$b ) ? 1 : -1;". |
---|
| 305 | "else if (\$sortorder==\"asc\")". |
---|
| 306 | "return ( \$a > \$b ) ? 1 : -1;" ); |
---|
| 307 | |
---|
[301] | 308 | if( isset( $jobs ) && count( $jobs ) > 0 ) { |
---|
[117] | 309 | |
---|
[301] | 310 | foreach( $jobs as $jobid => $jobattrs ) { |
---|
[135] | 311 | |
---|
[301] | 312 | $state = $jobattrs[status]; |
---|
| 313 | $user = $jobattrs[owner]; |
---|
| 314 | $queue = $jobattrs[queue]; |
---|
| 315 | $name = $jobattrs[name]; |
---|
| 316 | $req_cpu = $jobattrs[requested_time]; |
---|
| 317 | $req_memory = $jobattrs[requested_memory]; |
---|
[135] | 318 | |
---|
[301] | 319 | if( $state == 'R' ) |
---|
| 320 | $nodes = count( $jobattrs[nodes] ); |
---|
| 321 | else |
---|
| 322 | $nodes = $jobattrs[nodes]; |
---|
[117] | 323 | |
---|
[301] | 324 | $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1; |
---|
| 325 | $cpus = $nodes * $ppn; |
---|
| 326 | $queued_time = (int) $jobattrs[queued_timestamp]; |
---|
| 327 | $start_time = (int) $jobattrs[start_timestamp]; |
---|
| 328 | $runningtime = $report_time - $start_time; |
---|
[117] | 329 | |
---|
[301] | 330 | switch( $sortby ) { |
---|
| 331 | case "id": |
---|
| 332 | $sorted[$jobid] = $jobid; |
---|
| 333 | break; |
---|
[117] | 334 | |
---|
[301] | 335 | case "state": |
---|
| 336 | $sorted[$jobid] = $state; |
---|
| 337 | break; |
---|
[117] | 338 | |
---|
[301] | 339 | case "user": |
---|
| 340 | $sorted[$jobid] = $user; |
---|
| 341 | break; |
---|
[117] | 342 | |
---|
[301] | 343 | case "queue": |
---|
| 344 | $sorted[$jobid] = $queue; |
---|
| 345 | break; |
---|
[117] | 346 | |
---|
[301] | 347 | case "name": |
---|
| 348 | $sorted[$jobid] = $name; |
---|
| 349 | break; |
---|
[117] | 350 | |
---|
[301] | 351 | case "req_cpu": |
---|
| 352 | $sorted[$jobid] = timeToEpoch( $req_cpu ); |
---|
| 353 | break; |
---|
[117] | 354 | |
---|
[301] | 355 | case "req_mem": |
---|
| 356 | $sorted[$jobid] = $req_memory; |
---|
| 357 | break; |
---|
[117] | 358 | |
---|
[301] | 359 | case "nodes": |
---|
| 360 | $sorted[$jobid] = $nodes; |
---|
| 361 | break; |
---|
[117] | 362 | |
---|
[301] | 363 | case "cpus": |
---|
| 364 | $sorted[$jobid] = $cpus; |
---|
| 365 | break; |
---|
[245] | 366 | |
---|
[301] | 367 | case "queued": |
---|
| 368 | $sorted[$jobid] = $queued_time; |
---|
| 369 | break; |
---|
[117] | 370 | |
---|
[301] | 371 | case "start": |
---|
| 372 | $sorted[$jobid] = $start_time; |
---|
| 373 | break; |
---|
[117] | 374 | |
---|
[301] | 375 | case "runningtime": |
---|
| 376 | $sorted[$jobid] = $runningtime; |
---|
| 377 | break; |
---|
[117] | 378 | |
---|
[301] | 379 | default: |
---|
| 380 | break; |
---|
[117] | 381 | |
---|
[301] | 382 | } |
---|
| 383 | } |
---|
| 384 | } |
---|
| 385 | |
---|
[128] | 386 | //uasort( $sorted, $cmp ); |
---|
| 387 | if( $sortorder == "asc" ) |
---|
| 388 | arsort( $sorted ); |
---|
| 389 | else if( $sortorder == "desc" ) |
---|
| 390 | asort( $sorted ); |
---|
[117] | 391 | |
---|
| 392 | return $sorted; |
---|
| 393 | } |
---|
| 394 | |
---|
| 395 | function makeOverview() { |
---|
| 396 | |
---|
| 397 | global $jobs, $nodes, $heartbeat, $clustername, $tpl; |
---|
[126] | 398 | global $sortorder, $sortby, $filter, $sh, $hc, $m; |
---|
| 399 | global $cluster_url, $get_metric_string, $host_url, $metrics; |
---|
[129] | 400 | global $start, $end, $reports, $gnodes, $default_showhosts; |
---|
[299] | 401 | global $COLUMN_QUEUED, $COLUMN_REQUESTED_MEMORY, $COLUMN_NODES, $hostname; |
---|
[126] | 402 | $metricname = $m; |
---|
| 403 | |
---|
[117] | 404 | $tpl->assign("sortorder", $sortorder ); |
---|
| 405 | $tpl->assign("sortby", $sortby ); |
---|
| 406 | |
---|
| 407 | $sorted_jobs = sortJobs( $jobs, $sortby, $sortorder ); |
---|
| 408 | |
---|
[118] | 409 | $even = 1; |
---|
| 410 | |
---|
[135] | 411 | $used_jobs = 0; |
---|
| 412 | $used_cpus = 0; |
---|
| 413 | $used_nodes = 0; |
---|
[124] | 414 | |
---|
[208] | 415 | $queued_jobs = 0; |
---|
| 416 | $queued_nodes = 0; |
---|
| 417 | $queued_cpus = 0; |
---|
| 418 | |
---|
| 419 | $total_nodes = 0; |
---|
| 420 | $total_cpus = 0; |
---|
| 421 | $total_jobs = 0; |
---|
| 422 | |
---|
[135] | 423 | $all_used_nodes = array(); |
---|
[208] | 424 | $total_used_nodes = array(); |
---|
[124] | 425 | |
---|
[208] | 426 | $running_name_nodes = array(); |
---|
| 427 | |
---|
| 428 | $running_nodes = 0; |
---|
| 429 | $running_jobs = 0; |
---|
| 430 | $running_cpus = 0; |
---|
| 431 | |
---|
[135] | 432 | $avail_nodes = count( $gnodes ); |
---|
| 433 | $avail_cpus = cluster_sum("cpu_num", $metrics); |
---|
| 434 | |
---|
| 435 | $view_cpus = 0; |
---|
| 436 | $view_jobs = 0; |
---|
| 437 | $view_nodes = 0; |
---|
| 438 | |
---|
[208] | 439 | $all_nodes = 0; |
---|
| 440 | $all_jobs = 0; |
---|
| 441 | $all_cpus = 0; |
---|
[135] | 442 | |
---|
[208] | 443 | $view_name_nodes = array(); |
---|
| 444 | |
---|
[241] | 445 | if( $COLUMN_REQUESTED_MEMORY ) { |
---|
[242] | 446 | $tpl->newBlock( "column_header_req_mem" ); |
---|
[241] | 447 | } |
---|
| 448 | |
---|
[299] | 449 | if( $COLUMN_NODES ) { |
---|
| 450 | $tpl->newBlock( "column_header_nodes" ); |
---|
| 451 | } |
---|
| 452 | |
---|
[242] | 453 | if( $COLUMN_QUEUED ) { |
---|
| 454 | $tpl->newBlock( "column_header_queued" ); |
---|
| 455 | } |
---|
| 456 | |
---|
[263] | 457 | $last_displayed_job = null; |
---|
| 458 | |
---|
[117] | 459 | foreach( $sorted_jobs as $jobid => $sortdec ) { |
---|
| 460 | |
---|
| 461 | $report_time = $jobs[$jobid][reported]; |
---|
| 462 | |
---|
[208] | 463 | if( $jobs[$jobid][status] == 'R' ) |
---|
| 464 | $nodes = count( $jobs[$jobid][nodes] ); |
---|
| 465 | else if( $jobs[$jobid][status] == 'Q' ) |
---|
| 466 | $nodes = $jobs[$jobid][nodes]; |
---|
| 467 | |
---|
[124] | 468 | $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1; |
---|
| 469 | $cpus = $nodes * $ppn; |
---|
| 470 | |
---|
[208] | 471 | if( $report_time == $heartbeat ) { |
---|
[124] | 472 | |
---|
[208] | 473 | $display_job = 1; |
---|
| 474 | |
---|
[300] | 475 | if( $jobs[$jobid][status] == 'R' ) { |
---|
| 476 | foreach( $jobs[$jobid][nodes] as $tempnode ) { |
---|
| 477 | $all_used_nodes[] = $tempnode; |
---|
| 478 | } |
---|
| 479 | } |
---|
[208] | 480 | |
---|
[135] | 481 | $used_cpus += $cpus; |
---|
| 482 | |
---|
[208] | 483 | if( $jobs[$jobid][status] == 'R' ) { |
---|
| 484 | $running_cpus += $cpus; |
---|
| 485 | $running_jobs++; |
---|
[117] | 486 | |
---|
[268] | 487 | $found_node_job = 0; |
---|
| 488 | |
---|
[263] | 489 | foreach( $jobs[$jobid][nodes] as $tempnode ) { |
---|
[208] | 490 | $running_name_nodes[] = $tempnode; |
---|
[263] | 491 | |
---|
[297] | 492 | if( isset( $hostname ) && $hostname != '' ) { |
---|
[263] | 493 | //$filter[host] = $hostname; |
---|
| 494 | |
---|
| 495 | $domain_len = 0 - strlen( $jobs[$jobid][domain] ); |
---|
| 496 | $hostnode = $tempnode; |
---|
| 497 | if( substr( $hostnode, $domain_len ) != $jobs[$jobid][domain] ) { |
---|
| 498 | $hostnode = $hostnode. '.'. $jobs[$jobid][domain]; |
---|
| 499 | } |
---|
| 500 | |
---|
[268] | 501 | if( $hostname == $hostnode ) { |
---|
| 502 | $found_node_job = 1; |
---|
| 503 | $display_job = 1; |
---|
| 504 | } else if( !$found_node_job ) { |
---|
[263] | 505 | $display_job = 0; |
---|
[268] | 506 | } |
---|
[297] | 507 | } |
---|
[263] | 508 | } |
---|
[208] | 509 | } |
---|
[117] | 510 | |
---|
[208] | 511 | if( $jobs[$jobid][status] == 'Q' ) { |
---|
[263] | 512 | if( isset( $hostname ) && $hostname != '' ) |
---|
| 513 | $display_job = 0; |
---|
| 514 | |
---|
[208] | 515 | $queued_cpus += $cpus; |
---|
| 516 | $queued_nodes += $nodes; |
---|
| 517 | $queued_jobs++; |
---|
| 518 | } |
---|
| 519 | |
---|
[119] | 520 | foreach( $filter as $filtername=>$filtervalue ) { |
---|
[118] | 521 | |
---|
[124] | 522 | if( $filtername == 'id' && $jobid != $filtervalue ) |
---|
| 523 | $display_job = 0; |
---|
| 524 | else if( $filtername == 'state' && $jobs[$jobid][status] != $filtervalue ) |
---|
| 525 | $display_job = 0; |
---|
| 526 | else if( $filtername == 'queue' && $jobs[$jobid][queue] != $filtervalue ) |
---|
| 527 | $display_job = 0; |
---|
| 528 | else if( $filtername == 'user' && $jobs[$jobid][owner] != $filtervalue ) |
---|
| 529 | $display_job = 0; |
---|
[118] | 530 | } |
---|
| 531 | |
---|
[119] | 532 | if( $display_job ) { |
---|
[117] | 533 | |
---|
[119] | 534 | $tpl->newBlock("node"); |
---|
| 535 | $tpl->assign( "clustername", $clustername ); |
---|
| 536 | $tpl->assign("id", $jobid ); |
---|
[263] | 537 | |
---|
| 538 | $last_displayed_job = $jobid; |
---|
| 539 | |
---|
[119] | 540 | $tpl->assign("state", $jobs[$jobid][status] ); |
---|
[240] | 541 | |
---|
| 542 | $fullstate = ''; |
---|
| 543 | if( $jobs[$jobid][status] == 'R' ) { |
---|
| 544 | $fullstate = "Running"; |
---|
| 545 | } else if( $jobs[$jobid][status] == 'Q' ) { |
---|
| 546 | $fullstate = "Queued"; |
---|
| 547 | } |
---|
| 548 | |
---|
| 549 | $tpl->assign("fullstate", $fullstate ); |
---|
| 550 | |
---|
[119] | 551 | $tpl->assign("user", $jobs[$jobid][owner] ); |
---|
| 552 | $tpl->assign("queue", $jobs[$jobid][queue] ); |
---|
[240] | 553 | |
---|
| 554 | $fulljobname = $jobs[$jobid][name]; |
---|
| 555 | $shortjobname = ''; |
---|
| 556 | |
---|
| 557 | $tpl->assign("fulljobname", $fulljobname ); |
---|
| 558 | |
---|
| 559 | if( mb_strwidth( $fulljobname ) > 10 ) { |
---|
| 560 | $tpl->newBlock("jobname_hint_start"); |
---|
| 561 | $tpl->gotoBlock("node"); |
---|
| 562 | |
---|
| 563 | $shortjobname = mb_strimwidth( $fulljobname, 0, 9 ) . '..'; |
---|
| 564 | } else { |
---|
| 565 | $shortjobname = $fulljobname; |
---|
| 566 | } |
---|
| 567 | |
---|
| 568 | $tpl->assign("name", $shortjobname ); |
---|
| 569 | |
---|
| 570 | if( strlen( $fulljobname ) > 10 ) { |
---|
| 571 | $tpl->newBlock("jobname_hint_end"); |
---|
| 572 | $tpl->gotoBlock("node"); |
---|
| 573 | } |
---|
| 574 | |
---|
[126] | 575 | $domain = $jobs[$jobid][domain]; |
---|
[120] | 576 | $tpl->assign("req_cpu", makeTime( timeToEpoch( $jobs[$jobid][requested_time] ) ) ); |
---|
[135] | 577 | |
---|
[241] | 578 | if( $COLUMN_REQUESTED_MEMORY ) { |
---|
| 579 | $tpl->newBlock( "column_req_mem" ); |
---|
| 580 | $tpl->assign( "req_memory", $jobs[$jobid][requested_memory] ); |
---|
| 581 | $tpl->gotoBlock( "node" ); |
---|
| 582 | } |
---|
[135] | 583 | |
---|
[299] | 584 | |
---|
[242] | 585 | if( $COLUMN_QUEUED ) { |
---|
| 586 | $tpl->newBlock( "column_queued" ); |
---|
[243] | 587 | $tpl->assign( "queued", makeDate( $jobs[$jobid][queued_timestamp] ) ); |
---|
[242] | 588 | $tpl->gotoBlock( "node" ); |
---|
| 589 | } |
---|
| 590 | |
---|
[119] | 591 | $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1; |
---|
| 592 | $cpus = $nodes * $ppn; |
---|
| 593 | $tpl->assign("nodes", $nodes ); |
---|
| 594 | $tpl->assign("cpus", $cpus ); |
---|
| 595 | $start_time = (int) $jobs[$jobid][start_timestamp]; |
---|
[126] | 596 | $job_start = $start_time; |
---|
[119] | 597 | |
---|
[135] | 598 | $view_cpus += $cpus; |
---|
| 599 | $view_jobs++; |
---|
[124] | 600 | |
---|
[299] | 601 | if( $jobs[$jobid][status] == 'R' ) { |
---|
[135] | 602 | foreach( $jobs[$jobid][nodes] as $tempnode ) |
---|
[208] | 603 | $view_name_nodes[] = $tempnode; |
---|
[299] | 604 | |
---|
| 605 | if( $COLUMN_NODES ) { |
---|
| 606 | $tpl->newBlock( "column_nodes" ); |
---|
[302] | 607 | $mynodehosts = array(); |
---|
| 608 | foreach( $jobs[$jobid][nodes] as $mynode ) { |
---|
| 609 | $myhost_href = "./?c=".$clustername."&h=".$mynode.".".$jobs[$jobid][domain]; |
---|
| 610 | $mynodehosts[] = "<A HREF=\"".$myhost_href."\">".$mynode."</A>"; |
---|
| 611 | } |
---|
| 612 | $nodes_hostnames = implode( " ", $mynodehosts ); |
---|
[299] | 613 | $tpl->assign( "nodes_hostnames", $nodes_hostnames ); |
---|
| 614 | $tpl->gotoBlock( "node" ); |
---|
| 615 | } |
---|
| 616 | } else if( $jobs[$jobid][status] == 'Q' ) { |
---|
[208] | 617 | $view_nodes += (int) $jobs[$jobid][nodes]; |
---|
[299] | 618 | } |
---|
[135] | 619 | |
---|
[119] | 620 | if( $even ) { |
---|
| 621 | |
---|
| 622 | $tpl->assign("nodeclass", "even"); |
---|
| 623 | $even = 0; |
---|
| 624 | } else { |
---|
| 625 | |
---|
| 626 | $tpl->assign("nodeclass", "odd"); |
---|
| 627 | $even = 1; |
---|
| 628 | } |
---|
| 629 | |
---|
| 630 | if( $start_time ) { |
---|
| 631 | |
---|
| 632 | $runningtime = makeTime( $report_time - $start_time ); |
---|
[126] | 633 | $job_runningtime = $report_time - $start_time; |
---|
[119] | 634 | $tpl->assign("started", makeDate( $start_time ) ); |
---|
| 635 | $tpl->assign("runningtime", $runningtime ); |
---|
| 636 | } |
---|
[117] | 637 | } |
---|
[116] | 638 | } |
---|
[114] | 639 | } |
---|
[250] | 640 | $all_used_nodes = array_unique( $all_used_nodes ); |
---|
| 641 | $view_name_nodes = array_unique( $view_name_nodes ); |
---|
| 642 | $running_name_nodes = array_unique( $running_name_nodes ); |
---|
[208] | 643 | |
---|
[135] | 644 | $used_nodes = count( $all_used_nodes ); |
---|
[208] | 645 | $view_nodes += count( $view_name_nodes ); |
---|
| 646 | $running_nodes += count( $running_name_nodes ); |
---|
[124] | 647 | |
---|
[208] | 648 | $total_nodes = $queued_nodes + $running_nodes; |
---|
| 649 | $total_cpus = $queued_cpus + $running_cpus; |
---|
| 650 | $total_jobs = $queued_jobs + $running_jobs; |
---|
| 651 | |
---|
[135] | 652 | $tpl->assignGlobal("avail_nodes", $avail_nodes ); |
---|
| 653 | $tpl->assignGlobal("avail_cpus", $avail_cpus ); |
---|
| 654 | |
---|
[208] | 655 | $tpl->assignGlobal("queued_nodes", $queued_nodes ); |
---|
| 656 | $tpl->assignGlobal("queued_jobs", $queued_jobs ); |
---|
| 657 | $tpl->assignGlobal("queued_cpus", $queued_cpus ); |
---|
| 658 | |
---|
| 659 | $tpl->assignGlobal("total_nodes", $total_nodes ); |
---|
| 660 | $tpl->assignGlobal("total_jobs", $total_jobs ); |
---|
| 661 | $tpl->assignGlobal("total_cpus", $total_cpus ); |
---|
| 662 | |
---|
| 663 | $tpl->assignGlobal("running_nodes", $running_nodes ); |
---|
| 664 | $tpl->assignGlobal("running_jobs", $running_jobs ); |
---|
| 665 | $tpl->assignGlobal("running_cpus", $running_cpus ); |
---|
| 666 | |
---|
[135] | 667 | $tpl->assignGlobal("used_nodes", $used_nodes ); |
---|
| 668 | $tpl->assignGlobal("used_jobs", $used_jobs ); |
---|
| 669 | $tpl->assignGlobal("used_cpus", $used_cpus ); |
---|
| 670 | |
---|
[209] | 671 | $free_nodes = $avail_nodes - $running_nodes; |
---|
| 672 | $free_cpus = $avail_cpus - $running_cpus; |
---|
[208] | 673 | |
---|
| 674 | $tpl->assignGlobal("free_nodes", $free_nodes ); |
---|
| 675 | $tpl->assignGlobal("free_cpus", $free_cpus ); |
---|
| 676 | |
---|
[135] | 677 | $tpl->assignGlobal("view_nodes", $view_nodes ); |
---|
| 678 | $tpl->assignGlobal("view_jobs", $view_jobs ); |
---|
| 679 | $tpl->assignGlobal("view_cpus", $view_cpus ); |
---|
| 680 | |
---|
[124] | 681 | $tpl->assignGlobal("report_time", makeDate( $heartbeat)); |
---|
[126] | 682 | |
---|
[266] | 683 | if( intval($view_jobs) == 1 and $start_time ) |
---|
| 684 | if( $last_displayed_job != null ) |
---|
| 685 | $filter[id] = $last_displayed_job; |
---|
[263] | 686 | |
---|
[266] | 687 | makeHeader( 'overview' ); |
---|
[263] | 688 | setupFilterSettings(); |
---|
| 689 | |
---|
[188] | 690 | if( intval($view_jobs) == 1 and $start_time ) { |
---|
[263] | 691 | |
---|
[126] | 692 | $tpl->newBlock( "showhosts" ); |
---|
| 693 | |
---|
| 694 | # Present a width list |
---|
| 695 | $cols_menu = "<SELECT NAME=\"hc\" OnChange=\"toga_form.submit();\">\n"; |
---|
| 696 | |
---|
[263] | 697 | |
---|
[126] | 698 | $hostcols = ($hc) ? $hc : 4; |
---|
| 699 | |
---|
| 700 | foreach(range(1,25) as $cols) { |
---|
| 701 | $cols_menu .= "<OPTION VALUE=$cols "; |
---|
| 702 | if ($cols == $hostcols) |
---|
| 703 | $cols_menu .= "SELECTED"; |
---|
| 704 | $cols_menu .= ">$cols\n"; |
---|
| 705 | } |
---|
| 706 | $cols_menu .= "</SELECT>\n"; |
---|
| 707 | |
---|
| 708 | //$tpl->assign("cluster", $clustername); |
---|
| 709 | $tpl->assign("metric","$metricname $units"); |
---|
[127] | 710 | $tpl->assign("id", $filter[id]); |
---|
[126] | 711 | # Host columns menu defined in header.php |
---|
| 712 | $tpl->assign("cols_menu", $cols_menu); |
---|
| 713 | |
---|
[129] | 714 | $showhosts = isset($sh) ? $sh : $default_showhosts; |
---|
| 715 | //if( !$showhosts) $showhosts = $default_showhosts; |
---|
[126] | 716 | $tpl->assign("checked$showhosts", "checked"); |
---|
| 717 | |
---|
| 718 | if( $showhosts ) { |
---|
| 719 | //----- |
---|
| 720 | |
---|
| 721 | if( !isset($start) ) $start="jobstart"; |
---|
| 722 | if( !isset($stop) ) $stop="now"; |
---|
| 723 | //$tpl->assign("start", $start); |
---|
| 724 | //$tpl->assign("stop", $stop); |
---|
| 725 | |
---|
| 726 | $sorted_hosts = array(); |
---|
| 727 | $hosts_up = $jobs[$filter[id]][nodes]; |
---|
| 728 | |
---|
| 729 | $r = intval($job_runningtime * 1.25); |
---|
| 730 | |
---|
| 731 | $jobrange = ($job_runningtime < 3600) ? -3600 : -$r ; |
---|
| 732 | $jobstart = $report_time - $job_runningtime; |
---|
| 733 | |
---|
| 734 | if ($reports[$metricname]) |
---|
| 735 | $metricval = "g"; |
---|
| 736 | else |
---|
| 737 | $metricval = "m"; |
---|
[263] | 738 | |
---|
[126] | 739 | foreach ($hosts_up as $host ) { |
---|
[195] | 740 | |
---|
| 741 | $domain_len = 0 - strlen( $domain ); |
---|
| 742 | if( substr( $host, $domain_len ) != $domain ) { |
---|
| 743 | $host = $host. '.'.$domain; |
---|
| 744 | } |
---|
[126] | 745 | $cpus = $metrics[$host]["cpu_num"][VAL]; |
---|
| 746 | if (!$cpus) $cpus=1; |
---|
| 747 | $load_one = $metrics[$host]["load_one"][VAL]; |
---|
| 748 | $load = ((float) $load_one)/$cpus; |
---|
| 749 | $host_load[$host] = $load; |
---|
| 750 | $percent_hosts[load_color($load)] += 1; |
---|
| 751 | if ($metricname=="load_one") |
---|
| 752 | $sorted_hosts[$host] = $load; |
---|
| 753 | else |
---|
| 754 | $sorted_hosts[$host] = $metrics[$host][$metricname][VAL]; |
---|
| 755 | } |
---|
| 756 | switch ($sort) { |
---|
| 757 | case "descending": |
---|
| 758 | arsort($sorted_hosts); |
---|
| 759 | break; |
---|
| 760 | case "by hostname": |
---|
| 761 | ksort($sorted_hosts); |
---|
| 762 | break; |
---|
| 763 | default: |
---|
| 764 | case "ascending": |
---|
| 765 | asort($sorted_hosts); |
---|
| 766 | break; |
---|
| 767 | } |
---|
| 768 | |
---|
| 769 | //$sorted_hosts = array_merge($down_hosts, $sorted_hosts); |
---|
| 770 | |
---|
| 771 | # First pass to find the max value in all graphs for this |
---|
| 772 | # metric. The $start,$end variables comes from get_context.php, |
---|
| 773 | # included in index.php. |
---|
| 774 | list($min, $max) = find_limits($sorted_hosts, $metricname); |
---|
| 775 | |
---|
| 776 | # Second pass to output the graphs or metrics. |
---|
| 777 | $i = 1; |
---|
| 778 | foreach ( $sorted_hosts as $host=>$value ) { |
---|
| 779 | $tpl->newBlock ("sorted_list"); |
---|
| 780 | //$host = $host. '.'.$domain; |
---|
| 781 | $host_url = rawurlencode($host); |
---|
| 782 | $cluster_url = rawurlencode($clustername); |
---|
| 783 | |
---|
| 784 | $textval = ""; |
---|
| 785 | //printf("host = %s, value = %s", $host, $value); |
---|
| 786 | //echo "$host: $value, "; |
---|
| 787 | $val = $metrics[$host][$metricname]; |
---|
| 788 | $class = "metric"; |
---|
[148] | 789 | $host_link="\"../../?c=$cluster_url&h=$host_url&r=job&jr=$jobrange&js=$jobstart\""; |
---|
[126] | 790 | |
---|
| 791 | if ($val[TYPE]=="timestamp" or $always_timestamp[$metricname]) { |
---|
| 792 | $textval = date("r", $val[VAL]); |
---|
| 793 | } elseif ($val[TYPE]=="string" or $val[SLOPE]=="zero" or $always_constant[$metricname] or ($max_graphs > 0 and $i > $max_graphs )) { |
---|
| 794 | $textval = "$val[VAL] $val[UNITS]"; |
---|
| 795 | } else { |
---|
| 796 | $load_color = load_color($host_load[$host]); |
---|
| 797 | $graphargs = ($reports[$metricname]) ? "g=$metricname&" : "m=$metricname&"; |
---|
[193] | 798 | $graphargs .= "z=small&c=$cluster_url&h=$host_url&l=$load_color" ."&v=$val[VAL]&r=job&jr=$jobrange&js=$jobstart"; |
---|
| 799 | if( $max > 0 ) { |
---|
| 800 | |
---|
| 801 | $graphargs .= "&x=$max&n=$min"; |
---|
| 802 | } |
---|
[126] | 803 | } |
---|
| 804 | if ($textval) { |
---|
| 805 | $cell="<td class=$class>". "<b><a href=$host_link>$host</a></b><br>". "<i>$metricname:</i> <b>$textval</b></td>"; |
---|
| 806 | } else { |
---|
[239] | 807 | $cell="<td><a href=$host_link>". "<img src=\"../../graph.php?$graphargs\" ". "alt=\"$host\" border=0></a></td>"; |
---|
[126] | 808 | } |
---|
| 809 | |
---|
| 810 | $tpl->assign("metric_image", $cell); |
---|
| 811 | if (! ($i++ % $hostcols) ) |
---|
| 812 | $tpl->assign ("br", "</tr><tr>"); |
---|
| 813 | } |
---|
| 814 | } |
---|
| 815 | //--- |
---|
| 816 | } |
---|
[114] | 817 | } |
---|
[113] | 818 | ?> |
---|