Statistics on snginx logs to view nginx cache hit rate

Source: Internet
Author: User

Statistics on snginx logs to view nginx cache hit rate

To calculate the nginx cache, make sure that you have configured the nginx cache, and then output the cache status in the log, as shown in the following log format Configuration:

The last entry in the log is the cache status.

Log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request" ''$ status $ response" $ http_referer "'' "$ http_user_agent" "$ http_x_forwarded_for" ''" $ upstream_cache_status "';

Statistical Method: Calculate the cache HIT rate by dividing the number of HIT logs by the total number of logs:

Awk '{if ($ NF = "\" HIT \ "") hit ++} END {printf "%. 2f %", hit/NR}' access. log

The input percentage is similar to: 35.15%.

$ Upstream_cache_status contains the following statuses:

MISS missed, the request is sent to the backend
HIT cache HIT
An EXPIRED cache EXPIRED request is sent to the backend
UPDATING is UPDATING the cache. The old response will be used.
The STALE backend will receive an expired response.
BYPASS cache is bypassed
You can also modify the preceding script to calculate the percentage of other statuses based on these statuses.

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.