侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

使用Monit监控本地进程

2023-12-02 星期六 / 0 评论 / 0 点赞 / 81 阅读 / 6502 字

目前用它监控某些服务,失败自动重启,同时监控特定的日志文件,如果有变化,就发邮件报警 安装不细写了,网上好多 我先用cat /proc/version看了下我的系统是el6的,于是wget htt

  目前用它监控某些服务,失败自动重启,同时监控特定的日志文件,如果有变化,就发邮件报警

  安装不细写了,网上好多

  我先用cat /proc/version看了下我的系统是el6的,于是wget http://pkgs.repoforge.org/monit/monit-5.5-1.el6.rf.x86_64.rpm

  启动什么的就不管了,直接上配置文件:

  

set daemon  10 set logfile /var/monit/monit.logset idfile /var/monit/idset statefile /var/monit/state  set mailserver smtp.xxxxxxxxx.com port 25 USERNAME "[email protected]" PASSWORD "xxxxxxxx"  set mail-format {          from: [email protected]          subject: monit alert --  $EVENT $SERVICE          message: $EVENT Service $SERVICE                Date:        $DATE                Action:      $ACTION                Host:        $HOST                Description: $DESCRIPTION    }  set alert [email protected] with reminder on 3 cyclesset httpd port 2812 and    use address 192.168.1.45    allow xxxxx:*****    allow @users readonlyinclude /etc/monit.d/*

两个例子:

check process nginx with pidfile /var/run/nginx/nginx.pidstart program = "/etc/init.d/nginx start"stop program = "/etc/init.d/nginx stop"if failed host localhost port 80 protocol httpthen restart

和文件变化的监控

check file test.log with path /tmp/test.logif changed size then alert

 ##########################################################

今天又测试了下监控目录变化:

从github上找了下代码,代码里的文档比官网上的细多了。。。。

check directory root with path /rootif changed timestamp then alertalert ****@******.com

然后干脆把rocket的监控也加上了

check host 192.168.1.45 with address 192.168.1.45#check system 192.168.1.45      # if failed icmp type echo count 1 with timeout 3 seconds then alert       if failed host 192.168.1.45 port 9876  type tcp then alert       if failed host 192.168.1.45 port 10911 type TCP then alert       alert [email protected]

 

##########################################################

#从http://blog.chinaunix.net/uid-21516619-id-1825022.html copy 过来的tomcat监控

check process tomcat with pidfile /var/run/catalina.pid     # 这个要另外说明【2】

    start program = "/etc/init.d/tomcat start"              # 设置启动命令

    stop program  = "/etc/init.d/tomcat stop"               # 设置停止命令

    if 9 restarts within 10 cycles then timeout             # 设置在10个监视周期内重

                                                            # 启了9次则超时,不再监视

                                                            # 这个服务。原因另外说明【3】

        if cpu usage > 90% for 5 cycles then alert          # 如果在5个周期内该服务

                                                            # 的cpu使用率都超过90%

                                                            # 则提示

# 若连续5个周期打开url都失败(120秒超时,超时也认为失败)

# 则重启服务

        if failed url http://127.0.0.1:4000/ timeout 120 seconds for 5 cycles then restart

        if failed url http://127.0.0.1:5000/ timeout 120 seconds for 5 cycles then restart

 

使用/var/run/catalina.pid这个pid文件来检查tomcat这个服务(服务名可以随便起),tomcat进程默认是不使用pid文件的,pid文件需要显式为tomcat设置,可以打开tomcat目录下的bin目录,打开catalina.sh文件,在开头(但不是第一行)处加入:

CATALINA_PID=/var/run/catalina.pid

即可指定pid文件,然后重启tomcat,这样就可以monit的配置中指定pid文件了。

参考:

http://blog.chinaunix.net/uid-24774106-id-3705291.html

http://blog.csdn.net/fan_hai_ping/article/details/41733783

http://blog.chinaunix.net/uid-21516619-id-1825022.html

https://github.com/arnaudsj/monit

http://mmonit.com/monit/

广告 广告

评论区