Get notified when available space dips below a defined threshold

Status
Not open for further replies.

Dusan

Guru
Joined
Jan 29, 2013
Messages
1,165
There is a nice, but undocumented, script in FreeNAS that can check dataset's available space and email you when it's less than a defined amount: /usr/local/www/freenasUI/tools/check_space.py. It uses the email settings defined in System->Settings->Email.

You need to run it via python as it doesn’t have the executable bit set:
[PANEL]python /usr/local/www/freenasUI/tools/check_space.py -d [dataset] -t [threshold][/PANEL]
The [threshold] must have either a T, G, M, K suffix if you want to define an exact amount, or % if you want to use a percentage.

Example:
check_space.py -d [dataset] -t 100G will notify you if the available space is less than 100 gigabytes.
check_space.py -d [dataset] -t 10% will notify you if the available space is less than 10% of the dataset's capacity.

You can schedule a Cron Job to run the script as often as you want to check the available space.
I have a daily cron job setup to run this simple script to check that all pools have at least 10% of capacity available:
Code:
#!/bin/sh
for pool in `zpool list -Ho name`
do
  python /usr/local/www/freenasUI/tools/check_space.py -d $pool -t 10%
done
 

Yatti420

Wizard
Joined
Aug 12, 2012
Messages
1,437
Hi is this script broken as of 9.20? I can't seem to set it up..
 

Dusan

Guru
Joined
Jan 29, 2013
Messages
1,165
Yes, it is :(. I did not yet upgrade to 9.2.0 so I did not notice it, but now I tried it in a VM.
The script was not updated for newer Django version. If you are comfortable editing the root filesystem you can fix it by adding two lines to the script (it's at the top of the file, you need to add these two lines):
[panel]from freenasUI import settings
from django.core.management import setup_environ
setup_environ(settings)

from django.db.models.loading import cache
cache.get_apps()

from freenasUI.common.system import send_mail[/panel]
Or you can wait for 9.2.1 -- it is fixed there.
 

Yatti420

Wizard
Joined
Aug 12, 2012
Messages
1,437
Awesome.. Works for FreeNAS 9.2.0. Thanks!
 
Status
Not open for further replies.
Top