Monitor the size of your vDisks

In a recent thread on the VMTN PowerCLI Community someone asked if it is possible to get historical hard disk statistics. I referred the user to my Datastore usage statistics post, where I showed how to use the “disk” metrics to get that information.

But getting the individual vDisk statistics is a bit more tricky compared to getting the datastore statistics, as I showed in that post. The “disk” metrics hold the information, but the Instance that points to the MoRef value of a VM makes it a bit more tricky to retrieve.

Be forewarned, the “disk” metrics hold usage data for all the vDisks that a specific VM has on a specific datastore. You will not be able to get individual vDisk statistics, unless the vDisks are stored on different datastores !

On the positive side, the “disk” metrics will allow you to see how your vDisks increase in size over time. For your Thick vDisks that increase will be by expanding them, and for your Thin vDisks it will also show the natural growth.

The Script


Line 1: The datastore for which the script will produce a report

Line 2: The script looks for specific VMs on the datastore

Line 4: The Historical Interval 4 holds 1 entry per day, which is sufficient for monitoring vDisk growth. If you need finer samples change it to another Historical Interval, but note that the “disk” metrics are only available for the historical intervals.

Line 12: This will allow the script to interpret dates correctly, in other words it allows the script later on to read dates in the format “mm/dd/yyyy” and in the “dd/mm/yyyy” format.

Line 14-16: For the VMs we want to report upon, the script fetches the Value property of its MoRef. This Value corresponds with the Instance that will be returned with the performance data, and that allows the script to link the Instance to the VM name.

Line 18-19: With the QueryInstances parameter the script requests all the available Instances, in other words VM specific performance data. The script checks if the Instance is in the MoRef.Value format and if the Instance corresponds with one of the VMs we want to report upon.

Line 20-21: For all the qualifying Instances the script fetches the performance data.

Line 24-32: The performance data is grouped on the Timestamp. All the individual performance objects with a specific Timestamp, each for 1 Instance (or 1 VM), are combined into 1 object with a property for each Instance.

Line 26: The Timestamp became a string, in a format defined by the locale, in the Group-Object earlier on. To interpret the date string correctly the script calls the Parse method and passes the locale object.

Sample Usage

The script uses my Get-Stat2 function I have used before. Make sure that function is known before calling the script above. The latest version of my Get-Stat2 function can be downloaded below.

7.4 KiB

The CSV file that is produced by the script looks like this:

If you have a PowerShell module or snapin that allows you to produce graphs, you can make the result a bit fancier.

I replaced the Export-Csv line with the Out-Chart cmdlet from PowerGadgets.

Notice how I use the Parse method to interpret the dates correctly for the locale where the script runs.
The resulting picture looks as follows.

This vDisk reporting script can be expanded in many ways. We could for example find all created and removed VMs, which would give us a complete report of which VMs have hsitorically been using your datastore space. But that will be for a later post.

Enjoy !

One Comment


    This is another great script, thanks LucD!

    Instead of needing to call out the VMs inside of the datastore, how can I make the script just collect stats for all VMs on the given datastores? If I wanted to run this against all datastores in vCenter, is it possible to separate the datastores so its not a mass amount of data on one spreadsheet, possibly like having one datastore per spreadsheet sheet?


Leave a Reply

Your email address will not be published. Required fields are marked *


Buy the Book