Skip to content
Juan Wajnerman edited this page Sep 3, 2014 · 1 revision

<<toc>>

Using Monit

Installation

Monit 5.3

Monit 5.3 allows you to monitor the exit status of a program which you can then use to check your VPN connection.

Ubuntu 11.10

Ubuntu 11.10 or earlier comes with an older version of Monit which does not have the functionality to monitor program statuses. To install Monit 5.3+ get it from the 12.04 sources

# wget http://mirror.pnl.gov/ubuntu//pool/universe/m/monit/monit_5.3.2-1_amd64.deb
# sudo dpkg -i monit_5.3.2-1_amd64.deb

Or to install the older version released with Ubuntu 11.10

# sudo apt-get install monit

Configuration

Edit the file at /etc/monit/monitrc

Set up email alerts using Gmail

  set mailserver smtp.gmail.com port 587
    username "[email protected]" password "password"
    using tlsv1
    with timeout 30 seconds

  set alert [email protected]                      # receive all alerts

Set up http web server over SSL

First create a certificate and key and open up port 2812 if required on EC2 EC2#!enable-ssl

Then copy the key and certificate into one file:

sudo cat /etc/ssl/certs/nuntium.pem /etc/ssl/private/nuntium.key > /etc/certs/nuntium_with_key.pem

Finally add the settings below to /etc/monit/monitrc:

 set httpd port 2812 and
      SSL ENABLE
      PEMFILE  /etc/ssl/certs/nuntium_with_key.pem
      allow admin:monit      # require user 'admin' with password 'monit'

Monitor Server Resources

  check system myhost.mydomain.tld
    if loadavg (1min) > 4 then alert
    if loadavg (5min) > 2 then alert
    if memory usage > 75% then alert
    if swap usage > 25% then alert
    if cpu usage (user) > 70% then alert
    if cpu usage (system) > 30% then alert
    if cpu usage (wait) > 20% then alert

Monitor Nuntium Services

Nuntium comes with a rake task to generate the monit config for the services you want to run

# cd <<nuntium_dir>>
# bundle exec rake monit:generate
# sudo mv nuntium /etc/monit/conf.d/

Monitor Mysql and Apache

See http://ghosttx.com/2012/03/how-to-install-monit-on-ubuntu-11-10-server-to-monitor-apache-web-server-mysql-ssh/ for more info

Mysql

Configure mysql to use a PID file by adding the following to /etc/mysql/my.conf under [mysqld]

pid-file = /var/run/mysqld/mysqld.pid

Restart mysql

# sudo restart mysql

Add the following to /etc/monit/conf.d/mysql:

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

Apache

Add the following to /etc/monit/conf.d/apache

check process apache2 with pidfile /var/run/apache2.pid
  start program = "/etc/init.d/apache2 start" with timeout 60 seconds
  stop program = "/etc/init.d/apache2 stop"
  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
  group webserver

Restart Monit

# sudo /etc/init.d/monit restart