How does php monitor the varnish cache server status?

Source: Internet
Author: User
Tags varnish
How does php monitor the varnish cache server status?

  1. $ Outfile = shell_exec ("/usr/bin/varnishstat-x ");
  2. $ Xml = simplexml_load_string ($ outfile );
  3. Echo $ xml-> getName ()."
    ";
  4. Foreach ($ xml-> children () as $ child)
  5. {
  6. // $ TmpName = "";
  7. Foreach ($ child-> children () as $ subChild)
  8. {
  9. If ($ subChild-> getName () = "name ")
  10. {
  11. $ TmpName = $ subChild;
  12. }
  13. Elseif ($ subChild-> getName () = "value ")
  14. {
  15. If ($ tmpName! = "")
  16. {
  17. $ Arys ["$ tmpName"] = $ subChild;
  18. $ TmpName = "";
  19. }
  20. }
  21. Else
  22. {
  23. Continue;
  24. }
  25. }
  26. }
  27. Function byteReduce ($ bytes)
  28. {
  29. If ($ bytes> 1099511627776)
  30. {
  31. Return round ($ bytes/1099511627776). "TB ";
  32. }
  33. Else if ($ bytes> 1073741824)
  34. {
  35. Return round ($ bytes/1073741824). "GB ";
  36. }
  37. Else if ($ bytes> 1048576)
  38. {
  39. Return round ($ bytes/1048576). "MB ";
  40. }
  41. Else if ($ bytes> 1024)
  42. {
  43. Return round ($ bytes/1024). "KB ";
  44. }
  45. Else
  46. {
  47. Return $ bytes. "B ";
  48. }
  49. }
  50. Echo "client_conn:". $ arys ["client_conn"]."
    ";
  51. Echo "client_req:". $ arys ["client_req"]."
    ";
  52. Echo "cache_hit:". $ arys ["cache_hit"]."
    ";
  53. Echo "cache_miss:". $ arys ["cache_miss"]."
    ";
  54. Echo "Cache hit rate:". round ($ arys ["cache_hit"]/$ arys ["client_req"]) * 100). "%
    ";
  55. Echo "LRU nuked objects:". $ arys [n_lru_nuked]."
    ";
  56. Echo "". byteReduce ($ arys ["s_bodybytes"] + $ arys ["s_hdrbytes"]). "Acc Content (". byteReduce ($ arys ["s_hdrbytes"]). "header ". byteReduce ($ arys ["s_bodybytes"]). "Body )";
  57. ?>

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.

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.