hoangweb
7/15/2016 - 4:00 PM

monit-syntax

monit-syntax

#https://mmonit.com/monit/documentation/monit.html
#------------ check -------------------
# file/dir
check file <file-name> with path <path>
check directory <name> with path <path>

# process
check process nginx with pidfile /var/run/nginx.pid
# program
check program checkOracleDatabase with path /var/monit/programs/checkoracle.pl

#host
check host myhost with address 1.2.3.4

# ----------- condition -----------------
# if failed.. then ..
if failed host 127.0.0.1 port 80 then restart

# condition
is greater than
cpu is greater than 40%
cpu > 60%
cpu usage > 95%
cpu(user) > 75%
cpu(system) > 65%
cpu usage (user) > 70%
cpu usage (system) > 30%
cpu usage (wait) > 20%

inode usage > 90%
space usage > 90%

# POLL TIME
every 2 cycles
for 2 cycles
for 3 times
within 10 cycles
with 10 cycles
for 1 cycles
every "* 8-19 * * 1-5"  #every workday between 8AM to 7PM

# SERVICE RESTART LIMIT
10 restarts

host localhost
port 3306
protocol mysql|https

with # AND
not

timeout 15 seconds
unixsocket /var/run/mysqld/mysqld.sock

memory usage > 75%
memory > 85%
mem > 400.0 MB
totalmem > 100 Mb
children > 255
swap usage > 25%

loadavg (1min) > 4
loadavg (5min) > 2


# SERVICE GROUPS
group redis

# SERVICE DEPENDENCIES
depends on httpd

# then
then alert|restart|timeout

# -------------------------SERVICE METHODS -----------------------------
start program = "/usr/sbin/service redis-server start"
stop program = "/usr/sbin/service redis-server stop"
restart program = "service redis-server restart"

# also Monit will wait up to 60 seconds for the start/stop action to finish
start program = "/etc/init.d/foobar start" with timeout 60 seconds

# execute script
exec "/foo/bar"