How does php monitor the varnish cache server status?
- $ 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;
- }
- Elseif ($ 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 )";
- ?>
Effect, such: Note: To view the real-time status, you can add an html refresh on the monitoring page and view the varnish cache server status at any time. |