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