Important: You are required to change your passwords used for Gentoo services and set an email address for your Wiki account if you haven't done so. See the full announcement and Wiki email policy change for more information.


From Gentoo Wiki
Jump to: navigation, search
This page contains changes which are not marked for translation.

External resources

app-admin/monit[1] is a utility for managing and monitoring processes, programs, files, directories and filesystems on a UNIX system.



→ Information about USE flags
USE flag Default Recommended Description
pam No Yes Adds support for PAM (Pluggable Authentication Modules) - DANGEROUS to arbitrarily flip
ssl No Yes Adds support for Secure Socket Layer connections


root # emerge --ask monit


Config file of monit resides in /etc/monitrc. And there is a item to specify a config directory. Uncomment if needed.

File/etc/monitrcconfig dir

## It is possible to include additional configuration parts from other files or
## directories.
#  include /etc/monit.d/*


Users added to the monit or users group will be able to manipulate monit through the web interface.

root # gpasswd -a $USER monit
root # gpasswd -a $USER users
passwords can be streamed to monits web interface, disable it all together after it is setup
for security purposes change this entry

allow admin:monit

Boot Services


File/etc/inittabauto restart monit in case of failure

ca:12345:ctrlaltdel:/sbin/shutdown -r now

 # Run monit in standard runlevels
 mo:2345:respawn:/usr/bin/monit -Ic /etc/monitrc

# Used by /etc/init.d/xdm to control DM startup.

to start monit immediately after changing inittab

root # telinit q


prefer inittab method over rc services

To start the service at boot.

root # rc-update add monit default

To start the service immediately.

root # /etc/init.d/monit start

Monitoring Monit

This hourly cron script will check to make sure monit has not crashed. As this uses pgrep, make sure to not name it monit.


if ! pgrep monit >/dev/null;then
rc-service monit restart

Pidfile Check

monit relies on the pidfile convention, it can only monitor background daemons. For daemons that do not create a pidfile, a trick is needed.

pidfile approach is intrinsically broken for monitforing process. Monit can overcome this by checking the pidfile frequently enough to be reliable, though.


Auto Restart Mysql

File/etc/monitrcauto restart mysql

check process mysql with pidfile /var/run/mysqld/
    start program = "/bin/bash -c 'rc-service mysql start'"
    stop program  = "/bin/bash -c 'rc-service mysql stop'"

Squid Memory Alert

net-proxy/squid is a caching proxy that is memory hungry. It can control its memory consumption by itself in the configuration file, while we can make an redundent check here.

File/etc/monitrccheck squid

 check process squid with pidfile /run/
   start program = "/bin/bash -c 'rc-service squid start'"
   stop  program = "/bin/bash -c 'rc-service squid stop'"
   if totalmem > 30 MB then alert

CLI Interface

We can run monit foreground and see the effect.

root # monit -Ivv
'squid' total mem amount of 30848kB matches resource limit [total mem amount>30720kB]

Web Interface

Navigate to http://localhost:2812/ & login using your edited configuration line or admin / monit if you have not changed it yet.