[113] | 1 | <?php |
---|
[122] | 2 | global $GANGLIA_PATH, $clustername, $tpl, $filter, $cluster, $get_metric_string, $cluster_url; |
---|
[114] | 3 | |
---|
| 4 | $data_gatherer = new DataGatherer(); |
---|
| 5 | |
---|
[117] | 6 | //$tpl->assign( "self", "./index.php" ); |
---|
[116] | 7 | $tpl->assign( "clustername", $clustername ); |
---|
| 8 | |
---|
[114] | 9 | $data_gatherer->parseXML(); |
---|
[117] | 10 | |
---|
[114] | 11 | $heartbeat = $data_gatherer->getHeartbeat(); |
---|
| 12 | $jobs = $data_gatherer->getJobs(); |
---|
| 13 | $nodes = $data_gatherer->getNodes(); |
---|
| 14 | |
---|
[122] | 15 | $filter_image_url = ""; |
---|
| 16 | |
---|
[119] | 17 | foreach( $filter as $filtername => $filtervalue ) { |
---|
| 18 | $tpl->assign( "f_".$filtername, $filtervalue ); |
---|
[122] | 19 | $filter_image_url .= "&$filtername=$filtervalue"; |
---|
[119] | 20 | } |
---|
| 21 | |
---|
[122] | 22 | $tpl->assign( "clusterimage", "./image.php?c=".rawurlencode($clustername)."&view=big-clusterimage".$filter_image_url ); |
---|
| 23 | |
---|
[114] | 24 | $tpl->assign("heartbeat", makeDate( $heartbeat ) ); |
---|
| 25 | |
---|
| 26 | $pie = drawPie(); |
---|
| 27 | $tpl->assign("pie", $pie ); |
---|
| 28 | |
---|
[122] | 29 | //if( !array_key_exists( 'id', $filter ) ) { |
---|
| 30 | |
---|
| 31 | // $graph_args = "c=$cluster_url&$get_metric_string&st=$cluster[LOCALTIME]"; |
---|
| 32 | // $tpl->newBlock( "average_graphs" ); |
---|
| 33 | // $tpl->assign( "graph_args", $graph_args ); |
---|
| 34 | //} |
---|
| 35 | |
---|
[120] | 36 | function timeToEpoch( $time ) { |
---|
| 37 | |
---|
| 38 | $time_fields = explode( ':', $time ); |
---|
| 39 | |
---|
| 40 | if( count($time_fields) == 3 ) { |
---|
| 41 | |
---|
| 42 | $hours = $time_fields[0]; |
---|
| 43 | $minutes = $time_fields[1]; |
---|
| 44 | $seconds = $time_fields[2]; |
---|
| 45 | |
---|
| 46 | $myepoch = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) ); |
---|
| 47 | return $myepoch; |
---|
| 48 | } |
---|
| 49 | } |
---|
| 50 | |
---|
[114] | 51 | function makeTime( $time ) { |
---|
| 52 | |
---|
| 53 | $days = intval( $time / 86400 ); |
---|
[115] | 54 | $time = $days ? $time % ($days * 86400) : $time; |
---|
| 55 | |
---|
[114] | 56 | if( $days > 0 ) { |
---|
| 57 | if( $days > 1 ) |
---|
[116] | 58 | $date_str .= $days . ' days - '; |
---|
[114] | 59 | else |
---|
[116] | 60 | $date_str .= $days . ' day - '; |
---|
[114] | 61 | } |
---|
[115] | 62 | |
---|
[114] | 63 | $hours = intval( $time / 3600 ); |
---|
[115] | 64 | $time = $hours ? $time % ($hours * 3600) : $time; |
---|
| 65 | |
---|
[114] | 66 | if( $hours > 0 ) { |
---|
| 67 | $date_str .= $hours . ':'; |
---|
| 68 | $date_unit = ' hours'; |
---|
| 69 | } |
---|
[115] | 70 | |
---|
[114] | 71 | $minutes = intval( $time / 60 ); |
---|
[115] | 72 | $seconds = $minutes ? $time % ($minutes * 60) : $time; |
---|
| 73 | |
---|
[114] | 74 | if( $minutes > 0 ) { |
---|
[115] | 75 | |
---|
| 76 | if( $minutes >= 10 ) |
---|
| 77 | $date_str .= $minutes . ':'; |
---|
| 78 | else |
---|
| 79 | $date_str .= '0' . $minutes . ':'; |
---|
| 80 | |
---|
[114] | 81 | $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit; |
---|
[115] | 82 | } else if( $days > 0 or $hours > 0 ) { |
---|
| 83 | $date_str .= '00:'; |
---|
| 84 | $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit; |
---|
[114] | 85 | } |
---|
[115] | 86 | |
---|
[114] | 87 | $date_unit = (!isset($date_unit)) ? 'seconds' : $date_unit; |
---|
| 88 | |
---|
[115] | 89 | if( $seconds > 0 ) { |
---|
| 90 | |
---|
| 91 | if( $seconds >= 10 ) |
---|
| 92 | $date_str .= $seconds . ' ' . $date_unit; |
---|
| 93 | else |
---|
| 94 | $date_str .= '0' . $seconds . ' ' . $date_unit; |
---|
| 95 | |
---|
| 96 | } else if ( $days > 0 or $hours > 0 or $minutes > 0 ) |
---|
| 97 | $date_str .= '00 ' . $date_unit; |
---|
| 98 | |
---|
[114] | 99 | return $date_str; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | function makeDate( $time ) { |
---|
| 103 | return strftime( "%a %d %b %Y %H:%M:%S", $time ); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | function colorRed( $color ) { |
---|
| 107 | return substr( $color, 0, 2 ); |
---|
| 108 | } |
---|
| 109 | function colorGreen( $color ) { |
---|
| 110 | return substr( $color, 2, 2 ); |
---|
| 111 | } |
---|
| 112 | function colorBlue( $color ) { |
---|
| 113 | return substr( $color, 4, 2 ); |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | function colorDiffer( $first, $second ) { |
---|
| 117 | |
---|
| 118 | // Make sure these two colors differ atleast 50 R/G/B |
---|
| 119 | $min_diff = 50; |
---|
| 120 | |
---|
| 121 | $c1r = decHex( colorRed( $first ) ); |
---|
| 122 | $c1g = decHex( colorGreen( $first ) ); |
---|
| 123 | $c1b = decHex( colorBlue( $first ) ); |
---|
| 124 | |
---|
| 125 | $c2r = decHex( colorRed( $second ) ); |
---|
| 126 | $c2g = decHex( colorGreen( $second ) ); |
---|
| 127 | $c2b = decHex( colorBlue( $second ) ); |
---|
| 128 | |
---|
| 129 | $rdiff = ($c1r >= $c2r) ? $c1r - $c2r : $c2r - $c1r; |
---|
| 130 | $gdiff = ($c1g >= $c2g) ? $c1g - $c2g : $c2g - $c1g; |
---|
| 131 | $bdiff = ($c1b >= $c2b) ? $c1b - $c2b : $c2b - $c1b; |
---|
| 132 | |
---|
| 133 | if( $rdiff >= $min_diff or $gdiff >= $min_diff or $bdiff >= $min_diff ) |
---|
| 134 | return TRUE; |
---|
| 135 | else |
---|
| 136 | return FALSE; |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | function randomColor( $known_colors ) { |
---|
| 140 | |
---|
| 141 | $start = hexdec( "004E00" ); |
---|
| 142 | $end = hexdec( "FFFFFF" ); |
---|
| 143 | |
---|
| 144 | if( count( $known_colors ) == 0 ) |
---|
| 145 | return dechex(rand( $start, $end )); |
---|
| 146 | |
---|
| 147 | $color_changed = TRUE; |
---|
| 148 | |
---|
| 149 | while( $color_changed ) { |
---|
| 150 | |
---|
| 151 | $color_changed = FALSE; |
---|
| 152 | |
---|
| 153 | foreach( $known_colors as $old ) { |
---|
| 154 | |
---|
| 155 | if( !isset( $new ) ) |
---|
| 156 | $new = rand( $start, $end ); |
---|
| 157 | |
---|
| 158 | if( !colorDiffer( dechex( $new ), $old ) ) |
---|
| 159 | |
---|
| 160 | while( !colorDiffer( $new, $old ) ) { |
---|
| 161 | |
---|
| 162 | $new = rand( $start, $end ); |
---|
| 163 | $color_changed = TRUE; |
---|
| 164 | } |
---|
| 165 | } |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | // Whoa! Actually found a good color ;) |
---|
| 169 | return dechex( $new ); |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | function drawPie() { |
---|
| 173 | |
---|
| 174 | global $jobs, $nodes; |
---|
| 175 | |
---|
| 176 | $pie_args = "title=" . rawurlencode("Cluster Jobload"); |
---|
| 177 | $pie_args .= "&size=250x150"; |
---|
| 178 | |
---|
| 179 | $queues = array(); |
---|
| 180 | $nr_jobs = count( $jobs ); |
---|
| 181 | $nr_nodes = count( $nodes ); |
---|
| 182 | |
---|
| 183 | $emptynodes = 0; |
---|
| 184 | |
---|
| 185 | foreach( $nodes as $node ) { |
---|
| 186 | |
---|
| 187 | $myjobs = $node->getJobs(); |
---|
| 188 | |
---|
| 189 | if( count( $myjobs ) == 0 ) |
---|
| 190 | $emptynodes++; |
---|
| 191 | else |
---|
| 192 | $nodes_jobs = $nodes_jobs + count( $myjobs ); |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | $empty_percentage = ($emptynodes / $nr_nodes) * 100; |
---|
| 196 | $job_percentage = 100 - $empty_percentage; |
---|
| 197 | |
---|
| 198 | $color = randomColor( $qcolors ); |
---|
| 199 | $qcolors[] = $color; |
---|
| 200 | $pie_args .= "&free=$empty_percentage,$color"; |
---|
| 201 | |
---|
| 202 | foreach( $jobs as $jobid => $jobattrs ) { |
---|
| 203 | |
---|
| 204 | $qname = $jobattrs[queue]; |
---|
| 205 | |
---|
| 206 | if( !array_search( $qname, $queues ) ) { |
---|
| 207 | |
---|
| 208 | if( !isset( $queues[$qname] ) ) |
---|
| 209 | $queues[$qname] = array(); |
---|
| 210 | |
---|
| 211 | $queues[$qname][] = $jobid; |
---|
| 212 | } |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | $qcolors = array(); |
---|
| 216 | foreach( $queues as $queue => $myjobs ) { |
---|
| 217 | |
---|
| 218 | $qjobs = count ( $myjobs ); |
---|
| 219 | $percentage = ( $qjobs / $nr_jobs ) * $job_percentage; |
---|
| 220 | $color = randomColor( $qcolors ); |
---|
| 221 | $qcolors[] = $color; |
---|
| 222 | $pie_args .= "&$queue=$percentage,$color"; |
---|
| 223 | } |
---|
| 224 | $pie = "../../pie.php?$pie_args"; |
---|
| 225 | |
---|
| 226 | return $pie; |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | |
---|
[117] | 230 | function sortJobs( $jobs, $sortby, $sortorder ) { |
---|
[114] | 231 | |
---|
[117] | 232 | $sorted = array(); |
---|
[114] | 233 | |
---|
[117] | 234 | $cmp = create_function( '$a, $b', |
---|
| 235 | "global \$sortby, \$sortorder;". |
---|
[116] | 236 | |
---|
[117] | 237 | "if( \$a == \$b ) return 0;". |
---|
[116] | 238 | |
---|
[117] | 239 | "if (\$sortorder==\"desc\")". |
---|
| 240 | "return ( \$a < \$b ) ? 1 : -1;". |
---|
| 241 | "else if (\$sortorder==\"asc\")". |
---|
| 242 | "return ( \$a > \$b ) ? 1 : -1;" ); |
---|
| 243 | |
---|
| 244 | foreach( $jobs as $jobid => $jobattrs ) { |
---|
| 245 | |
---|
| 246 | $state = $jobattrs[status]; |
---|
| 247 | $user = $jobattrs[owner]; |
---|
| 248 | $queue = $jobattrs[queue]; |
---|
| 249 | $name = $jobattrs[name]; |
---|
| 250 | $req_cpu = $jobattrs[requested_time]; |
---|
| 251 | $req_memory = $jobattrs[requested_memory]; |
---|
| 252 | $nodes = count( $jobattrs[nodes] ); |
---|
| 253 | $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1; |
---|
| 254 | $cpus = $nodes * $ppn; |
---|
| 255 | $start_time = (int) $jobattrs[start_timestamp]; |
---|
| 256 | $runningtime = $report_time - $start_time; |
---|
| 257 | |
---|
| 258 | switch( $sortby ) { |
---|
| 259 | case "id": |
---|
| 260 | $sorted[$jobid] = $jobid; |
---|
| 261 | break; |
---|
| 262 | |
---|
| 263 | case "state": |
---|
| 264 | $sorted[$jobid] = $state; |
---|
| 265 | break; |
---|
| 266 | |
---|
| 267 | case "user": |
---|
| 268 | $sorted[$jobid] = $user; |
---|
| 269 | break; |
---|
| 270 | |
---|
| 271 | case "queue": |
---|
| 272 | $sorted[$jobid] = $queue; |
---|
| 273 | break; |
---|
| 274 | |
---|
| 275 | case "name": |
---|
| 276 | $sorted[$jobid] = $name; |
---|
| 277 | break; |
---|
| 278 | |
---|
| 279 | case "req_cpu": |
---|
| 280 | $sorted[$jobid] = $req_cpu; |
---|
| 281 | break; |
---|
| 282 | |
---|
| 283 | case "req_mem": |
---|
| 284 | $sorted[$jobid] = $req_memory; |
---|
| 285 | break; |
---|
| 286 | |
---|
| 287 | case "nodes": |
---|
| 288 | $sorted[$jobid] = $nodes; |
---|
| 289 | break; |
---|
| 290 | |
---|
| 291 | case "cpus": |
---|
| 292 | $sorted[$jobid] = $cpus; |
---|
| 293 | break; |
---|
| 294 | |
---|
| 295 | case "start": |
---|
| 296 | $sorted[$jobid] = $start_time; |
---|
| 297 | break; |
---|
| 298 | |
---|
| 299 | case "runningtime": |
---|
| 300 | $sorted[$jobid] = $runningtime; |
---|
| 301 | break; |
---|
| 302 | |
---|
| 303 | default: |
---|
| 304 | break; |
---|
| 305 | |
---|
| 306 | } |
---|
| 307 | } |
---|
| 308 | |
---|
| 309 | uasort( $sorted, $cmp ); |
---|
| 310 | |
---|
| 311 | return $sorted; |
---|
| 312 | } |
---|
| 313 | |
---|
| 314 | function makeOverview() { |
---|
| 315 | |
---|
| 316 | global $jobs, $nodes, $heartbeat, $clustername, $tpl; |
---|
[119] | 317 | global $sortorder, $sortby, $filter; |
---|
[117] | 318 | |
---|
| 319 | $tpl->assign("sortorder", $sortorder ); |
---|
| 320 | $tpl->assign("sortby", $sortby ); |
---|
| 321 | |
---|
| 322 | $sorted_jobs = sortJobs( $jobs, $sortby, $sortorder ); |
---|
| 323 | |
---|
[118] | 324 | $even = 1; |
---|
| 325 | |
---|
[117] | 326 | foreach( $sorted_jobs as $jobid => $sortdec ) { |
---|
| 327 | |
---|
| 328 | $report_time = $jobs[$jobid][reported]; |
---|
| 329 | |
---|
| 330 | if( $report_time == $heartbeat ) { |
---|
| 331 | |
---|
[119] | 332 | if( count( $filter ) == 0 ) |
---|
| 333 | $display_job = 1; |
---|
| 334 | else |
---|
| 335 | $display_job = 0; |
---|
[117] | 336 | |
---|
[119] | 337 | foreach( $filter as $filtername=>$filtervalue ) { |
---|
[118] | 338 | |
---|
[119] | 339 | if( $filtername == 'id' && $jobid == $filtervalue ) |
---|
| 340 | $display_job = 1; |
---|
| 341 | else if( $filtername == 'state' && $jobs[$jobid][status] == $filtervalue ) |
---|
| 342 | $display_job = 1; |
---|
| 343 | else if( $filtername == 'queue' && $jobs[$jobid][queue] == $filtervalue ) |
---|
| 344 | $display_job = 1; |
---|
| 345 | else if( $filtername == 'user' && $jobs[$jobid][owner] == $filtervalue ) |
---|
| 346 | $display_job = 1; |
---|
[118] | 347 | } |
---|
| 348 | |
---|
[119] | 349 | if( $display_job ) { |
---|
[117] | 350 | |
---|
[119] | 351 | $tpl->newBlock("node"); |
---|
| 352 | $tpl->assign( "clustername", $clustername ); |
---|
| 353 | $tpl->assign("id", $jobid ); |
---|
| 354 | $tpl->assign("state", $jobs[$jobid][status] ); |
---|
| 355 | $tpl->assign("user", $jobs[$jobid][owner] ); |
---|
| 356 | $tpl->assign("queue", $jobs[$jobid][queue] ); |
---|
| 357 | $tpl->assign("name", $jobs[$jobid][name] ); |
---|
[120] | 358 | $tpl->assign("req_cpu", makeTime( timeToEpoch( $jobs[$jobid][requested_time] ) ) ); |
---|
[119] | 359 | $tpl->assign("req_memory", $jobs[$jobid][requested_memory] ); |
---|
| 360 | $nodes = count( $jobs[$jobid][nodes] ); |
---|
| 361 | $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1; |
---|
| 362 | $cpus = $nodes * $ppn; |
---|
| 363 | $tpl->assign("nodes", $nodes ); |
---|
| 364 | $tpl->assign("cpus", $cpus ); |
---|
| 365 | $start_time = (int) $jobs[$jobid][start_timestamp]; |
---|
| 366 | |
---|
| 367 | if( $even ) { |
---|
| 368 | |
---|
| 369 | $tpl->assign("nodeclass", "even"); |
---|
| 370 | $even = 0; |
---|
| 371 | } else { |
---|
| 372 | |
---|
| 373 | $tpl->assign("nodeclass", "odd"); |
---|
| 374 | $even = 1; |
---|
| 375 | } |
---|
| 376 | |
---|
| 377 | if( $start_time ) { |
---|
| 378 | |
---|
| 379 | $runningtime = makeTime( $report_time - $start_time ); |
---|
| 380 | $tpl->assign("started", makeDate( $start_time ) ); |
---|
| 381 | $tpl->assign("runningtime", $runningtime ); |
---|
| 382 | } |
---|
[117] | 383 | } |
---|
[116] | 384 | } |
---|
[114] | 385 | } |
---|
| 386 | } |
---|
[113] | 387 | ?> |
---|