Reputation: 267
I'm monitoring a file size using Monit
the following way:
check file mydb with path /data/mydatabase.db
if size > 1 GB then alert
Can I do something similar to monitor a directory size?
Upvotes: 2
Views: 2190
Reputation: 323
You can write the bash command in the config to check the directory size.
The unit is in KB.
CHECK PROGRAM data_size
WITH PATH /bin/bash -c '[ $(du -s /data/path/ | awk "{print \$1}") -lt 500 ]'
IF status != 0
THEN alert
Upvotes: 2
Reputation: 812
Don't think they have one but my workaround is to use check program
the following way:
check program the_folder_size
with path "/path/to/bashscript /path/to/folder_to_monitor 500"
if status != 0 then alert
where the bash script takes in two arguments, the path to the folder to monitor and the size (in kB) which the folder isn't allowed to exceed. The echo part is to make monit
output the folder size in the 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
Upvotes: 4