Created
October 4, 2016 21:59
-
-
Save ahmadawais/ab77d418eee76e3d9a2320369d900a10 to your computer and use it in GitHub Desktop.
DevOps: Custom Monit monitrc configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Monit with EasyEngine v3.7.4 | |
####.#### ———————————————————————————————————————————— Monit Configuration ———————————————————————————————————————————— ####.#### | |
set daemon 60 #check services every 60 seconds | |
set logfile /var/log/monit.log | |
set idfile /var/lib/monit/id | |
set statefile /var/lib/monit/state | |
####.#### ———————————————————————————————————————————— HTTP ———————————————————————————————————————————— ####.#### | |
set httpd port 2812 address 0.0.0.0 # allow port 2812 connections on all network adapters | |
ssl enable | |
pemfile /var/certs/monit.pem | |
allow 0.0.0.0/0.0.0.0 # allow all IPs, can use local subnet too | |
allow USER:"PASS" # require user wp with password bullet | |
# allow wp-domain.crabdance.com # allow dynamicdns address to connect | |
####.#### ———————————————————————————————————————————— Event Queue ———————————————————————————————————————————— ####.#### | |
set eventqueue | |
basedir /var/lib/monit/events # set the base directory where events will be stored | |
slots 100 # optionally limit the queue size | |
####.#### ———————————————————————————————————————————— MAIL ———————————————————————————————————————————— ####.#### | |
set mail-format { | |
from: monit@$HOST | |
subject: MONIT_ALERT [ $SERVICE — $EVENT ] | |
message: | |
——————————————————————— | |
| SERVICE: $SERVICE | |
| EVENT: $EVENT | |
| ACTION: $ACTION | |
——————————————————————— | |
——————————————————————— | |
| DESCRIPTION: $DESCRIPTION | |
——————————————————————— | |
——————————————————————— | |
| HOST: $HOST | |
| DATE: $DATE | |
——————————————————————— | |
The event —— $EVENT —— happend to the service —— $SERVICE —— on —— $DATE —— and now Monit has taken —— $ACTION —— action on the —— $HOST —— for you. | |
— Monit! | |
} | |
set mailserver smtp.gmail.com port 587 | |
username "gmail_user" password "gmail_pass" | |
using TLSV1 with timeout 30 seconds | |
# Email address which will receive monit alerts. | |
set alert gmail_user@gmail.com | |
####.#### ———————————————————————————————————————————— MySQL ———————————————————————————————————————————— ####.#### | |
check process MySQL with pidfile "/var/run/mysqld/mysqld.pid" | |
start program = "/usr/sbin/service mysql start" with timeout 60 seconds | |
stop program = "/usr/sbin/service mysql stop" | |
if failed unixsocket /var/run/mysqld/mysqld.sock then restart | |
if failed host 127.0.0.1 port 3306 protocol mysql then restart | |
if cpu > 80% for 2 cycles then alert | |
####.#### ———————————————————————————————————————————— PHP ———————————————————————————————————————————— ####.#### | |
check process PHP5.6FPM with pidfile "/var/run/php/php5.6-fpm.pid" | |
start program = "/usr/sbin/service php5.6-fpm start" with timeout 60 seconds | |
stop program = "/usr/sbin/service php5.6-fpm stop" | |
if cpu > 80% for 2 cycles then alert | |
if failed host 127.0.0.1 port 9000 then restart | |
if failed url https://127.0.0.1/wp-login.php | |
with timeout 30 seconds for 5 cycles then alert | |
####.#### ———————————————————————————————————————————— NGINX ———————————————————————————————————————————— ####.#### | |
check process NGINX with pidfile "/var/run/nginx.pid" | |
start program = "/usr/sbin/service nginx start" with timeout 60 seconds | |
stop program = "/usr/sbin/service nginx stop" | |
if cpu > 80% for 2 cycles then alert | |
if failed host 127.0.0.1 port 80 protocol http for 3 cycles then restart | |
if failed url https://127.0.0.1:80/wp-login.php | |
with timeout 30 seconds for 5 cycles then alert | |
####.#### ———————————————————————————————————————————— DISK SPACE ———————————————————————————————————————————— ####.#### | |
check device DISK_SPACE with path / | |
if SPACE usage > 80% then alert | |
####.#### ———————————————————————————————————————————— REDIS ———————————————————————————————————————————— ####.#### | |
check process REDIS matching "redis-server" | |
start program = "/usr/sbin/service redis-server start" with timeout 60 seconds | |
stop program = "/usr/sbin/service redis-server stop" | |
if failed host 127.0.0.1 port 6379 then restart | |
####.#### ———————————————————————————————————————————— SSHD ———————————————————————————————————————————— ####.#### | |
check process SSHD with pidfile "/var/run/sshd.pid" | |
start program "/usr/sbin/service ssh start" | |
stop program "/usr/sbin/service ssh stop" | |
if failed port 22 protocol ssh then restart | |
####.#### ———————————————————————————————————————————— SYSTEM ———————————————————————————————————————————— ####.#### | |
check system ANY_HOST_NAME | |
if memory usage > 80% for 2 cycles then alert | |
if cpu usage (user) > 70% for 2 cycles then alert | |
if cpu usage (system) > 30% then alert | |
if cpu usage (wait) > 20% then alert | |
if loadavg (1min) > 6 for 2 cycles then alert | |
if loadavg (5min) > 4 for 2 cycles then alert | |
if swap usage > 5% then alert | |
####.#### ———————————————————————————————————————————— MODULAR STRUCTURE ———————————————————————————————————————————— ####.#### | |
include /etc/monit/conf.d/* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment