PHP监测Memcache服务端的运行状况(6)

$col_white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
 $col_red  = imagecolorallocate($image, 0xD0, 0x60,  0x30);
 $col_green = imagecolorallocate($image, 0x60, 0xF0, 0x60);
 $col_black = imagecolorallocate($image,  0,  0,  0);

imagecolortransparent($image,$col_white);

switch ($_GET['IMG']){
        case 1: // pie chart
            $tsize=$memcacheStats['limit_maxbytes'];
      $avail=$tsize-$memcacheStats['bytes'];
      $x=$y=$size/2;
      $angle_from = 0;
      $fuzz = 0.000001;

foreach($memcacheStatsSingle as $serv=>$mcs) {
       $free = $mcs['STAT']['limit_maxbytes']-$mcs['STAT']['bytes'];
       $used = $mcs['STAT']['bytes'];


                if ($free>0){
       // draw free
          $angle_to = ($free*360)/$tsize;
                    $perc =sprintf("%.2f%%", ($free *100) / $tsize) ;

fill_arc($image,$x,$y,$size,$angle_from,$angle_from + $angle_to ,$col_black,$col_green,$perc);
           $angle_from = $angle_from + $angle_to ;
                }
       if ($used>0){
       // draw used
           $angle_to = ($used*360)/$tsize;
           $perc =sprintf("%.2f%%", ($used *100) / $tsize) ;
           fill_arc($image,$x,$y,$size,$angle_from,$angle_from + $angle_to ,$col_black,$col_red, '('.$perc.')' );
                    $angle_from = $angle_from+ $angle_to ;
       }
       }

break;

case 2: // hit miss

$hits = ($memcacheStats['get_hits']==0) ? 1:$memcacheStats['get_hits'];
            $misses = ($memcacheStats['get_misses']==0) ? 1:$memcacheStats['get_misses'];
            $total = $hits + $misses ;

fill_box($image, 30,$size,50,-$hits*($size-21)/$total,$col_black,$col_green,sprintf("%.1f%%",$hits*100/$total));
      fill_box($image,130,$size,50,-max(4,($total-$hits)*($size-21)/$total),$col_black,$col_red,sprintf("%.1f%%",$misses*100/$total));
  break;
 
    }
    header("Content-type: image/png");
 imagepng($image);
 exit;
}

echo getHeader();
echo getMenu();

switch ($_GET['op']) {

case 1: // host stats
     $phpversion = phpversion();
        $memcacheStats = getMemcacheStats();
        $memcacheStatsSingle = getMemcacheStats(false);

$mem_size = $memcacheStats['limit_maxbytes'];
     $mem_used = $memcacheStats['bytes'];
    $mem_avail= $mem_size-$mem_used;
    $startTime = time()-array_sum($memcacheStats['uptime']);

$curr_items = $memcacheStats['curr_items'];
        $total_items = $memcacheStats['total_items'];
        $hits = ($memcacheStats['get_hits']==0) ? 1:$memcacheStats['get_hits'];
        $misses = ($memcacheStats['get_misses']==0) ? 1:$memcacheStats['get_misses'];
        $sets = $memcacheStats['cmd_set'];

$req_rate = sprintf("%.2f",($hits+$misses)/($time-$startTime));
    $hit_rate = sprintf("%.2f",($hits)/($time-$startTime));
    $miss_rate = sprintf("%.2f",($misses)/($time-$startTime));
    $set_rate = sprintf("%.2f",($sets)/($time-$startTime));

echo <<< EOB
  <div><h2>General Cache Information</h2>
  <table cellspacing=0><tbody>
  <tr><td>PHP Version</td><td>$phpversion</td></tr>
EOB;
  echo "<tr><td>Memcached Host". ((count($MEMCACHE_SERVERS)>1) ? 's':'')."</td><td>";
  $i=0;
  if (!isset($_GET['singleout']) && count($MEMCACHE_SERVERS)>1){
      foreach($MEMCACHE_SERVERS as $server){
            echo ($i+1).'. <a href="'https://www.linuxidc.com/Linux/2014-11/.$PHP_SELF.'&singleout='.$i++.'">'.$server.'</a><br/>';
      }
  }
  else{
      echo '1.'.$MEMCACHE_SERVERS[0];
  }
  if (isset($_GET['singleout'])){
        echo '<a href="'https://www.linuxidc.com/Linux/2014-11/.$PHP_SELF.'">(all servers)</a><br/>';
  }
  echo "</td></tr>\n";
  echo "<tr><td>Total Memcache Cache</td><td>".bsize($memcacheStats['limit_maxbytes'])."</td></tr>\n";

echo <<<EOB
  </tbody></table>
  </div>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/8864f323703fffce391c0cd784e04a30.html