记录使用monito软件监测 log文件的大小

  1. monit是一个可以监控系统,进程,文件系统,目录,设备的监控软件,可以自动唤起那些异常退出的进程,还可定制你想监控的东西。同时monit提供了内置的WEB UI的功能,可以一目了然地了解监控项的情况。其中正常项为绿色,异常项为红色,很方便的告警,另外,monit还提供了发邮件通知的功能,对于紧急的异常情况可以发送邮件到指定邮箱。比如发生了coredump,发生了DB corrupt,daemon进程异常重启,可以第一时间邮件通知到管理员,呵呵很强大吧。片汤话我们不多讲,讲讲怎么用monit搭建一个监控系统。
    monit是一个很轻量级的程序,只需要一个可执行程序monit,一个配置文件monitrc即可工作onit是一个很轻量级的程序,只需要一个可执行程序monit,一个配置文件monitrc即可工作.

  2. 下载地址:https://mmonit.com/monit/dist/ 下载monit-5.27.0.tar.gz 安装包,安装软件,默认安装位置/usr/local
    3 monitrc 配置文件的修改

 # check system 127.0.0.1
248    # if loadavg (5min) > 4 for 4 times 5 cycles then alert
249    # if memory usage > 90% then alert
250    # if cpu usage (user)  > 70% for 4 times within 5 cycles then alert
251    # if cpu usage (system) > 30% for 4 times within 5 cycles then alert
252    # if cpu usage (wait)  > 20% for 4 times within 5 cycles then  alert
253 
254 
255 ## Check a file's timestamp. In this example, we test if a file is older
256 ## than 15 minutes and assume something is wrong if its not updated. Also,
257 ## if the file size exceed a given limit, execute a script
258 #
259 #  check file database with path /data/mydatabase.db
260 #    if failed permission 700 then alert
261 #    if failed uid "data" then alert
262 #    if failed gid "data" then alert
263 #    if timestamp > 15 minutes then alert
264 #    if size > 100 MB then exec "/my/cleanup/script" as uid dba and gid dba
265       check file mylog  with path /home/log    //检测文件的路径及文件名字
266 
267         IF SIZE > 5 KB then exec "/bin/bash /home/clean" //达到指定的大小后清楚文件的内容

4 .配置好monitrc后我们使用monit 命令
monit reload //重载入配置文件
monit //启动服务
monit stop //停止启动服务

monit status  //查看状态
monit  summary //如下表所示 展示类型和状态

┌─────────────────────────────────┬────────────────────────────┬───────────────┐
│ Service Name │ Status │ Type │
├─────────────────────────────────┼────────────────────────────┼───────────────┤
│ shanlin-VirtualBox │ OK │ System │
├─────────────────────────────────┼────────────────────────────┼───────────────┤
│ mylog │ OK │ File │
└─────────────────────────────────┴────────────────────────────┴───────────────┘

5 。 经过测试此配置服务正常运行,此软还可监控软件的运行,脚本,还有其他服务器的运行。

你可能感兴趣的:(记录使用monito软件监测 log文件的大小)