That is perfect! I was thinking of calling a script but was not quite sure how to go about it.
Thanks! On Sun, Nov 3, 2019 at 9:31 AM Henning Bopp (boppy) <[email protected]> wrote: > Hi Lorne, > > I am using a `check program` for this (info: my Monit has 1 minute cycle): > > ``` > check program "dirsizer" path "/srv/monit/dirsizer" timeout 360 seconds > every 60 cycles # Runs once an hour > if status != 0 then alert > ``` > > > while "/srv/monit/dirsizer" might be like: > > ``` > #!/usr/bin/env bash > > checkdir="/var/www/html" > sizes=$(du -d 1 -t 1G -h "${checkdir}" 2>/dev/null | head -n -1 | sort -rh) > chars=$(wc -c <<< "$sizes") > > if [[ "${chars}" -gt "1" ]]; then > echo "$(head -n10 <<< "$sizes")" > exit 1 > fi > > exit 0 > ``` > > In this case, you will receive an alert if there is at least one > directory with >= 1G of size. You will also get the 10 biggest > directories above 1G in the programs output to review on the web front > end AND included in the alert email (if the LIMITS allow it). Since > Monit is configured to alert only on status!=0, you might even echo > the sizes without an alert, so you can review them any time on the > web-frontend of Monit. > > As this request seems to refer to some kind a shared hosting, you have > to keep an eye on the execution time. In my scenario there are not > that many small files that slow down du significantly. But with > multiple CMS' installs, you might run into a timeout. Good thing: > You'll receive an alert about this! ;) > >
