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