PHP Implementation Monitoring Varnish cache server Status, PHP monitoring varnish cache
When varnish and website deployed on the same server, we can not log on to the server at any time to see varnish hit rate, did not expect the Great God has written out, today to share to everyone, use the Web page to view varnish hit rate.
System: CentOS 5.x
Software: varnish-3.0.x
ps:3.0 The following version can be connected to the varnish management port through the socket, through the Stat command to view, more than 3.0 No stat command, can only be resolved by the following method.
Copy CodeThe code is as follows:
<?php
$outfile =shell_exec ("/usr/bin/varnishstat-x");
$xml =simplexml_load_string ($outfile);
echo $xml->getname (). "
";
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"]. "
";
echo "Client_req:". $arys ["Client_req"]. "
";
echo "Cache_hit:". $arys ["Cache_hit"]. "
";
echo "Cache_miss:". $arys ["Cache_miss"]. "
";
echo "Cache hit rate:". Round (($arys ["Cache_hit"]/$arys ["Client_req]") *100). "%
";
echo "LRU nuked objects:". $arys [n_lru_nuked]. "
";
echo "". Bytereduce ($arys ["S_bodybytes"]+ $arys ["S_hdrbytes"]). " ACC Content (". Bytereduce ($arys [" s_hdrbytes "])." Header ". Bytereduce ($arys [" s_bodybytes "])." Body) ";
?>
The effect is as follows:
PS: In order to see the real-time situation, you can add an HTML timed refresh on this monitoring page.
OK, so it's convenient for us to check the status of varnish at any time.
http://www.bkjia.com/PHPjc/935486.html www.bkjia.com true http://www.bkjia.com/PHPjc/935486.html techarticle PHP Implementation Monitoring varnish cache server Status, PHP monitoring varnish cache when varnish and website are deployed on the same server, we cannot log on to the server at any time to view v ...