Hi,
Here is a script we wrote to check free space on a mount point passed in parameter. If the mount point is nfs type, the script writes and deletes a test file to validate the access.
The free space percentage is recalculated since the df command output.
Thank's for your returns.
Matthieu
#!/bin/bash # # This script return df result for the mount point # and check if writing on it is possible (NFS only) # support: support@sensorfactory.freshdesk.com if [ $# != 1 ] then echo "<prtg>" echo " <error>1</error> <text>Please specify a mount point</text>" echo "</prtg>" exit 1 fi # Data collecting data=($(df -PkTm | grep -w $1 | awk '{ print $2,$3,$4,$5,$6 }')) # Compute real free percent space freep=$(awk "BEGIN { pc=100*${data[3]}/${data[1]}; i=int(pc); print (pc-i<0.5)?i:i+1 }") # Check NFS writing if [ "${data[0]}" = "nfs" ]; then touch "$1/test" if [ $? -ne 0 ]; then echo "<prtg>" echo " <error>1</error> <text>Unable to write on $1</text>" echo "</prtg>" else rm -f "$1/test" fi fi # Output echo "<prtg>" echo "<result> <channel>Free%</channel> <value>$freep</value> <Unit>Percent</Unit> <LimitMinWarning>12</LimitMinWarning> <LimitMinError>10</LimitMinError> <LimitMode>1</LimitMode> </result>" echo "<result> <channel>Total</channel> <value>${data[1]}</value> <CustomUnit>MBytes</CustomUnit> </result>" echo "<result> <channel>Used</channel> <value>${data[2]}</value> <CustomUnit>MBytes</CustomUnit> </result>" echo "<result> <channel>Free</channel> <value>${data[3]}</value> <CustomUnit>MBytes</CustomUnit> </result>" echo "</prtg>" exit 0
Thank you very much for sharing this script, Matthieu! Awesome!
Just in case other users wonder how to use the script for monitoring with PRTG, they are welcome to follow these steps:
Mar, 2016 - Permalink