Home > computers > linux > monit | About

Monit monitors your processes or files and restart them or alert you if they're not responding the way they're supposed to.

To tell monit exactly what to do, you simply write a little script.

When monit is started, it reads your script and act accordingly.

For example, your script might say : try to get a webpage from http://my.web.app, if you fail 3 times in a row, then restart the web application with this command : /etc/init.d/my.web.app restart.

If you are a sysadmin, just put your script in /etc/monitrc

You can test your script with the -t option like this :

 $ monit -t
 Control file syntax OK
 $

The concept of cycles

Monit checks your services at every multiple of cycles. For example, if you define a cycle as 10 seconds, then the service or file will be monitored every 10 seconds if you specify 1 cycle, 20 seconds if you specify 2 cycles etc.

How to write a monit script ?

Each line must begin with the keyword check,

check

then you specify what to check : a host, a service, a process, a file, a directory… The full list is :

. Process
. File
. Fifo
. Filesystem
. Directory
. Host
. System
. Custom
. Network
check process

Next, you must give a unique name for that check. You can name it anything you want, for example

check process infomaniak

Then, each type of check has its own type of arguments. For the process check the next arguments are either PIDFILE or MATCHING. If you use PIDFILE you must then give the absolute path to the pidfile of the process you want to monitor, and if you use MATCHING you must give the name of the process (that would be grepped from the output of ps -ax for example).

CHECK PROCESS infomaniak PIDFILE /var/run/infomaniak.pid 

This is used to restart the program.

The most interesting part is of course tests.

Tests

Too many tests available, read them all over at monit's documentation site, Service Tests section

CHECK PROCESS infomaniak PIDFILE /var/run/infomaniak.pid
    restart = /etc/init.d/infomaniak restart
    IF FAILED http://audio-mon.eprs.dz 
      PORT 8000 
      PROTOCOL HTTP  
      TIMEOUT 300 
    THEN 
      ALERT

Launching Monit in daemon mode

Still in the configuration file, use the SET keyword.

SET DAEMON 60 seconds
SET INIT

This tells monit to set its polling cycle to 60 seconds and acknowledges it that it will be run from initd (/etc/init.d/monit), which is better than launching from the command line (because you then can run the service at boot time with rc.d)

Configuring the HTTP port for the monit web interface

SET HTTPD PORT 8001 ALLOW user:pass

You must put an ALLOW keyword, otherwise it won't work.

Sending alerts when something goes wrong

Use 'SET ALERT', either globally or by 'check' line

SET ALERT myemail@domain.tld

Use 'SET MAILSERVER' to configure how monit will send its mail

 SET MAILSERVER 10.10.10.19 USERNAME user PASSWORD pass

contact : @ychaouche yacinechaouche at yahoocom


QR Code
QR Code The concept of cycles (generated for current page)