PHP Implementation Monitoring Varnish cache server Status, PHP monitoring varnish cache _php Tutorial

Source: Internet
Author: User
Tags varnish

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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.