I have a directory on my server and I want to monitor the number of files inside this directory with Monit... How can this be done?
Asked
Active
Viewed 1,264 times
1 Answers
3
There should be some better way to do that, but this works:
Create your monitoring program like this, for example in
/tmp/monit-num-files.sh
:#!/bin/bash maxfiles=80 dir="/tmp" if [ $(ls $dir|wc -l) -ge $maxfiles ]; then exit 1 else exit 0 fi
Then add this to your Monit configuration.
check program number-of-files with path "/tmp/monit-num-files.sh" if status != 0 then alert
This alerts if the number of files in /tmp
is more or equal 80. Directories are counted as files (but this can be changed easily).
If you want to change the file limit or the directory simply change the variables "maxfiles" and "dir" in the monitoring program.

Giacomo1968
- 3,542
- 27
- 38

unlink
- 700
- 7
- 12