Back to tutorials
Tutorial

Apache Performance Monitoring Tutorial (2026): Complete Server Metrics Setup with mod_status, Log Analysis, and Real-time Alerts

Learn Apache performance monitoring with mod_status, log analysis, and alert setup. Complete tutorial for VPS optimization in 2026.

By Anurag Singh
Updated on Jun 13, 2026
Category: Tutorial
Share article
Apache Performance Monitoring Tutorial (2026): Complete Server Metrics Setup with mod_status, Log Analysis, and Real-time Alerts

Understanding Apache Performance Metrics You Need to Track

Your Apache web server handles hundreds or thousands of requests daily. Without monitoring, performance issues creep in unnoticed until sites slow to a crawl.

This Apache performance monitoring tutorial shows you how to set up comprehensive metrics collection, log analysis, and automated alerts on your VPS.

Apache generates valuable performance data through multiple channels. The mod_status module provides real-time server statistics. Access logs reveal request patterns and response times.

Error logs highlight configuration issues and resource constraints. You'll configure monitoring tools that track key metrics: requests per second, memory usage, connection counts, and response times.

Plus automated alerts when thresholds breach normal ranges.

Enable mod_status for Real-time Apache Metrics

Apache's mod_status module displays live server statistics through a web interface. Most Ubuntu distributions include this module, but it requires explicit configuration.

First, verify the module is available:

sudo apache2ctl -M | grep status

If you see status_module listed, you're ready. Otherwise, enable it:

sudo a2enmod status
sudo systemctl restart apache2

Create a configuration file for the status interface:

sudo nano /etc/apache2/conf-available/status.conf

Add this configuration:

<Location "/server-status">
    SetHandler server-status
    Require local
    Require ip 192.168.1.0/24
</Location>

<Location "/server-info">
    SetHandler server-info
    Require local
    Require ip 192.168.1.0/24
</Location>

Replace the IP range with your actual network. For VPS hosting environments, restrict access to your management IP addresses only.

Enable the configuration and restart Apache:

sudo a2enconf status
sudo systemctl restart apache2

Access the status page at http://your-server-ip/server-status. You'll see current connections, request statistics, and worker process information.

Configure Apache Access Log Analysis

Apache access logs contain detailed request information. The default log format captures basic data.

Performance analysis needs enhanced logging with response times and connection details.

Edit your virtual host configuration:

sudo nano /etc/apache2/sites-available/your-site.conf

Add a custom log format within your virtual host block:

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/html
    
    LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\" %D %{X-Forwarded-For}i" combined_with_time
    CustomLog ${APACHE_LOG_DIR}/access.log combined_with_time
</VirtualHost>

The %D directive logs response time in microseconds. %O captures bytes sent including headers.

This enhanced format helps identify slow requests and bandwidth usage patterns. For sites running on WordPress hosting, this detailed logging reveals which pages consume most server resources.

Restart Apache to apply the new log format:

sudo systemctl restart apache2

Install and Configure GoAccess for Log Analysis

GoAccess provides real-time log analysis with web-based dashboards. It processes Apache logs and generates detailed statistics about visitor patterns, response times, and error rates.

Install GoAccess on Ubuntu:

sudo apt update
sudo apt install goaccess -y

Create a configuration file for Apache log parsing:

sudo nano /etc/goaccess.conf

Configure the log format to match your Apache logs:

time-format %H:%M:%S
date-format %d/%b/%Y
log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u" %D %^

Generate an initial HTML report:

sudo goaccess /var/log/apache2/access.log -o /var/www/html/stats.html --log-format=COMBINED

For continuous monitoring, run GoAccess in real-time mode:

sudo goaccess /var/log/apache2/access.log -o /var/www/html/stats.html --log-format=COMBINED --real-time-html --daemon

This creates a live dashboard that updates as new requests arrive. Protect the stats page with HTTP authentication or IP restrictions in your Apache configuration.

Set Up Automated Performance Alerts

Manual log checking catches issues too late. Automated monitoring alerts you to performance problems before users notice them.

Create a monitoring script that checks key Apache metrics:

sudo nano /usr/local/bin/apache-monitor.sh

Add this monitoring script:

#!/bin/bash

# Configuration
STATUS_URL="http://localhost/server-status?auto"
MAX_CONNECTIONS=80
MAX_CPU=75
ALERT_EMAIL="admin@yourdomain.com"
LOGFILE="/var/log/apache-monitor.log"

# Fetch status data
STATUS=$(curl -s $STATUS_URL)

if [ -z "$STATUS" ]; then
    echo "$(date): ERROR - Cannot fetch Apache status" >> $LOGFILE
    echo "Apache status check failed" | mail -s "Apache Alert" $ALERT_EMAIL
    exit 1
fi

# Extract metrics
CONNECTIONS=$(echo "$STATUS" | grep "BusyWorkers:" | awk '{print $2}')
CPU_LOAD=$(echo "$STATUS" | grep "CPULoad:" | awk '{print $2}' | cut -d'.' -f1)

# Check thresholds
if [ "$CONNECTIONS" -gt "$MAX_CONNECTIONS" ]; then
    echo "$(date): ALERT - High connections: $CONNECTIONS" >> $LOGFILE
    echo "Apache has $CONNECTIONS active connections (threshold: $MAX_CONNECTIONS)" | mail -s "High Apache Load" $ALERT_EMAIL
fi

if [ "$CPU_LOAD" -gt "$MAX_CPU" ]; then
    echo "$(date): ALERT - High CPU load: $CPU_LOAD%" >> $LOGFILE
    echo "Apache CPU load is $CPU_LOAD% (threshold: $MAX_CPU%)" | mail -s "High Apache CPU" $ALERT_EMAIL
fi

echo "$(date): OK - Connections: $CONNECTIONS, CPU: $CPU_LOAD%" >> $LOGFILE

Make the script executable:

sudo chmod +x /usr/local/bin/apache-monitor.sh

Schedule regular monitoring checks with cron:

sudo crontab -e

Add this line to run checks every 5 minutes:

*/5 * * * * /usr/local/bin/apache-monitor.sh

Monitor Apache Error Logs for Issues

Error logs reveal configuration problems, resource exhaustion, and security threats. Set up automated scanning to catch critical issues quickly.

Create an error log monitoring script:

sudo nano /usr/local/bin/apache-error-monitor.sh
#!/bin/bash

ERROR_LOG="/var/log/apache2/error.log"
LAST_CHECK_FILE="/var/lib/apache-monitor/last-check"
ALERT_EMAIL="admin@yourdomain.com"

# Create state directory
sudo mkdir -p /var/lib/apache-monitor

# Get timestamp of last check
if [ -f "$LAST_CHECK_FILE" ]; then
    LAST_CHECK=$(cat $LAST_CHECK_FILE)
else
    LAST_CHECK=$(date -d "5 minutes ago" +%s)
fi

# Find new error entries
NEW_ERRORS=$(find $ERROR_LOG -newer $LAST_CHECK_FILE 2>/dev/null | xargs grep -i "error\|critical\|emergency" | wc -l)

if [ "$NEW_ERRORS" -gt 0 ]; then
    RECENT_ERRORS=$(tail -100 $ERROR_LOG | grep -i "error\|critical\|emergency")
    echo "Found $NEW_ERRORS new errors in Apache log:

$RECENT_ERRORS" | mail -s "Apache Error Alert" $ALERT_EMAIL
fi

# Update timestamp
echo $(date +%s) > $LAST_CHECK_FILE

Schedule error log monitoring every 10 minutes:

*/10 * * * * /usr/local/bin/apache-error-monitor.sh

Track Performance Trends with Long-term Metrics

Daily snapshots reveal performance trends over time. This historical data helps with capacity planning and identifying gradual performance degradation.

Create a daily metrics collection script:

sudo nano /usr/local/bin/apache-daily-stats.sh
#!/bin/bash

STATS_FILE="/var/log/apache-daily-stats.csv"
DATE=$(date +%Y-%m-%d)
ACCESS_LOG="/var/log/apache2/access.log"

# Initialize CSV header if file doesn't exist
if [ ! -f "$STATS_FILE" ]; then
    echo "Date,Total_Requests,Avg_Response_Time,Error_Rate,Peak_Connections" > $STATS_FILE
fi

# Calculate daily statistics
TOTAL_REQUESTS=$(grep "$(date +%d/%b/%Y)" $ACCESS_LOG | wc -l)
AVG_RESPONSE_TIME=$(grep "$(date +%d/%b/%Y)" $ACCESS_LOG | awk '{sum+=$(NF-1)} END {if(NR>0) print int(sum/NR/1000)}' || echo 0)
ERROR_COUNT=$(grep "$(date +%d/%b/%Y)" $ACCESS_LOG | awk '$9 >= 400 {count++} END {print count+0}')
ERROR_RATE=$(echo "scale=2; $ERROR_COUNT * 100 / $TOTAL_REQUESTS" | bc -l 2>/dev/null || echo 0)

# Get peak connections from status log if available
PEAK_CONNECTIONS=$(grep "$(date +%Y-%m-%d)" /var/log/apache-monitor.log | grep "Connections:" | awk '{print $5}' | sed 's/,//' | sort -nr | head -1 || echo 0)

echo "$DATE,$TOTAL_REQUESTS,$AVG_RESPONSE_TIME,$ERROR_RATE,$PEAK_CONNECTIONS" >> $STATS_FILE

Schedule daily statistics collection at midnight:

0 0 * * * /usr/local/bin/apache-daily-stats.sh

Optimize Apache Configuration Based on Monitoring Data

Monitoring reveals bottlenecks in your Apache configuration. Common issues include insufficient worker processes, incorrect memory limits, and suboptimal caching settings.

Review your mpm_prefork or mpm_worker configuration based on connection patterns:

sudo nano /etc/apache2/mods-available/mpm_prefork.conf

Adjust worker limits based on your monitoring data:

<IfModule mpm_prefork_module>
    StartServers             8
    MinSpareServers          5
    MaxSpareServers         20
    ServerLimit            256
    MaxRequestWorkers      256
    MaxConnectionsPerChild   0
</IfModule>

If your monitoring shows consistently high connection counts, increase MaxRequestWorkers. For memory-constrained environments, lower this value to prevent swapping.

Monitor the impact of configuration changes by comparing before and after metrics. Performance data helps validate optimization decisions.

Ready to implement Apache performance monitoring on your server? HostMyCode VPS hosting provides the resources and flexibility you need for comprehensive monitoring setups. Our managed VPS hosting includes monitoring support to keep your Apache servers running smoothly.

Frequently Asked Questions

How often should I check Apache performance metrics?

Check critical metrics like connection counts and CPU usage every 5 minutes through automated scripts. Review daily trend reports weekly to identify gradual performance changes. Real-time monitoring through mod_status helps during troubleshooting sessions.

What Apache metrics indicate performance problems?

Watch for consistently high connection counts approaching MaxRequestWorkers, response times above 2-3 seconds, error rates exceeding 2%, and CPU usage staying above 80%. Memory usage climbing toward available RAM also signals potential issues requiring configuration adjustments.

Can Apache monitoring impact server performance?

Lightweight monitoring scripts checking every 5-10 minutes have minimal impact. Log analysis tools like GoAccess use more CPU when processing large files. Schedule intensive analysis during low-traffic periods and avoid running multiple analysis tools simultaneously.

How do I monitor Apache on shared hosting?

Shared hosting typically restricts access to Apache configuration and system monitoring. Focus on application-level monitoring through error logs available in your control panel. Consider upgrading to VPS hosting for comprehensive Apache performance monitoring capabilities.

What tools integrate well with Apache monitoring?

Nagios, Zabbix, and Prometheus integrate well with Apache monitoring through custom plugins and mod_status parsing. For simpler setups, combine GoAccess with shell scripts and email alerts. Log aggregation tools like ELK stack handle high-volume environments effectively.