[113] | 1 | <?php |
---|
[114] | 2 | |
---|
| 3 | $my_dir = getcwd(); |
---|
| 4 | |
---|
| 5 | include_once "./libtoga.php"; |
---|
| 6 | |
---|
| 7 | global $GANGLIA_PATH; |
---|
| 8 | chdir( $GANGLIA_PATH ); |
---|
| 9 | include_once "./class.TemplatePower.inc.php"; |
---|
| 10 | chdir( $my_dir ); |
---|
| 11 | |
---|
| 12 | $httpvars = new HTTPVariables( $HTTP_GET_VARS ); |
---|
| 13 | $clustername = $httpvars->getClusterName(); |
---|
| 14 | |
---|
| 15 | $data_gatherer = new DataGatherer(); |
---|
| 16 | |
---|
| 17 | $tpl = new TemplatePower("templates/overview.tpl"); |
---|
| 18 | $tpl->prepare(); |
---|
| 19 | |
---|
| 20 | $tpl->assign( "clusterimage", "./image.php?c=".$clustername."&view=big-clusterimage" ); |
---|
| 21 | |
---|
| 22 | $data_gatherer->parseXML(); |
---|
| 23 | $heartbeat = $data_gatherer->getHeartbeat(); |
---|
| 24 | $jobs = $data_gatherer->getJobs(); |
---|
| 25 | $nodes = $data_gatherer->getNodes(); |
---|
| 26 | |
---|
| 27 | $tpl->assign("heartbeat", makeDate( $heartbeat ) ); |
---|
| 28 | |
---|
| 29 | $pie = drawPie(); |
---|
| 30 | $tpl->assign("pie", $pie ); |
---|
| 31 | |
---|
| 32 | function makeTime( $time ) { |
---|
| 33 | |
---|
| 34 | $days = intval( $time / 86400 ); |
---|
| 35 | if( $days > 0 ) { |
---|
| 36 | $time = $time % ($days * 86400); |
---|
| 37 | if( $days > 1 ) |
---|
| 38 | $date_str .= $days . 'days - '; |
---|
| 39 | else |
---|
| 40 | $date_str .= $days . 'day - '; |
---|
| 41 | } |
---|
| 42 | $hours = intval( $time / 3600 ); |
---|
| 43 | if( $hours > 0 ) { |
---|
| 44 | $time = $time % ($hours * 3600); |
---|
| 45 | $date_str .= $hours . ':'; |
---|
| 46 | $date_unit = ' hours'; |
---|
| 47 | } |
---|
| 48 | $minutes = intval( $time / 60 ); |
---|
| 49 | if( $minutes > 0 ) { |
---|
| 50 | $seconds = $time % ($minutes * 60); |
---|
| 51 | $date_str .= $minutes . ':'; |
---|
| 52 | $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit; |
---|
| 53 | } |
---|
| 54 | $date_unit = (!isset($date_unit)) ? 'seconds' : $date_unit; |
---|
| 55 | $date_str .= $seconds . ' ' . $date_unit; |
---|
| 56 | |
---|
| 57 | return $date_str; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | function makeDate( $time ) { |
---|
| 61 | return strftime( "%a %d %b %Y %H:%M:%S", $time ); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | function colorRed( $color ) { |
---|
| 65 | return substr( $color, 0, 2 ); |
---|
| 66 | } |
---|
| 67 | function colorGreen( $color ) { |
---|
| 68 | return substr( $color, 2, 2 ); |
---|
| 69 | } |
---|
| 70 | function colorBlue( $color ) { |
---|
| 71 | return substr( $color, 4, 2 ); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | function colorDiffer( $first, $second ) { |
---|
| 75 | |
---|
| 76 | // Make sure these two colors differ atleast 50 R/G/B |
---|
| 77 | $min_diff = 50; |
---|
| 78 | |
---|
| 79 | $c1r = decHex( colorRed( $first ) ); |
---|
| 80 | $c1g = decHex( colorGreen( $first ) ); |
---|
| 81 | $c1b = decHex( colorBlue( $first ) ); |
---|
| 82 | |
---|
| 83 | $c2r = decHex( colorRed( $second ) ); |
---|
| 84 | $c2g = decHex( colorGreen( $second ) ); |
---|
| 85 | $c2b = decHex( colorBlue( $second ) ); |
---|
| 86 | |
---|
| 87 | $rdiff = ($c1r >= $c2r) ? $c1r - $c2r : $c2r - $c1r; |
---|
| 88 | $gdiff = ($c1g >= $c2g) ? $c1g - $c2g : $c2g - $c1g; |
---|
| 89 | $bdiff = ($c1b >= $c2b) ? $c1b - $c2b : $c2b - $c1b; |
---|
| 90 | |
---|
| 91 | if( $rdiff >= $min_diff or $gdiff >= $min_diff or $bdiff >= $min_diff ) |
---|
| 92 | return TRUE; |
---|
| 93 | else |
---|
| 94 | return FALSE; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | function randomColor( $known_colors ) { |
---|
| 98 | |
---|
| 99 | $start = hexdec( "004E00" ); |
---|
| 100 | $end = hexdec( "FFFFFF" ); |
---|
| 101 | |
---|
| 102 | if( count( $known_colors ) == 0 ) |
---|
| 103 | return dechex(rand( $start, $end )); |
---|
| 104 | |
---|
| 105 | $color_changed = TRUE; |
---|
| 106 | |
---|
| 107 | while( $color_changed ) { |
---|
| 108 | |
---|
| 109 | $color_changed = FALSE; |
---|
| 110 | |
---|
| 111 | foreach( $known_colors as $old ) { |
---|
| 112 | |
---|
| 113 | if( !isset( $new ) ) |
---|
| 114 | $new = rand( $start, $end ); |
---|
| 115 | |
---|
| 116 | if( !colorDiffer( dechex( $new ), $old ) ) |
---|
| 117 | |
---|
| 118 | while( !colorDiffer( $new, $old ) ) { |
---|
| 119 | |
---|
| 120 | $new = rand( $start, $end ); |
---|
| 121 | $color_changed = TRUE; |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | // Whoa! Actually found a good color ;) |
---|
| 127 | return dechex( $new ); |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | function drawPie() { |
---|
| 131 | |
---|
| 132 | global $jobs, $nodes; |
---|
| 133 | |
---|
| 134 | $pie_args = "title=" . rawurlencode("Cluster Jobload"); |
---|
| 135 | $pie_args .= "&size=250x150"; |
---|
| 136 | |
---|
| 137 | $queues = array(); |
---|
| 138 | $nr_jobs = count( $jobs ); |
---|
| 139 | $nr_nodes = count( $nodes ); |
---|
| 140 | |
---|
| 141 | $emptynodes = 0; |
---|
| 142 | |
---|
| 143 | foreach( $nodes as $node ) { |
---|
| 144 | |
---|
| 145 | $myjobs = $node->getJobs(); |
---|
| 146 | |
---|
| 147 | if( count( $myjobs ) == 0 ) |
---|
| 148 | $emptynodes++; |
---|
| 149 | else |
---|
| 150 | $nodes_jobs = $nodes_jobs + count( $myjobs ); |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | $empty_percentage = ($emptynodes / $nr_nodes) * 100; |
---|
| 154 | $job_percentage = 100 - $empty_percentage; |
---|
| 155 | |
---|
| 156 | $color = randomColor( $qcolors ); |
---|
| 157 | $qcolors[] = $color; |
---|
| 158 | $pie_args .= "&free=$empty_percentage,$color"; |
---|
| 159 | |
---|
| 160 | foreach( $jobs as $jobid => $jobattrs ) { |
---|
| 161 | |
---|
| 162 | $qname = $jobattrs[queue]; |
---|
| 163 | |
---|
| 164 | if( !array_search( $qname, $queues ) ) { |
---|
| 165 | |
---|
| 166 | if( !isset( $queues[$qname] ) ) |
---|
| 167 | $queues[$qname] = array(); |
---|
| 168 | |
---|
| 169 | $queues[$qname][] = $jobid; |
---|
| 170 | } |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | $qcolors = array(); |
---|
| 174 | foreach( $queues as $queue => $myjobs ) { |
---|
| 175 | |
---|
| 176 | $qjobs = count ( $myjobs ); |
---|
| 177 | $percentage = ( $qjobs / $nr_jobs ) * $job_percentage; |
---|
| 178 | $color = randomColor( $qcolors ); |
---|
| 179 | $qcolors[] = $color; |
---|
| 180 | $pie_args .= "&$queue=$percentage,$color"; |
---|
| 181 | } |
---|
| 182 | $pie = "../../pie.php?$pie_args"; |
---|
| 183 | |
---|
| 184 | return $pie; |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | foreach( $jobs as $jobid => $jobattrs ) { |
---|
| 188 | |
---|
| 189 | $report_time = $jobattrs[reported]; |
---|
| 190 | |
---|
| 191 | if( $report_time == $heartbeat ) { |
---|
| 192 | |
---|
| 193 | $tpl->newBlock("node"); |
---|
| 194 | $tpl->assign("id", $jobid ); |
---|
| 195 | $tpl->assign("state", $jobattrs[status] ); |
---|
| 196 | $tpl->assign("user", $jobattrs[owner] ); |
---|
| 197 | $tpl->assign("queue", $jobattrs[queue] ); |
---|
| 198 | $tpl->assign("name", $jobattrs[name] ); |
---|
| 199 | $nodes = count( $jobattrs[nodes] ); |
---|
| 200 | $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1; |
---|
| 201 | $cpus = $nodes * $ppn; |
---|
| 202 | $tpl->assign("cpus", $cpus ); |
---|
| 203 | $tpl->assign("req_cpu", $jobattrs[requested_time] ); |
---|
| 204 | $tpl->assign("req_memory", $jobattrs[requested_memory] ); |
---|
| 205 | $tpl->assign("nodes", $nodes ); |
---|
| 206 | $start_time = (int) $jobattrs[start_timestamp]; |
---|
| 207 | $runningtime = makeTime( $report_time - $start_time ); |
---|
| 208 | $tpl->assign("started", makeDate( $start_time ) ); |
---|
| 209 | $tpl->assign("runningtime", $runningtime ); |
---|
| 210 | } |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | $tpl->printToScreen(); |
---|
| 214 | |
---|
[113] | 215 | ?> |
---|