【问题标题】:Can Monit send an alert if a folder size exceeds a certain number?如果文件夹大小超过一定数量,Monit 可以发送警报吗?
【发布时间】:2015-07-20 16:08:23
【问题描述】:

我通过以下方式使用Monit 监控文件大小:

check file mydb with path /data/mydatabase.db
  if size > 1 GB then alert

我可以做一些类似的事情来监控目录大小吗?

【问题讨论】:

    标签: monit


    【解决方案1】:

    不认为他们有,但我的解决方法是通过以下方式使用check program

    check program the_folder_size 
      with path "/path/to/bashscript /path/to/folder_to_monitor 500"
      if status != 0 then alert
    

    bash 脚本接受两个参数,即要监视的文件夹的路径和不允许超过的文件夹大小(以 kB 为单位)。 echo部分是让monit在monit web gui中输出文件夹大小。

    #!/bin/bash
    FOLDER_PATH=$1
    REFERENCE_SIZE=$2
    SIZE=$(/usr/bin/du -s $FOLDER_PATH  | /usr/bin/awk '{print $1}')
    echo "$FOLDER_PATH  -  ${SIZE}kB"
    if [[ $SIZE -gt $(( $REFERENCE_SIZE )) ]]; then exit 1;fi
    

    【讨论】:

      【解决方案2】:

      您可以在配置中编写 bash 命令来检查目录大小。

      单位为 KB。

      CHECK PROGRAM data_size
         WITH PATH /bin/bash -c '[ $(du -s /data/path/ | awk "{print \$1}") -lt 500 ]'
      
         IF status != 0
         THEN alert
      

      【讨论】:

        猜你喜欢
        • 2016-06-11
        • 1970-01-01
        • 1970-01-01
        • 2023-03-06
        • 2016-03-18
        • 2011-11-06
        • 2021-03-18
        • 1970-01-01
        • 2016-03-03
        相关资源
        最近更新 更多