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