Checking the diskspace on your VMFS volumes
Filed under: Howto, Scripting, VMware
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=95cat /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:





January 21st, 2008 at 19:38
[…] Checking diskspave on VMFS volume Written by Rene on January 21, 2008 – 7:39 pm Nice article about checking the free disk space on a VMFS volume. Posted in VMWare […]
January 21st, 2008 at 21:54
[…] Hier geht’s zum Artikel. […]
January 22nd, 2008 at 19:46
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!
January 22nd, 2008 at 20:13
Matt, I will post a blog tomorrow for you and others that requested this…
January 22nd, 2008 at 20:19
Awesome! Thank you!
January 23rd, 2008 at 03:01
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!!
January 23rd, 2008 at 03:08
Checking the diskspace on your VMFS volumes…
As most people who deal with VMware know it is very important to make sure that you never run out of space on your VMFS volumes. You can cause serious downtime and cause VMs to not be able to start up. There are some third party tools available both fr…
January 23rd, 2008 at 08:34
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
January 23rd, 2008 at 17:13
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.
January 23rd, 2008 at 17:46
Kent, check the download!
February 5th, 2008 at 01:44
[…] couple of weeks ago, Duncan over at yellow-bricks.com posted a nice script which gathers the disk usage of an ESX host. I thought it was a nice piece of work, but […]
February 5th, 2008 at 16:49
Thank you - the download (which I must have missed) worked perfectly. Great blog!
February 12th, 2008 at 18:09
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
April 14th, 2008 at 12:35
[…] Checking the diskspace on your VMFS volumes is a post on Yellowbricks.com that contains a script for monitoring your ESX host disk free space. […]