monit检测语法

Posted pycode

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了monit检测语法相关的知识,希望对你有一定的参考价值。

1.存在性检测

    功能:检测文件或者服务不存在时进行相应的动作,默认是重启

    语法:

IF [DOES] NOT EXIST [[<X>] <Y> CYCLES]    THEN     action    [ELSE IF SUCCEEDED [[<X>] <Y> CYCLES] THEN action]

 

        action的相关动作:ALERT告警  、RESTART 重启 、START 启动、 STOP关闭、EXEC 执行命令、 UNMONITOR 不监控

    例子:

check process named with pidfile /var/run/named.pid

start program = “/etc/init.d/named start”

stop program  = “/etc/init.d/named stop”

if failed port 53 use type udp protocol dns then restart

if 3 restarts within 5 cycles then timeout

如果53的udp端口不通,就重启

 

 

2.资源检测

    功能:检测对象的指标是否达到某个值,然后进行相应的动作 

    语法:

IF  resource  operator value [[<X>] <Y> CYCLES]    THEN    action [ELSE IF SUCCEEDED [[<X>] <Y> CYCLES] THEN action]

 

        resource:就是监控的对象,如"CPU", "TOTALCPU", "CPU([user|system|wait])", "MEMORY", "SWAP", "CHILDREN", "TOTALMEMORY", "LOADAVG([1min|5min|15min])". 

        operator:逻辑判断符号,如 > ,=,< 等

        action的相关动作:ALERT告警  、RESTART 重启 、START 启动、 STOP关闭、EXEC 执行命令、 UNMONITOR 不监控

    例子:

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

 

 

3.文件校验码检测

        功能:检测文件是否发生变化   

        例子:

     

  check file apache_bin with path /usr/local/apache/bin/httpd
    if failed checksum and 
       expect the sum 8f7f419955cefa0b33a2ba316cba3659 then unmonitor
    if failed permission 755 then unmonitor
    if failed uid root then unmonitor
    if failed gid root then unmonitor
    alert [email protected] on {
           checksum, permission, uid, gid, unmonitor
        } with the mail-format { subject: Alarm! }
    group server

 

 

 

4。文件大小检测

check file with path /home/laicb/test.txt  
    if does not exist for 5 cycles then alert  
    if changed size for  1 cycles then alert //如果没有指定,查看服务所对应的会发现是for 5 times within 5cycles

 

 

5.UID GID检测

check file passwd with path /etc/passwd
       if failed uid root then unmonitor
check file shadow with path /etc/shadow
       if failed gid root then unmonitorv

 

6.pid文件检测,及运行时间检测

check process myapp with pidfile /var/run/myapp.pid
    start program = "/etc/init.d/myapp start"
    stop program = "/etc/init.d/myapp stop"
    if uptime > 3 days then restart

 

7。监控磁盘空间

check filesystem datafs with path /dev/sdb1
       group server
       start program  = "/bin/mount /data"
       stop program  =  "/bin/umount /data"
       if failed permission 660 then unmonitor
       if failed uid root then unmonitor
       if failed gid disk then unmonitor
       if space usage > 80 % then alert
       if space usage > 94 % then stop
       if inode usage > 80 % then alert
       if inode usage > 94 % then stop
       alert [email protected]

 

 

8.icmp检测

check host www.tildeslash.com with address www.tildeslash.com

if failed

icmp type echo count 5 with timeout 15 seconds

then alert

 



以上是关于monit检测语法的主要内容,如果未能解决你的问题,请参考以下文章

如何使用模块化代码片段中的LeakCanary检测内存泄漏?

在下面的代码片段中的剩余 ='passthrough' 处的代码中出现语法错误

Android:使用Tab检测单个片段viewpager

十条实用的jQuery代码片段

如何使用Monit部署服务器监控系统

深入理解多线程—— Moniter的实现原理