亚洲免费乱码视频,日韩 欧美 国产 动漫 一区,97在线观看免费视频播国产,中文字幕亚洲图片

      1. <legend id="ppnor"></legend>

      2. 
        
        <sup id="ppnor"><input id="ppnor"></input></sup>
        <s id="ppnor"></s>

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

        字號:


            這篇文章主要介紹了php實(shí)現(xiàn)監(jiān)控varnish緩存服務(wù)器的狀態(tài),Varnish是一款高性能的開源HTTP加速器,可以替代Squid、Nginx等服務(wù)器,需要的朋友可以參考下
            當(dāng)varnish和網(wǎng)站部署在同一臺服務(wù)器上的時候,我們不可能隨時登錄上服務(wù)器去查看varnish的命中率,沒想到有大神早就寫了出來,今天就分享給大家,使用網(wǎng)頁查看varnish命中率。
            系統(tǒng):centos 5.x
            軟件:varnish-3.0.x
            ps:3.0以下的版本可以通過Socket連接到Varnish管理端口,通過stat命令查看,3.0以上沒有stat命令,只能通過下面的方法解決。
            代碼如下:
            <?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í)時情況,可以在這監(jiān)控頁加個html定時刷新.
            好了,這樣就方便我們隨時查看varnish的狀態(tài)了.