You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4.6 KiB

Alias Tag Date DocType Hierarchy TimeStamp location CollapseMetaTable
monit
💻
🖥️
🔎
2021-09-14 Personal NonRoot
51.514678599999996
-0.18378583926867909
true

Parent:: Selfhosting, Server Cloud, Server Alias, Server Tools, Server VPN


^Top

name Save
type command
action Save current file
id Save

^button-monitSave

Configuring monit

title: Summary
collapse: open
This note runs through [monit](https://mmonit.com), a free open-source tool to monitor running programs and deamons on a VPs.

style: number


Location

#^Top

title: Alias server
http://emailalias.mfxm.fr:2812
title: Cloud server
http://cloud.mfxm.fr:2812
title: Tools server
http://monit-tools.mfxm.fr
title: Cloud server
http://vpn.mfxm.fr:2812


Installation

#^Top

Program installation

The program is within the apt library:

~~~bash
sudo apt-get install monit
~~~

Once installed, it needs to be enabled:

~~~bash
sudo systemctl enable --now monit
~~~

Check that the service is running appropriately:

~~~bash
sudo systemctl status monit
~~~

Once set up, the next step is to enable the web interface.

Configuration of webportal

#^Top The following configuration file need to be amended:

/etc/monit/monitrc

By unchecking the following:

~~~bash
set httpd port 2812
     allow admin:monit
~~~

After making the change, monit needs to be restarted:

~~~bash
sudo systemctl restart monit
~~~

And the corresponding port opened:

~~~bash
sudo ufw allow 2812
~~~

Configuration of email alerts

#^Top The following configuration file need to be amended:

/etc/monit/monitrc

By unchecking the following:

~~~bash
set mailserver localhost
set mail-format { from: monit@(localhost)
set alert (dest email address)
~~~

After making the change, monit needs to be restarted:

~~~bash
sudo systemctl restart monit
~~~


Generic configuration

#^Top

Pre-loaded configurations

Monit has a number of pre-loaded configurations that can be accessed here:

~~~bash
ls -alh /etc/monit/conf-available
~~~

To enable some of the pre-loaded confs, command below:

~~~bash
sudo ln -s /etc/monit/conf-available/(process) /etc/monit/conf-enabled/
~~~

Creating custom configuration

#^Top Create a conf document in the following folder:

~~~bash
sudo touch /etc/monit/conf-available/(processname)
~~~

Edit the document with at least the below declarations:

~~~bash
check process (processname) matching "(processname)"
	start program = "(path to command)"
	stop program = "(path to command)"
~~~

Once done, enable the config:

~~~bash
sudo ln -s /etc/monit/conf-available/(process) /etc/monit/conf-enabled/
~~~

Docker container configuration

#^Top Docker containers can be set up as programs with the use of a script.

  1. Create a script for the docker container
~~~bash
sudo mkdir /etc/monit/scripts/
sudo touch /etc/monit/scripts/check_container_(container name).sh
sudo chmod 711 /etc/monit/scripts/check_container_(container name).sh
~~~
  1. Edit the script
~~~bash
#! /bin/bash
docker top "(container name)"
exit $?
~~~
  1. Create the configuration file
~~~bash
sudo touch/vi /etc/monit/conf-available/(container name)
~~~
  1. Edit the config file
~~~bash
CHECK PROGRAM (container name) WITH PATH /etc/monit/scripts/check\_container_(container name).sh
  START PROGRAM = "/usr/bin/docker start (container name)"
  STOP PROGRAM = "/usr/bin/docker stop (container name)"
  IF status != 0 FOR 3 CYCLES THEN RESTART
  IF 2 RESTARTS WITHIN 5 CYCLES THEN UNMONITOR
~~~
  1. Enable the config
~~~bash
sudo ln -s /etc/monit/conf-available/(container name) /etc/monit/conf-enabled/
~~~

Validate configuration

#^Top Once configuration is updated, monit provides a tool to check the script:

~~~bash
sudo monit -t
~~~

The program needs to be restarted:

~~~bash
sudo monit reload
~~~


Basic commands

Print monit activity

~~~bash
sudo monit summary
~~~

#^Top