How to Fix “Error Connecting to Monit Daemon” When Running monit status Command


6 views

When you encounter the message "error connecting to the monit daemon" after running monit status myproc, it typically indicates one of two scenarios:

  • The monit daemon isn't running at all
  • The HTTP interface isn't properly configured for CLI communication

First, check if the monit service is actually running:

sudo systemctl status monit
# or for older systems:
sudo service monit status

The crucial configuration needed in /etc/monit/monitrc:

set httpd port 2812 and
    use address 0.0.0.0  # or 127.0.0.1 for local only
    allow 0.0.0.0/0      # or restrict to specific IPs
    allow admin:monit    # basic authentication

Here's a full monitrc configuration that works with both CLI and HTTP:

# Global settings
set log /var/log/monit.log
set idfile /var/lib/monit/id
set statefile /var/lib/monit/state

# HTTP interface
set httpd port 2812
    use address 127.0.0.1
    allow 127.0.0.1
    allow admin:password

# Process monitoring example
check process nginx with pidfile /var/run/nginx.pid
    start program = "/etc/init.d/nginx start"
    stop program = "/etc/init.d/nginx stop"

After making changes, always:

sudo monit -t   # Test configuration
sudo systemctl restart monit
monit status    # Should now work

For systems where HTTP isn't desirable, configure UNIX socket:

set daemon 30 with start delay 5
set httpd unixsocket /var/run/monit.sock
    allow unix:root

Then use:

monit -s /var/run/monit.sock status
  • Check /var/log/monit.log for errors
  • Verify port 2812 isn't blocked by firewall: sudo ufw allow 2812
  • Ensure SELinux isn't blocking if applicable

When you encounter the "error connecting to the monit daemon" message while running monit status, it's typically because Monit's HTTP interface isn't configured. This behavior persists in modern Monit versions (5.25+), confirming that the 2005 observation remains accurate.

First check if HTTPD is enabled in your config file (usually at /etc/monit/monitrc):

# This should be present:
set httpd port 2812 and
    use address localhost
    allow localhost
    allow admin:monit

Here's a basic setup that enables both monitoring and HTTP access:

set daemon 30              # Check services every 30 seconds
set logfile /var/log/monit.log

set httpd port 2812
    use address 127.0.0.1
    allow 127.0.0.1
    allow admin:password

check process nginx with pidfile /var/run/nginx.pid
    start program = "/etc/init.d/nginx start"
    stop program = "/etc/init.d/nginx stop"

After modifying the configuration:

# Validate config syntax
monit -t

# Reload configuration
monit reload

# Now status checks should work
monit status nginx

If you can't enable HTTP, consider these approaches:

# 1. Use the summary flag
monit summary

# 2. Check the status file directly
cat /var/lib/monit/state

# 3. Use monit in non-daemon mode for testing
monit -Iv