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