📜 ⬆️ ⬇️

MonIT + M \ MonIT = simple and free monitoring of several servers

There was a task to monitor several servers located in different DCs with different operating systems and software.

TZ turned out something like this:

  1. System monitoring (cpu, mem, load average, bandwidth).
  2. Monitoring the status of services (running or not).
  3. Monitoring the operation of the service (responds to requests correctly or not).
  4. Control of resources consumed by services and their general condition.
  5. Centralized "admin" for all this joy.
  6. Email notification, self-correction of a problem (for example, restarting a fallen service).

')


Search for a solution.


In the process of studying possible options, 5 options were found:



The first and third options were discarded as too complex to set up and having obviously unnecessary (albeit huge) functionality. The second is dropped due to the enchanting ($ 995) price and server requirements with MS Windows. In the end, I decided to stop at Monit.

What is Monit?



Monit is a free open source application that provides comprehensive monitoring of UNIX-like systems, such as:



The main advantages of the program are low consumption of resources, ease of configuration (setting 15-20 minutes) and open source.

Supported operating systems are GNU \ Linux (available on most batch systems), FreeBSD (available in ports), OpenBSD, Solaris, MacOS X. Windows is NOT supported as a server, but it doesn’t interfere with monitoring network services located on a remote windows machine.

Architectures - x86, x86_64, PowerPC (Mac only), Sparc (Sun only).

Installation and basic setup.



The package is available for most distributions (Gentoo, Debian, FreeBSD - mostly tree, CentOS, Fedora, RedHat - in the dag repository). The package is called monit .

The main configuration file is /etc/monit.conf (on Linux) or / usr / local / etc / monitrc (on FreeBSD). On FreeBSD, this file needs to be created:

# mv /usr/local/etc/monitrc.sample /usr/local/etc/monitrc

Then we need to uncomment the line in the configuration file:

include /etc/monit.d/*

Now all configuration files from /etc/monit.d/ will be automatically picked up by the monit.

I split my configuration into two files (for convenience) - main.conf (common settings) and master.conf (service monitoring settings).

main.conf


For those who are too lazy to read comments in English, I cite his example and the translation of a part of comments.

set daemon 120 # .
set logfile syslog facility log_daemon # syslogd facility.
set mailserver localhost, # IP\hostname , .
set eventqueue # .
basedir /var/log/monit # , .
slots 100 # .

set mail-format { from: main-servers-alert@example.com } # .
set alert admin@example.com # __ ().
set alert support@example.com { timeout } # ( \).

check system *CHANGEME.HOSTNAME.EXAMPLE.COM* # .
if loadavg (1min) > 6 then alert
if loadavg (5min) > 3 then alert
if memory usage > 75% then alert
if cpu usage (user) > 70% then alert
if cpu usage (system) > 30% then alert
if cpu usage (wait) > 20% then alert


As you can see, the config is extremely simple and straightforward.

master.conf


master.conf - in my case is responsible for monitoring specific demons.

Again, I give his example (blindly copy-paste _not_ need_). I show with the example of the Exim mailer , according to this logic, such a block is written for each daemon that needs to be monitored:

check process exim with pidfile /var/run/exim.pid # PID.
start program = "/etc/init.d/exim stop" # .
stop program = "/etc/init.d/exim start" # .
if cpu > 60% for 2 cycles then alert # CPU > 60% - .
if cpu > 80% for 5 cycles then restart # 5 80% - .
if totalmem > 300.0 MB for 5 cycles then restart # > 300 - .
if children > 50 then restart # 50 - .
if failed port 25 protocol smtp then restart # 25 SMTP - .
if 5 restarts within 5 cycles then timeout # - timeout.


M \ Monit



M \ Monit is a tool for centralized monitoring of servers under the control of monit .

The program itself is paid, but you can use it for free - the Free-version is posted on the site, albeit with certain restrictions.

Installation and basic setup.


We download the version for the OS and architecture, we unpack archive.

Install:

# mv mmonit-2.0.3 /usr/local/mmonit
# cd /usr/local/mmonit
# cp /usr/local/mmonit/doc/startup/mmonit_init /etc/init.d/mmonit


We create a MySQL database (PgSQL and SQLite are also supported), we bring in the contents:

# cat /usr/local/mmonit/db/mmonit-schema.mysql | mysql -u -p monit


/usr/local/mmonit/conf/server.xml . - XML. :

<Realm url="mysql://user:password@hostname/database"
minConnections="5"
maxConnections="250"
reapConnections="300" />


:

# /etc/init.d/mmonit start


- localhost :8080. admin, swordfish

.

monit m\monit

, main.conf :

set mmonit monit:monit@:8080/collector
set httpd port 2812 and use address allow localhost
allow allow monit:monit


.

. . , .
# cat /usr/local/mmonit/db/mmonit-schema.mysql | mysql -u -p monit


/usr/local/mmonit/conf/server.xml . - XML. :

<Realm url="mysql://user:password@hostname/database"
minConnections="5"
maxConnections="250"
reapConnections="300" />


:

# /etc/init.d/mmonit start


- localhost :8080. admin, swordfish

.

monit m\monit

, main.conf :

set mmonit monit:monit@:8080/collector
set httpd port 2812 and use address allow localhost
allow allow monit:monit


.

. . , .
# cat /usr/local/mmonit/db/mmonit-schema.mysql | mysql -u -p monit


/usr/local/mmonit/conf/server.xml . - XML. :

<Realm url="mysql://user:password@hostname/database"
minConnections="5"
maxConnections="250"
reapConnections="300" />


:

# /etc/init.d/mmonit start


- localhost :8080. admin, swordfish

.

monit m\monit

, main.conf :

set mmonit monit:monit@:8080/collector
set httpd port 2812 and use address allow localhost
allow allow monit:monit


.

. . , .

Source: https://habr.com/ru/post/60078/


All Articles