I like thin provisioning on vSphere. I also like not over-allocating datastores by half a terabyte without knowing it. To prevent crazy amounts of over-allocation (but still keep the environment going with a slightly-less-crazy amount of over-allocation) it is important for me to know the “true” free space on all of my datastores. By this, I do not mean what vCenter tells me is the free space, but rather a blend of a couple things: the actual usage on the datastore, and the current allocation on that datastore. With these, I can determine how far I can push the provisioning of virtual machines before I need to worry about running out of space and DOSing other VMs on the same datastore.
Lucky for me, this data is readily available with the PowerCLI, here’s the source code: http://bit.ly/eMLjVk
.\StorageCapacity.ps1 -server <string> -dbserver <string> -db <string> -overallocate <int>
Where -overallocate is the percentage by which you want to overallocate storage (if at all) & the account you run the script as must have at least Read-Only access to vCenter Server and data reader role on the virtualcenter SQL db.
This script is a work-in-progress, but has come in very handy when I am placing VMs, and their virtual disks, in our environment. Also, I reuse parts of this script in a series of scripts that auto-provision VMs for our group and external customers via a custom web request form. (more on the auto-provisioning stuff another time…)
Right now, the script scours the virtual environment for VMs & templates, then tracks how much space their virtual disks and swap files take up. After adding that all up, it displays (and outputs a CSV of) all of the useful information per datastore, including the “real” free space available, capacity that includes your over-allocation %, provisioned space, and normal free space. In a future (more accurate) version, I plan to also include log files, since those can actually take up significant space.