欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php實(shí)現(xiàn)監(jiān)控varnish緩存服務(wù)器的狀態(tài)

 更新時(shí)間:2014年12月30日 11:29:43   投稿:junjie  
這篇文章主要介紹了php實(shí)現(xiàn)監(jiān)控varnish緩存服務(wù)器的狀態(tài),Varnish是一款高性能的開(kāi)源HTTP加速器,可以替代Squid、Nginx等服務(wù)器,需要的朋友可以參考下

當(dāng)varnish和網(wǎng)站部署在同一臺(tái)服務(wù)器上的時(shí)候,我們不可能隨時(shí)登錄上服務(wù)器去查看varnish的命中率,沒(méi)想到有大神早就寫了出來(lái),今天就分享給大家,使用網(wǎng)頁(yè)查看varnish命中率。

系統(tǒng):centos 5.x
軟件:varnish-3.0.x

ps:3.0以下的版本可以通過(guò)Socket連接到Varnish管理端口,通過(guò)stat命令查看,3.0以上沒(méi)有stat命令,只能通過(guò)下面的方法解決。

復(fù)制代碼 代碼如下:

<?php
$outfile=shell_exec("/usr/bin/varnishstat -x");
$xml=simplexml_load_string($outfile);
echo $xml->getName() . "<br />";
foreach($xml->children() as $child)
  {
      //$tmpName="";
      foreach($child->children() as $subChild)
      {
        if ($subChild->getName() =="name" )
         {
            $tmpName=$subChild;
        }
        else  if ($subChild->getName() =="value" )
        {
            if ($tmpName!="")
            {
               $arys["$tmpName"]=$subChild;
               $tmpName="";
            }
        }
        else
         {
            continue;
        }
      }
  }
  function byteReduce($bytes)
  {
      if ($bytes>1099511627776)
      {
          return round($bytes/1099511627776)."TB";
      }
      else if ($bytes > 1073741824)
      {
          return round($bytes/1073741824)."GB";
      }
      else if ($bytes>1048576)
      {
          return round($bytes/1048576)."MB";
      }
      else if ($bytes>1024)
      {
          return round($bytes/1024)."KB";
      }
      else
      {
          return $bytes."B";
      }
  }
  echo "client_conn: ".$arys["client_conn"] . "<br />";
  echo "client_req: ".$arys["client_req"] . "<br />";
  echo "cache_hit: ".$arys["cache_hit"] . "<br />";
  echo "cache_miss: ".$arys["cache_miss"] . "<br />";
  echo "Cache hit rate: ".round(($arys["cache_hit"]/$arys["client_req"])*100)." % <br/>";
  echo "LRU nuked objects: ".$arys[n_lru_nuked]."<br/>";
  echo " ".byteReduce($arys["s_bodybytes"]+$arys["s_hdrbytes"])." Acc Content (".byteReduce($arys["s_hdrbytes"])." header ".byteReduce($arys["s_bodybytes"])." Body)";
?>

效果如下:

ps:為了查看實(shí)時(shí)情況,可以在這監(jiān)控頁(yè)加個(gè)html定時(shí)刷新.
好了,這樣就方便我們隨時(shí)查看varnish的狀態(tài)了.

相關(guān)文章

最新評(píng)論