Monit

Monit, not to be confused to M/Monit, is an AGPL3.0 licensed system and process monitoring tool. Monit can automatically restart crashed services, display temperatures from standard hardware (through lm_sensors and hard drives from smartmontools for example). Service alerts can be sent based on a wide criteria including a single occurrence or occurrences over a period of time. It can be accessed directly through the command line or ran as a web app using its integrated HTTP(S) server. This allows quick and streamlined snapshot of a given systems status.

Installation

Install the monit package and any software for optional testing such as lm_sensors or smartmontools. Once you have completed the configuration, be sure to enable and start monit.service.

Configuration

Monit keeps a main configuration file as /etc/monitrc. You can choose to edit this file but if you wish to run scripts (such as to get hard drive temperatures or health status) you should uncomment the last directive of include /etc/monit.d/*, save /etc/monitrc and create /etc/monit.d/.

Note: Monit requires the /etc/monitrc file (and potentially files stored in /etc/monit.d) to have 0700 permissions. Failure to comply will result in Monit failing to start.

Configuration syntax

Monit utilizes a configuration syntax that makes it very easy to read; essentially check WHAT followed by if THING condition THEN action format. Any occurrence of , and, , , , on(ly), , , in the configuration file is for human readability only and are completely ignored by Monit.

Checks are usually performed in cycles. This is defined at the beginning of the configuration file, for example a 30second poll is defined with:

Checks with would therefore happen every 2 minutes

Configuration examples

Filesystem(s) usage

check filesystem rootfs with path /
    if space usage > 90% then alert

check filesystem NFS with path /mnt/nfs_share
    if space usage > 90% then alert

Process monitoring

Note: For the above samba example, the first block has depends on smbd_bin, this makes the testing of Samba require the actual smbd process

Temperature

Create the file as well as the folder if necessary.

In this example, the script assumes your drive path is where is filled in by the letter at the end of the declaration. A similar method is used for the SMART health status in the next example.

SMART health status

/etc/monit.d/scripts/hdhealth.sh
 #!/usr/bin/sh
 STATUS=`/usr/bin/smartctl -H /dev/sd${1} | grep overall-health | awk 'match($0,"result:"){print substr($0,RSTART+8,6)}'`
 if [ "$STATUS" = "PASSED" ] 
 then
     # 1 implies PASSED
     TP=1
 else 
     # 2 implies FAILED
     TP=2
 fi
 #echo $TP # for debug only
 exit $TP

Alert recipients: global or subsystem based

Alerts can be set globally, where a given user / email address is alerted for any condition; or you can set an alert recipient for each type of check (eg network alerts go to recipient A; process alerts go to recipient B). You can set as many global or subsystem recipients as you like, just make multiple declarations.

Global alerts

Global alerts are set outside of any subsystem checks; for ease of reading they should be set in the same location as the mailserver declaration.

SET ALERT email@domain

Subsystem alerts

Subsystem alerts are set very similarly to global alerts except they lack the flag.

ALERT email@domain
gollark: Insufficient potatos.
gollark: Hιͺ.
gollark: What did you δο?!
gollark: I κnεw this would happen from the start.
gollark: ~30 minutes from project "start" to abandonment.

See also

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.