Using monit for server monitoring

Having trouble installing Group-Office? No worries. Help is on the way.

Moderator: Developers

peter_stirnberg
Posts: 263
Joined: Tue Dec 13, 2005 7:57 am

Using monit for server monitoring

Postby peter_stirnberg » Fri Apr 08, 2016 1:11 pm

We're using monit for monitoring our servers (see screenshot).
monit.png
monit.png (72.46 KiB) Viewed 9782 times

Here's how to install and configure:

#Install monit
------------
apt-get install monit
cp /etc/monit/monitrc /etc/monit/monitrc_orig
cat /dev/null > /etc/monit/monitrc

#Configure monit
---------------
nano /etc/monit/monitrc
set daemon 60
set logfile syslog facility log_daemon
set mailserver localhost
set mail-format { from: monit@server1.example.com }
set alert me@domain.example
set httpd port 2812 and
SSL ENABLE
PEMFILE /var/certs/monit.pem
allow admin:test #These are the credentials for accessing the webpage

#Configure processes (comment out or edit to your needs)
-------------------------------------------------
#proftpd
check process proftpd with pidfile /var/run/proftpd.pid
start program = "/etc/init.d/proftpd start"
stop program = "/etc/init.d/proftpd stop"
if failed port 21 protocol ftp then restart
if 5 restarts within 5 cycles then timeout

#ssh
check process sshd with pidfile /var/run/sshd.pid
start program "/etc/init.d/ssh start"
stop program "/etc/init.d/ssh stop"
if failed port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout

#mysql
check process mysql with pidfile /var/run/mysqld/mysqld.pid
group database
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if failed host 127.0.0.1 port 3306 then restart
if 5 restarts within 5 cycles then timeout

#apache2
group www
start program = "/etc/init.d/apache2 start"
stop program = "/etc/init.d/apache2 stop"
check process apache with pidfile /var/run/apache2/apache2.pid
if cpu > 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if totalmem > 200.0 MB for 5 cycles then restart
if children > 250 then restart
if loadavg(5min) greater than 10 for 8 cycles then stop
if failed host 127.0.0.1 port 80 protocol http
then restart

#postfix
check process postfix with pidfile /var/spool/postfix/pid/master.pid
group mail
start program = "/etc/init.d/postfix start"
stop program = "/etc/init.d/postfix stop"
if failed port 25 protocol smtp then restart
if 5 restarts within 5 cycles then timeout

#RAID
check device md2 with path /dev/md2
group system
if space usage > 85% then alert
if space usage > 85% then alert

#Securing monit
mkdir -p /var/www/www.example.com/web/monit
echo "hello" > /var/www/www.example.com/web/monit/token
mkdir /var/certs
cd /var/certs
openssl req -new -x509 -days 365 -nodes -out /var/certs/monit.pem -keyout /var/certs/monit.pem
openssl gendh 512 >> /var/certs/monit.pem
openssl x509 -subject -dates -fingerprint -noout -in /var/certs/monit.pem
chmod 700 /var/certs/monit.pem

#Defaults
/etc/default/monit
startup=1 od. YES
CHECK_INTERVALS=60

#Restart service
/etc/init.d/monit restart



More options and samples could be found on monit website -> https://mmonit.com/
Have fun!

Return to “Installation”

Who is online

Users browsing this forum: No registered users and 4 guests

cron