get monit
sudo apt-get install monit
monit configuration is in ~/.monitrc
You can think of monit as a wrapper around init.d
, so you give monit your daemons you want to wrap and you tell monit how to start and stop them, from then on you can use monit to start and stop these services.
monit start mydaemon
where the name mydaemon is set in your monitrc file (example using celery shown below)
set daemon 10
set alert [email protected] {resource}
check process celery with pidfile /var/run/celery.pid
start program = "/etc/init.d/celeryd start"
stop program = "/etc/init.d/celeryd stop"
if total memory > 1000.0 MB for 5 cycles then alert
if total memory > 1500.0 MB for 5 cycles then alert
if total memory > 2000.0 MB for 5 cycles then restart
- tell monit to go into Daemon mode and wake up every
n
seconds, in the conf set to 10 seconds. This is the monitcycle
that is used elsewhere in the config. Change the time if the resource deltas in the process being monitored are much lower or higher frequency. - Set an email alert for email address [email protected], (obviously put your own in there), for the alert types 'resource'.
- The next chunk is where we monitor our first process, celery. We define the alias
celery
which is linked to the process found at pidfile/var/run/celery.pid
you will need to make sure celery uses this pidfile, or some other pidfile you can link with monit (doesn't matter the location so long as they match), see how to set a pidfile using celery here
First make sure we got the monitrc right by running a quick self test
monit -t
You should get something telling you everything is OK
Then you start monit with a simple
monit
and can start your process, and start monitoring it with
monit start celery
you can do things like
monit status