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