###############################################################################
## Monit controlfile###############################################################################
##
## Comments begin with a'#'and extend through the end of the line. Keywords
## arecase insensitive. All path's MUST BE FULLY QUALIFIED, starting with'/'.
##
## Below you willfindexamples of some frequently used statements. For
## information about the controlfileand a complete list of statements and
## options, please have a lookinthe Monit manual.
##
##
###############################################################################
## Global section
###############################################################################
##
## Start Monitinthe background (run as a daemon):
#
# 设置检测周期30s
set daemon30 # check services at 30seconds intervals
# with start delay240 # optional: delay the first check by 4-minutes (by
# # default Monit check immediately after Monit start)
#
#
## Set syslog logging. If you want to log to a standalone logfileinstead,
## specify the full path to the logfile#
#设置log路径,这里默认记录到syslog
set logfile syslog
#
#
## Set the location of the Monit lockfile which stores the process idof the
## running Monit instance. By default thisfile is stored in $HOME/.monit.pid
#
# set pidfile/var/run/monit.pid
#
## Set the location of the Monitid file which stores the unique id forthe
## Monit instance. Theidis generated and stored on first Monit start. By
## default thefile is placed in $HOME/.monit.id.
#
# set idfile/var/.monit.id#
## Set the location of the Monit statefile whichsaves monitoring states
## on each cycle. By default thefile is placed in $HOME/.monit.state. If
## the statefileis stored on a persistent filesystem, Monit will recover
## the monitoring state across reboots. If it is on temporary filesystem, the
## state will be lost on rebootwhich may be convenient insome situations.
#
# set statefile/var/.monit.state
#
## Set the list of mail serversforalert delivery. Multiple servers may be
## specified using a comma separator. If the first mail server fails, Monit
# will use the second mail serverinthe list and so on. By default Monit uses
# port25 -it is possible to override this with the PORT option.
#
# set mailserver mail.bar.baz, # primary mailserver
# backup.bar.baz port10025, # backup mailserver on port 10025# localhost # fallback relay
#
# 设置邮件服务器用来发送邮件告警通知
set mailserver mail.abcd.so
#
## By default Monit will drop alert eventsifno mail servers are available.
## If you want to keep the alertsforlater delivery retry, you can use the
## EVENTQUEUE statement. The base directory where undelivered alerts will be
## stored is specified by the BASEDIR option. You can limit the queue size
## by using the SLOTS option (ifomitted, the queue is limited by space
## availableinthe back end filesystem).
#
# set eventqueue
# basedir/var/monit # set the base directory where events will be stored
# slots100# optionally limit the queue size
#
#
## Send status and events to M/Monit (for more informations about M/Monit
## see http://mmonit.com/). By default Monit registers credentials with
## M/Monit so M/Monit can smoothly communicate back to Monit and you don't
## have to register Monit credentials manually in M/Monit. It is possible to
## disable credential registration using the commented out option below.
## Though,ifsafety is a concern we recommend instead using https when
## communicating with M/Monit and send credentials encrypted.
#
# set mmonit http://monit:monit@192.168.1.10:8080/collector
# # and register without credentials # Don't register credentials
#
#
## Monit by default uses the following formatfor alerts if the the mail-format
## statement is missing::
##--8
# 设置邮件告警通知格式
set mail-format {
from: monit@$HOST
subject: monit alert--$EVENT $SERVICE
message: $EVENT Service $SERVICE
Date: $DATE
Action: $ACTION
Host: $HOST
Description: $DESCRIPTION
Your faithful employee,
Monit
}
##--8
## You can override this message format or parts of it, such as subject
## or sender using the MAIL-FORMAT statement. Macros such as $DATE, etc.
## are expanded at runtime. For example, to override the sender, use:
#
# set mail-format { from: monit@foo.bar }
#
#
## You can set alert recipients whom will receive alertsif/when a
## service definedin this filehas errors. Alerts may be restricted on
## events by using a filter asinthe second example below.
#
# 设置邮件告警通知人,Monit默认会通知monit进程本身的变化情况,如果不想收到monit进程自身的通知,加上but not on {instance}配置
set alert weian@abcd.so but not on { instance } # receive all alerts
#
## Do not alert when Monit starts, stops or performs a user initiated action.
## This filter is recommended to avoid getting alertsfortrivial cases.
#
# set alert weian@abcd.so
#
#
## Monit has an embedded HTTP interfacewhichcan be used to view status of
## services monitored and manage services from a web interface. The HTTP
## interface is also requiredifyou want to issue Monit commands from the
## command line, such as'monit status' or 'monit restart service'The reason
##forthis is that the Monit client uses the HTTP interface to send these
## commands to a running Monit daemon. See the Monit Wikiifyou want to
## enable SSLforthe HTTP interface.
#
# 设置UI界面访问信息
set httpd port2812and
use address10.2.2.28# only accept connection from localhost
# allow localhost # allow localhost to connect to the server and
allow admin:monit # require user'admin' with password 'monit'###############################################################################
## Services
###############################################################################
##
## Check general system resources such as load average, cpu and memory
## usage. Each test specifies a resource, conditions and the action to be
## performed should a test fail.
#
# check system $HOST
#if loadavg (1min) > 4 thenalert
#if loadavg (5min) > 2 thenalert
#if cpu usage > 95% for 10 cycles thenalert
#if memory usage > 75% thenalert
#if swap usage > 25% thenalert
#
#
## Checkif a fileexists, checksum, permissions, uid and gid. In addition
## to alert recipientsinthe global section, customized alert can be sent to
## additional recipients by specifying a local alert handler. The service may
## be grouped using the GROUP option. More than one group can be specified by
## repeating the'group name'statement.
#
# checkfile apache_bin with path /usr/local/apache/bin/httpd
#iffailed checksum and
# expect thesum 8f7f419955cefa0b33a2ba316cba3659 thenunmonitor
#if failed permission 755 thenunmonitor
#if failed uid root thenunmonitor
#if failed gid root thenunmonitor
# alert security@foo.bar on {
# checksum, permission, uid, gid, unmonitor
# } with the mail-format { subject: Alarm!}
# group server
#
#
## Check that a process is running,in this caseApache, and that it respond
## to HTTP and HTTPS requests. Check its resource usage such as cpu and memory,
## and number of children. If the process is not running, Monit will restart
## it by default. Incasethe service is restarted very often and the
## problem remains, it is possible to disable monitoring using the TIMEOUT
## statement. This service depends on another service (apache_bin)which## is defined above.
#
# check process apache with pidfile/usr/local/apache/logs/httpd.pid
# start program= "/etc/init.d/httpd start" with timeout 60seconds
# stop program= "/etc/init.d/httpd stop"#if cpu > 60% for 2 cycles thenalert
#if cpu > 80% for 5 cycles thenrestart
#if totalmem > 200.0 MB for 5 cycles thenrestart
#if children > 250 thenrestart
#if loadavg(5min) greater than 10 for 8 cycles thenstop
#if failed host www.tildeslash.com port 80protocol http
# and request"/somefile.html"#thenrestart
#if failed port 443type tcpssl protocol http
# with timeout15seconds
#thenrestart
#if 3 restarts within 5 cycles thenunmonitor
# depends on apache_bin
# group server#
# 监控进程可以通过上面监控pid文件的方式,当没有pid文件时,可以通过MATCHING正则表达式来匹配进程。
# 测试一个进程是否匹配来自命令行使用的模式monit procmatch "regex-pattern",这将列出匹配或不匹配的所有进程,regex模式。
# 我们这里监控了包含shop-pad-server字段的进程,并指明了启动以及停止的命令,这样在进程因故断掉后,Monit会自动重启进程。
# 同时若进程ID变动,会发送邮件通知到之前指定的收件人。