monit-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Auto Monitor New Users Or Directories


From: Henning Bopp (boppy)
Subject: Re: Auto Monitor New Users Or Directories
Date: Sun, 3 Nov 2019 15:30:41 +0100

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! ;)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]