How to Check Web Server Error Rate - 4xx and 5xx Errors on Linux Server

Step-by-step guide to check web server error rates for 4xx and 5xx HTTP status codes. Monitor error rates, detect issues, and ensure reliable web service delivery.

Last updated: 2026-01-11

How to Check Web Server Error Rate - 4xx and 5xx Errors on Linux Server

Monitor web server error rates to track 4xx (client errors) and 5xx (server errors), detect issues early, and ensure reliable web service delivery. This guide shows you how to check error rates and set up automated monitoring.

For comprehensive web server monitoring, see Application Performance Monitoring. For troubleshooting web server issues, see Nginx Apache 502 Bad Gateway Error.

Why Checking Error Rates Matters

Web server error rates indicate application health and user experience issues. High error rates can cause poor user experience, SEO penalties, and business impact. Monitoring error rates helps maintain reliable web services.

Method 1: Check Error Rates from Access Logs

Analyze Nginx Access Logs

# Count 4xx errors in last hour
tail -1000 /var/log/nginx/access.log | awk '$9 ~ /^4/ {count++} END {print "4xx errors:", count}'

# Count 5xx errors in last hour
tail -1000 /var/log/nginx/access.log | awk '$9 ~ /^5/ {count++} END {print "5xx errors:", count}'

# Calculate error rate percentage
TOTAL=$(tail -1000 /var/log/nginx/access.log | wc -l)
ERRORS=$(tail -1000 /var/log/nginx/access.log | awk '$9 ~ /^[45]/ {count++} END {print count}')
RATE=$(echo "scale=2; $ERRORS * 100 / $TOTAL" | bc)
echo "Error rate: $RATE%"

Analyze Apache Access Logs

# Count 4xx errors
tail -1000 /var/log/apache2/access.log | awk '$9 ~ /^4/ {count++} END {print "4xx errors:", count}'

# Count 5xx errors
tail -1000 /var/log/apache2/access.log | awk '$9 ~ /^5/ {count++} END {print "5xx errors:", count}'

# Calculate error rate
TOTAL=$(tail -1000 /var/log/apache2/access.log | wc -l)
ERRORS=$(tail -1000 /var/log/apache2/access.log | awk '$9 ~ /^[45]/ {count++} END {print count}')
RATE=$(echo "scale=2; $ERRORS * 100 / $TOTAL" | bc)
echo "Error rate: $RATE%"

Method 2: Monitor Error Rates in Real-Time

Track Error Rates Continuously

# Monitor error rates
while true; do
  TOTAL=$(tail -100 /var/log/nginx/access.log | wc -l)
  ERRORS=$(tail -100 /var/log/nginx/access.log | awk '$9 ~ /^[45]/ {count++} END {print count+0}')
  if [ "$TOTAL" -gt 0 ]; then
    RATE=$(echo "scale=2; $ERRORS * 100 / $TOTAL" | bc)
    echo "$(date): Error rate: $RATE% ($ERRORS/$TOTAL)"
  fi
  sleep 60
done

Method 3: Automated Error Rate Monitoring with Zuzia.app

Set up automated monitoring to track error rates continuously and receive alerts when error rates exceed thresholds.

Step 1: Add Error Rate Monitoring Command

  1. Log in to Zuzia.app Dashboard

    • Access your Zuzia.app account
    • Navigate to your server
    • Click "Add Scheduled Task"
  2. Configure Error Rate Check Command

    TOTAL=$(tail -1000 /var/log/nginx/access.log | wc -l)
    ERRORS=$(tail -1000 /var/log/nginx/access.log | awk '$9 ~ /^[45]/ {count++} END {print count+0}')
    if [ "$TOTAL" -gt 0 ]; then
      echo "scale=2; $ERRORS * 100 / $TOTAL" | bc
    else
      echo "0"
    fi
    
    • Set execution frequency (every 5-10 minutes)
    • Configure alerts when error rate exceeds thresholds

Step 2: Configure Alert Thresholds

  • Warning: Error rate > 1%
  • Critical: Error rate > 5%
  • Emergency: Error rate > 10%

Step 3: Monitor Specific Error Types

Add commands to monitor specific error codes:

# Count 502 errors
tail -1000 /var/log/nginx/access.log | awk '$9 == 502 {count++} END {print count+0}'

# Count 404 errors
tail -1000 /var/log/nginx/access.log | awk '$9 == 404 {count++} END {print count+0}'

Best Practices for Error Rate Monitoring

1. Monitor Error Rates Continuously

  • Track error rates regularly
  • Alert when error rates exceed thresholds
  • Monitor error rate trends over time
  • Optimize based on data

2. Distinguish Between Error Types

  • Monitor 4xx errors separately from 5xx errors
  • Track specific error codes (404, 500, 502)
  • Investigate root causes of different error types
  • Optimize based on error patterns

3. Set Appropriate Thresholds

  • Set thresholds based on application requirements
  • Adjust thresholds for different endpoints
  • Monitor error rate percentiles
  • Alert on error rate spikes

4. Correlate Errors with Other Metrics

  • Compare error rates with server resources
  • Correlate with application performance
  • Monitor errors during peak traffic
  • Identify error patterns

Troubleshooting High Error Rates

Step 1: Identify Error Causes

When error rates are high:

# Check recent errors
tail -100 /var/log/nginx/access.log | awk '$9 ~ /^[45]/'

# Count errors by type
tail -1000 /var/log/nginx/access.log | awk '{print $9}' | sort | uniq -c | sort -rn

# Check error logs
tail -50 /var/log/nginx/error.log

Step 2: Resolve Error Issues

Based on investigation:

  1. Fix Server Errors (5xx):

    • Review application logs
    • Fix application bugs
    • Optimize server configuration
  2. Fix Client Errors (4xx):

    • Review application routing
    • Fix broken links
    • Optimize application configuration
  3. Optimize Error Handling:

    • Improve error messages
    • Implement proper error handling
    • Update application code

FAQ: Common Questions About Error Rate Monitoring

What is considered high error rate?

High error rate depends on your application. Generally, error rates under 0.1% are excellent, 0.1-1% are acceptable, 1-5% require attention, and over 5% are critical. Set thresholds based on your requirements.

How often should I check error rates?

For production web servers, continuous automated monitoring is essential. Zuzia.app can check error rates every few minutes, storing historical data and alerting you when error rates exceed thresholds.

How do I distinguish between 4xx and 5xx errors?

4xx errors are client errors (bad requests, not found), while 5xx errors are server errors (internal server error, bad gateway). Monitor both separately and investigate root causes differently.

Can error rate monitoring impact server performance?

Error rate monitoring commands have minimal impact on server performance when done correctly. Use appropriate monitoring frequency and avoid monitoring during peak traffic periods.

Note: The content above is part of our brainstorming and planning process. Not all described features are yet available in the current version of Zuzia.

If you'd like to achieve what's described in this article, please contact us – we'd be happy to work on it and tailor the solution to your needs.

In the meantime, we invite you to try out Zuzia's current features – server monitoring, SSL checks, task management, and many more.

We use cookies to ensure the proper functioning of our website.