You can use Nginx access logs to monitor website performance and quickly identify exception issues. This topic describes common scenarios and examples of analyzing Nginx access logs.
Nginx is a widely used web server, and its logs are an essential source of information for operations and maintenance. You can upload Nginx access logs to TLS and use real-time query and analysis features to gain deeper insights into website performance, quickly detect and resolve issues, and improve user experience and service quality. For example:
- By analyzing client IP addresses, you can understand user distribution, identify where users are from, and optimize your site’s regional services.
- Analyzing request status codes helps you understand the proportion of each code, know website health, and detect and resolve potential issues promptly.
- By tracking page views (PV) and unique visitors (UV), you can assess website traffic and user activity, providing data to support marketing and operational decisions.
- Analyze access sources to identify the channel with the highest traffic, enabling you to optimize your marketing strategy.
- Analyze the response time of requests to quickly identify performance bottlenecks and optimize server performance.
- Calculate the number of queries the system processes per second (QPS) to assess server load and adjust resources as needed.
- An index has been created based on the log fields. For details, see Configure indexes.
The table below lists key fields in Nginx access log examples.
Index configuration example
This example creates the following index configuration based on the log example above. For specific operations and precautions related to index configuration, seeConfigure indexes. Typical query and analysis scenarios
Typical analysis scenarios for Nginx access logs mainly cover business monitoring, performance tuning, monitoring, and alarm.
Scenario 1 Count daily PV and UV
- Scenario: Count website PV, UV, and trend changes every 5 minutes within the past day.
- Query and analysis statement:
- Query and analysis results
- Use a line chart to show the website's PV, UV, and trends every 5 minutes during the past day. For more information, see Line chart.
-
- Scenario: Track the changes in QPS over the past day
- Query and analysis statement:
- Query and analysis results
- Display QPS trends over the past day using a line chart (enable time series mode) For more information, see Line chart.
-
Scenario 3 Analyze request method distribution
- Scenario: Calculate the distribution of request methods
- Query and analysis statement:
- Query and analysis results
- Display the distribution of request methods using a pie chart. For more information, see Pie chart.
-
Scenario 4 Calculate request failure rate
- Scenario: Calculate the overall request failure rate per minute, 404 error rate, 4xx error rate, and 5xx error rate.
- Query and analysis statement:
- Query and analysis results
- Display the overall failure rate, the failure rates of various errors, and their trends using a line chart. For more information, see Line chart.
Scenario 5 Count the Top 100 requested applications
- Scenario: Count the applications with the Top 100 request volumes and their corresponding request volumes, success rates, and QPS.
- Query and analysis statement:
- Query and analysis results
-
Scenario 6 Count the Top 10 request volumes
- Scenario: Count the Top 10 request volumes and their corresponding request pages.
- Query and analysis statement:
- Query and analysis results
-
Performance optimization
Analyze Nginx access logs to know request latency and identify website bottlenecks, helping optimize website performance.
Scenario 1: Calculate average and maximum latency.
- Scenario: Calculate the average and maximum request latency per hour over the past day.
- Query and analysis statement:
- Query and analysis results
- Use a line chart to show the hourly average and maximum request latency and trends for the past day. For more information, see Line chart.
-
Scenario 2: Calculate the maximum latency and its corresponding request page.
- Scenario: Calculate the maximum request latency per hour over the past day and identify the corresponding request page.
- Query and analysis statement:
- Query and analysis results
-
Scenario 3: Track the top 3 request times
- Scenario: Count the three longest request times from the past day.
- Query and analysis statement:
- Query and analysis results
-
Scenario 4: Query average request latency, P50 latency, and P99 latency
- Scenario: Query average request latency, P50 latency, and P99 latency.
- Query and analysis statement:
- Query and analysis results
- Display average latency, P50 latency, and P99 latency trends in a line chart. For more information, see Line chart.
-
Scenario 5: Histogram of request duration
- Scenario: Generate a histogram of request duration statistics.
- Query and analysis statement:
- Query and analysis results
-
Scenario 6: Page optimization
- Scenario: Optimize page performance by calculating metrics such as page visits (healthz page) PV and UV, the number of requests by method, the number of requests by status, the number of requests by browser, average latency, and maximum latency.
- Query and analysis statement:
- Query and analysis results
-
For request errors and other issues, you can monitor your website in real time through the alarm feature to quickly detect and handle exceptions.
Scenario 1: Request error alarm
- Scenario: Track hourly error counts and trigger alerts when errors occur.
- Query and analysis statement:
- Query and analysis results
-
- Alarm policy configuration:
Scenario 2: Request average latency alarm
- Scenario: Create an alarm based on the average request latency of the healthz page and monitor the basic latency of healthz page requests.
- Query and analysis statement:
- Query and analysis results
-
- Alarm policy configuration:
Scenario 3: Request latency P99 alarm
- Scenario: Using average latency does not effectively reflect requests with higher delays and can not show the website's true operating conditions. By creating alarms based on latency percentiles, such as P99 latency, you can quickly detect requests with relatively high delays.
- Query and analysis statement:
- Query and analysis results
-
- Alarm policy configuration: