PHP implementation monitors the status of varnish cache servers
This article mainly introduces the PHP implementation monitoring Varnish cache server Status, varnish is a high-performance open-source HTTP accelerator, can replace squid, nginx and other servers, the need for friends can refer to the next
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.
The code is as follows:
$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/975881.html www.bkjia.com true http://www.bkjia.com/PHPjc/975881.html techarticle PHP Implementation Monitoring Varnish Cache server Status This article mainly introduces the implementation of PHP monitoring varnish cache Server Status, varnish is a high-performance open-source HTTP accelerator, can replace ...