Troubleshooting Apache “Not Monitored” Status in Monit: PID Verification and HTTP Checks


2 views

When Monit reports Apache as "Not Monitored" despite correct configuration, we're typically dealing with one of these fundamental issues:

  1. PID file path mismatch or permission issues
  2. HTTP status check failures
  3. Configuration syntax errors
  4. Monitoring mode conflicts

First let's confirm the PID file location and content matches running processes:

# Cross-verify PID file location
ls -la /var/run/httpd.pid

# Check process using the PID
cat /var/run/httpd.pid | xargs ps -p

# Alternative process check
pgrep -lf httpd

Common issues here include:

  • PID file not being updated by Apache
  • Permission denied errors (Monit typically runs as root)
  • Custom Apache builds using different PID paths

Here's an improved configuration that adds more robust checks:

check process apache with pidfile /var/run/httpd.pid
    group www
    start program = "/etc/init.d/httpd start" with timeout 60 seconds
    stop program = "/etc/init.d/httpd stop" with timeout 60 seconds
    if failed 
        host localhost 
        port 80
        protocol http
        request "/server-status?auto"
        status = 200
        content = "ServerUptime"
    then restart
    if cpu > 80% for 2 cycles then alert
    if memory > 500 MB for 5 cycles then restart
    if 5 restarts within 5 cycles then timeout

Test the HTTP check manually:

curl -I http://localhost/server-status?auto
telnet localhost 80
monit procmatch apache

Enable debug logging in Monit:

monit -vv

Check system logs for related messages:

grep -iE 'monit|httpd' /var/log/{messages,syslog}

For systems using systemd:

check process apache matching "^/usr/sbin/httpd"
    start program = "/bin/systemctl start httpd"
    stop program = "/bin/systemctl stop httpd"

For cases where Apache uses multiple worker processes:

check process apache with pidfile /var/run/httpd.pid
    matching "httpd"

When Monit reports Apache as "Not Monitored" despite correct configuration, it typically indicates one of these scenarios:

  • The PID file path doesn't match Apache's actual process
  • Permission issues preventing Monit from accessing the PID file
  • Missing or incorrect protocol specifications
  • Process pattern matching failures

First verify Apache's actual PID location:

ps -ef | grep httpd
cat /proc/$(pgrep httpd | head -1)/status | grep PPid

Check Monit's error logs for specific failure reasons:

grep -i apache /var/log/monit.log
monit status apache -v

Here's an enhanced configuration that handles most edge cases:

check process apache with pidfile /var/run/httpd/httpd.pid
    group www
    start program = "/bin/systemctl start httpd" with timeout 30 seconds
    stop program = "/bin/systemctl stop httpd" with timeout 30 seconds
    if failed 
        host 127.0.0.1 
        port 80 
        protocol http
        request "/server-status?auto"
        status = 200
        timeout 15 seconds
    then restart
    if cpu > 80% for 2 cycles then alert
    if memory usage > 85% for 5 cycles then restart
    if 5 restarts within 5 cycles then timeout

For SELinux environments:

semanage fcontext -a -t monit_var_run_t '/var/run/httpd(/.*)?'
restorecon -Rv /var/run/httpd

For PID file location issues:

mkdir -p /var/run/httpd
chown apache:apache /var/run/httpd
echo "PIDFile /var/run/httpd/httpd.pid" >> /etc/httpd/conf/httpd.conf

Enable mod_status in Apache:

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

Then enhance Monit's check with:

if failed 
    url http://localhost/server-status?auto
    content = "Scoreboard: [SRWKDCLGI_ .]+"
then alert