Checking the diskspace on your VMFS volumes

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




You can leave a response, or trackback from your own site.

28 Responses to “Checking the diskspace on your VMFS volumes”

  1. [...] 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 [...]

  2. Matt Lydy says:

    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!

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

  4. Clint says:

    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. 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…

  6. Alexander Ebert says:

    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

  7. Kent A says:

    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.

  8. Kent, check the download!

  9. [...] 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 [...]

  10. Kent A says:

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

  11. Dinny says:

    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

  12. [...] 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. [...]

  13. Garp1997 says:

    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

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

  15. Garp1997 says:

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

    Many thanks.

  16. [...] this article for a script that will check the disk space of all VMFS volumes and format the results into a nice [...]

  17. RiK says:

    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!

  18. Aufgabe von vdf als HTML…

    Mittels vdf kann man sich die aktuelle Belegung der VMFS Dateisysteme auf der Serviceconsole vom VMware ESX ausgeben lassen. Da es aber bei der Serviceconsole um ein mehr oder weniger komplettes RHEL3 handelt, kann man sich natürlich die üblichen Skr…

  19. rwu says:

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

  20. Abid Belghiran says:

    Hi Duncan,

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

    Greetings

    Abid

  21. Abid says:

    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.

  22. timbow says:

    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

  23. naz says:

    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

  24. kklo says:

    Hello,

    To be able to send a mail only when there is a YELLOW or a RED warning you should modify the script as follows:

    SENDMAIL=0
    SENDMAIL=$( /usr/sbin/vdf -h -P | sort -k 6 | grep -E ‘^/vmfs/volumes/’ | awk ‘{ print $2 ” ” $3 ” ” $4 ” ” $5 ” ” $6 }’ | while read output ; do
    ……
    ……
    if [ $CUTPERC -ge $VMFSYELLOW ] ; then
    WARNING=”yellow”
    echo -ne 1
    fi
    ……
    ……
    done
    )
    echo “” >> “${LOG}”
    echo “VMFS – Disk Usage Monitor by BitBat, S.L.” >> “${LOG}”
    echo “” >> “${LOG}”
    echo “” >> “${LOG}”

    if [ $SENDMAIL -ge 1 ]; then
    MAIL_BODY=`cat ${LOG}`

    /usr/bin/perl smtp_send.pl -t $MAIL_TO -f $MAIL_FROM -s “VMFS Disk Usage – $MYDATE” -r $MAIL_SERVER -m “$MAIL_BODY”
    fi

    best regards,
    kklo

  25. kklo says:

    There is a malfunction in my last post.

    if there is o warning yellow or red, the SENDMAIL variable is not defined and this gives a sintaxis error in the eval:
    if [ $SENDMAIL -ge 1 ]; then

    So the better way to avoid this error is change the test as follows:

    if [ ! $SENDMAIL ]; then
    # SENDMAIL is not defined, so there is no warning
    else
    #Put here the sending mail procedure
    ….

    fi

    regards
    kklo

  26. kcampbell says:

    fabu -many tx!

Leave a Reply

Subscribe to RSS Feed Follow me on Twitter!