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