如果文件夹大小超过一定数量,Monit 可以发送警报吗?

Can Monit send an alert if a folder size exceeds a certain number?

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

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

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

别以为他们有,但我的解决方法是按以下方式使用 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=
REFERENCE_SIZE=
SIZE=$(/usr/bin/du -s $FOLDER_PATH  | /usr/bin/awk '{print }')
echo "$FOLDER_PATH  -  ${SIZE}kB"
if [[ $SIZE -gt $(( $REFERENCE_SIZE )) ]]; then exit 1;fi

你可以在config里写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