• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Yellow Bricks

by Duncan Epping

  • Home
  • ESXTOP
  • Stickers/Shirts
  • Privacy Policy
  • About
  • Show Search
Hide Search

Checking the diskspace on your VMFS volumes

Duncan Epping · Jan 21, 2008 ·

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:

Share it:

  • Tweet

Related

Management & Automation, Server 3.0.x, ESX, Scripting, service console

Reader Interactions

Comments

  1. Matt Lydy says

    22 January, 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!

  2. Duncan Epping says

    22 January, 2008 at 20:13

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

    • Edwin Dass says

      7 July, 2013 at 10:27

      Dear Duncan,

      I download your script and ran it on Centos machine on our network, which is not a VM. it show and error Line 25:vdf:command not found
      How do you point to the Vcenter to pull the data? Can you suggest me where I went wrong. I am not an linux expert.

      Thanks,

      Edwin Dass

      • Duncan Epping says

        9 July, 2013 at 13:33

        This script is over 4 years old. Can I recommend using a script by Alan (http://www.virtu-al.net , pretty sure his vCheck script does this) or William (http://www.virtuallyghetto.com/p/vghetto-script-repository.html)

  3. Matt Lydy says

    22 January, 2008 at 20:19

    Awesome! Thank you!

  4. Clint says

    23 January, 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!!

  5. Alexander Ebert says

    23 January, 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

  6. Kent A says

    23 January, 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.

  7. Duncan Epping says

    23 January, 2008 at 17:46

    Kent, check the download!

  8. Kent A says

    5 February, 2008 at 16:49

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

  9. Dinny says

    12 February, 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

  10. Garp1997 says

    5 August, 2008 at 10:54

    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 says

    5 August, 2008 at 12:06

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

  12. Garp1997 says

    5 August, 2008 at 12:14

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

    Many thanks.

  13. RiK says

    20 September, 2008 at 03:58

    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 says

    3 December, 2008 at 17:42

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

  15. Abid Belghiran says

    24 February, 2009 at 18:03

    Hi Duncan,

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

    Greetings

    Abid

  16. Abid says

    28 February, 2009 at 22:15

    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 [email protected] -s “Diskspace report of the VMFS volumes” -f [email protected] -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 says

    12 March, 2009 at 16:02

    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 says

    19 March, 2009 at 12:35

    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

  19. kklo says

    5 October, 2009 at 11:38

    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

  20. kklo says

    5 October, 2009 at 18:35

    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

  21. kcampbell says

    4 December, 2009 at 16:59

    fabu -many tx!

  22. John says

    23 March, 2011 at 11:03

    Does this work for ESXi?

    • Duncan says

      23 March, 2011 at 11:28

      No more than likely it doesn’t. I would recommend using PowerCLI today. These scripts were developed before PowerCLI existed.

      • John says

        23 March, 2011 at 11:43

        Do you have any examples for this?

        • Duncan says

          23 March, 2011 at 11:57

          Something like this? (needs to be tweaked though)

          http://communities.vmware.com/message/1701585

  23. Andrey Vakhitov says

    4 May, 2012 at 12:23

    Hello, Duncan. Thank you for your script. I rewrote the script, it now runs from vma
    http://vmind.ru/2012/05/04/monitoring-svobodnogo-mesta-na-xranilishhax-esxi5-cherez-vma/
    Link to the script is located at the bottom of article.

Primary Sidebar

About the author

Duncan Epping is a Chief Technologist in the Office of CTO of the Cloud Platform BU at VMware. He is a VCDX (# 007), the author of the "vSAN Deep Dive", the “vSphere Clustering Technical Deep Dive” series, and the host of the "Unexplored Territory" podcast.

Upcoming Events

Feb 9th – Irish VMUG
Feb 23rd – Swiss VMUG
March 7th – Dutch VMUG
May 24th – VMUG Poland
June 1st – VMUG Belgium

Recommended Reads

Sponsors

Want to support Yellow-Bricks? Buy an advert!

Advertisements

Copyright Yellow-Bricks.com © 2023 · Log in