Jason
Jason

Reputation: 267

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

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

Answers (2)

ws-ono
ws-ono

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

Ingo
Ingo

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

Related Questions