Checking the diskspace on your VMFS volumes

Posted by Duncan Epping in January 21st, 2008
Published in Management & Automation, Server

On a regular basis I noticed that people forget to monitor the free diskspace of their VMFS volumes. I created a script that can easily be scheduled with crontab and mailed with smtp_send. You can send it as an html based email if you setup MIME correctly. (For more info on how to set this up, check this blog) The script creates an html file with a table in which the necessary info is dumped, if a VMFS volume has less than 10% free space that specific line will be yellow and if it’s less than 5% than that line will be red… So a helpdesk should be able to monitor it and warn you in case it runs or will run out of diskspace.

The script, and you can download it here!:

#!/bin/bash
# Script voor het controleren op het bestaan van Snapshots
LOGLOC="/var/log/"
LOG="${LOGLOC}vdf.html"
MYDATE=$(date +%d-%m-%y)
VMFSYELLOW=90
VMFSRED=95

cat /dev/null > "${LOG}"
echo "<html>" >> "${LOG}"
echo "<head>" >> "${LOG}"
echo "<style>" >> "${LOG}"
echo "body {margin: 10px; width: 600px; font-family:arial; font-size: 10px;}" >> "${LOG}"
echo "div#footer {font-size: 9px;}" >> "${LOG}"
echo "</style>" >> "${LOG}"
echo "</head>" >> "${LOG}"
echo "<body>" >> "${LOG}"

echo "<table cellspacing="0" cellpadding="2" border="1"; style='border-collapse:collapse; background-color: white; color: black'>" >> "${LOG}"
echo "<tr><th colspan='5'; align='left'; style='background-color: rgb(179,179,179); color: black'>" >> "${LOG}"
echo "VMFS Disk Usage - $MYDATE</th></tr>" >> "${LOG}"
echo "" >> "${LOG}"
echo "<tr>" >> "${LOG}"
echo "<td><b>VMFS Volume</b></td><td><b>Disk Size</b></td><td><b>Used</b></td><td><b>Available</b></td><td><b>Percentage</b></td>" >> "${LOG}"
echo "</tr>" >> "${LOG}"
vdf -h -P | grep -E '^/vmfs/volumes/' | awk '{ print $2 " " $3 " " $4 " " $5 " " $6 }' | while read output ; do
DISKSIZE=$(echo $output | awk '{ print $1 }' )
DISKUSED=$(echo $output | awk '{ print $2 }' )
DISKAVAILABLE=$(echo $output | awk '{ print $3 }' )
PERCENTINUSE=$(echo $output | awk '{ print $4 }' )
VOLNAME=$(echo $output | awk '{ print $5 }' )
CUTPERC=$(echo $PERCENTINUSE | cut -d'%' -f1 )
WARNING="white"
if [ $CUTPERC -ge $VMFSYELLOW ] ; then
WARNING="yellow"
fi
if [ $CUTPERC -ge $VMFSRED ] ; then
WARNING="red"
fi
echo "<tr><td style='background-color: ${WARNING}'>$VOLNAME</td>" >> "${LOG}"
echo "<td style='background-color: ${WARNING}'>$DISKSIZE</td>" >> "${LOG}"
echo "<td style='background-color: ${WARNING}'>$DISKUSED</td>" >> "${LOG}"
echo "<td style='background-color: ${WARNING}'>$DISKAVAILABLE</td>" >> "${LOG}"
echo "<td style='background-color: ${WARNING}'>$PERCENTINUSE</td></tr>" >> "${LOG}"
done
echo "</table>" >> "${LOG}"
echo "<div id='footer'>Created by Ictivity bv.</div>" >> "${LOG}"
echo "</body>" >> "${LOG}"
echo "</html>" >> "${LOG}"

The output will look similar to this:

HTML list of VMFS volumes

Close
HTML list of VMFS volumes


25 user comments or pingbacks in this post

Follow-up this post comment rss or leave a trackback
1. Matt Lydy said,

I really want to try out this script in my environment. Thanks for posting this. Can you describe what you mean by “You can send it as an html based email if you setup MIME correctly.”

Should MIME be configured on the ESX server or is that for IIS or something like that? If you could point me to a link or documentation for getting that configured it would be greatly appreciated!

2. Duncan Epping said,

Matt, I will post a blog tomorrow for you and others that requested this…

3. Matt Lydy said,

Awesome! Thank you!

4. Clint said,

Very nice script. We use BMC patrol in our environment and although it does a good job monitoring many things in ESX it always tends to have some false positives on the VMFS disk size.

So this could be useful!!

5. Alexander Ebert said,

Hello Duncan,

many thanks for this great job! This script is very useful for our VMware Enviroment. Vmware should be integrated into virtual center. The Alarms in Virtual Center are very poor und we need additional features, like your script, to monitor our productive enviroment.
Greetings from Germany

Alex

6. Kent A said,

Could you repost the script without the formatting or as a download? The quotations are problematic, and I am unable to get the vdf -h -P line correct. Thanks.

7. Duncan Epping said,

Kent, check the download!

8. Kent A said,

Thank you – the download (which I must have missed) worked perfectly. Great blog!

9. Dinny said,

Nice script.

I added a ” | sort -k 6″ into the vdf command string, to sort the vmfs vols in alphabetic order.

May be useful to some people – depending on naming conventions?

Dinny

10. Garp1997 said,

Hi Duncan,
I used your script (great job) and it working well but, if I run it from crontab no table is in, only header and footer. Have you any suggestion?

Bye

11. Duncan Epping said,

probably a path related issue. try to use full paths every where.

12. Garp1997 said,

Thanks for answer Duncan, I added /usr/sbin/ before vdf and now it works.

Many thanks.

13. RiK said,

I love this script, it helps a lot! I’m not a scripter, does anyone know how I could add a row at the bottom with total used/available and overall percent? Thanks!

14. rwu said,

Would it be possible for you to try and get this info incorporated into RVTools?

15. Abid Belghiran said,

Hi Duncan,

very great job! This script is very useful.
Thanks a lot !

Greetings

Abid

16. Abid said,

Hello Duncan,

thanks for your very great script. Your Script works very good. I am a beginner in perl but now I would like to modify the script. I would like to be Informed only if the threshold for Warning is reached.

at the bottom of your script,I have add this.

if [ $CUTPERC -ge $VMFSRED ] ; then
/usr/local/bin/smtp_send.pl -t info@me.com -s “Diskspace report of the VMFS volumes” -f esx01@me.com -m “`cat /var/log/vdf.html`” -r 172.10.10.10
fi

But unfortunately it does not work because the values of $CUTPERC and $VMFSRED are lost after the loop. Could you give me a hint , how I can solve my problem

Many thanks.

17. timbow said,

Hello Duncan,

thanks for the nice script. I’ve got a ESX 3.5 Server and it works great. I modified it so it only sends Emails when one of the Volumes status is “red”. Manually used it works perfect, but when I put it in Crontab as a job nothing happens. In the Crontab log files I can see that the script is executed every hour, thats like i wanted it but theres no email sending… can you help me? Thanks for help greetings from germany

18. naz said,

Hello timbow,

how did you modify the script?
I need the same functionality, I want only Emails when one of the Volumes status is red. could you help me ?

Thank you

Naz

Leave A Reply Below

Currently browsing Checking the diskspace on your VMFS volumes

 Username (*required)

 Email Address (*private)

 Website (*optional)

Pingback and trackback

Link trail from various blogs:
Pingback on January 21st, 2008 at 21:54
Pingback on January 23rd, 2008 at 03:08
Pingback on August 7th, 2008 at 12:24
Pingback on October 17th, 2008 at 11:12

Topics Search

Yellow-Bricks recommends:







VMware Fusion and VMware Workstation: Support Yellow-Bricks and get a 10% discount on select VMware products.

Train Signal:
Learn Virtualization technology with Train Signal. Support us and learn how to fully utilize VMware products at the same time! Click here for more info!

Advertisements

Recent Comments

Tags

Info