Php implements varnish cache server monitoring, and php monitors varnish cache _ PHP Tutorial

Source: Internet
Author: User
Tags varnish
Php monitors the status of the varnish cache server, and php monitors the varnish cache. Php monitors the status of the varnish cache server. php monitors the varnish cache when varnish and the website are deployed on the same server, it is impossible for us to log on to the server at any time to view the status of v php to monitor the varnish cache server, and php to monitor the varnish Cache

When varnish and the website are deployed on the same server, it is impossible for us to log on to the server at any time to check varnish's hit rate. I did not expect a great man to write it out. I will share it with you today, use the Web page to view the varnish hit rate.

System: centos 5.x
Software: varnish-3.0.x

Ps: For versions earlier than 3.0, you can connect to the Varnish management Port through Socket. you can use the stat command to check whether the stat command is available in versions later than 3.0. you can only use the following method to solve this problem.

The 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: To view the real-time status, you can add an html to regularly refresh the page.
Now, we can check the varnish status at any time.

When varnish and the website are deployed on the same server, it is impossible for us to log on to the server at any time to view v...

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.