Can't get Monit to work

Posted by Andrea on Server Fault See other posts from Server Fault or by Andrea
Published on 2012-06-04T16:00:18Z Indexed on 2012/06/04 16:45 UTC
Read the original article Hit count: 252

I am trying to configure Monit on my local machine to get a taste at how it works, but I have some issues.

What I am trying to do is to get any evidence that Monit is up and running correctly and is actually monitoring something. So my /etc/monit/monitrc looks like

set daemon  60
set logfile /var/log/monit.log
set idfile /var/lib/monit/id
set statefile /var/lib/monit/state
set eventqueue
    basedir /var/lib/monit/events
    slots 100
set httpd port 2812 and
    allow username:password

check process apache2 with pidfile /usr/local/apache/logs/apache2.pid
    start program = "/etc/init.d/apache2 start"
    stop program  = "/etc/init.d/apache2 stop"
    if failed port 6543 protocol http then exec "/usr/bin/touch /tmp/monit"

If I understand correctly, since apache does not listen on port 6543 (it is just a random number) I should get an error, and as a consequence the file /tmp/monit should be created. So I start monit by

sudo service monit start
sudo monit monitor apache2

Unfortunately no such file is created. Instead the web console shows an error for apache - execution failed. The log says 'apache2' failed to start.

What am I doing wrong?

EDIT As suggested in the comments, I ran monit in verbose mode, by

monit -vv monitor apache2

(the exact command suggested in the comments failed). The output is

Runtime constants:
 Control file       = /etc/monit/monitrc
 Log file           = /var/log/monit.log
 Pid file           = /var/run/monit.pid
 Debug              = True
 Log                = True
 Use syslog         = False
 Is Daemon          = True
 Use process engine = True
 Poll time          = 60 seconds with start delay 0 seconds
 Expect buffer      = 256 bytes
 Event queue        = base directory /var/lib/monit/events with 100 slots
 Mail from          = (not defined)
 Mail subject       = (not defined)
 Mail message       = (not defined)
 Start monit httpd  = True
 httpd bind address = Any/All
 httpd portnumber   = 2812
 httpd signature    = True
 Use ssl encryption = False
 httpd auth. style  = Basic Authentication

The service list contains the following entries:

Process Name          = apache2
 Pid file             = /usr/local/apache/logs/apache2.pid
 Monitoring mode      = active
 Start program        = '/etc/init.d/apache2 start' timeout 30 second(s)
 Stop program         = '/etc/init.d/apache2 stop' timeout 30 second(s)
 Existence            = if does not exist 1 times within 1 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert
 Pid                  = if changed 1 times within 1 cycle(s) then alert
 Ppid                 = if changed 1 times within 1 cycle(s) then alert
 Port                 = if failed localhost:6543 [HTTP via TCP] with timeout 5 seconds 1 times within 1 cycle(s) then exec '/usr/bin/touch /tmp/prova-monit' timeout 0 cycle(s) else if succeeded 1 times within 1 cycle(s) then alert

System Name           = system_andrea-Vostro-420-Series
 Monitoring mode      = active

© Server Fault or respective owner

Related posts about monitoring

Related posts about configuration