VMware Cloud Community
Myersc
Contributor
Contributor

Datastore Capacity function

I'm sure that this question has been answered before but a search of the community results in everything that I don't want.  What I am attempting to do is gather the Datastore Capacity, Used, Free and % free.  I have this all working but the numbers don't all match to what the vCenter shows. I am guessing it is because of the rounding.  What alternate function can I use so that my numbers are somewhat closer to what the vCenter shows.

I am using this right now.

function CapacitySpace

{

     param($ds)

     [math]::Round(($ds.CapacityMB/1024,2)

}

Any help is appreciated.

Craig

Reply
0 Kudos
7 Replies
cblomart
Enthusiast
Enthusiast

Hello,

Many people are using this regularly.

I personaly didn't notice a great difference. Especialy concerning capacity.

Would you have some figures?

Cédric

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership

Maybe you should first refresh the storage system information and then retrieve the datastores with:

Get-Datastore -Refresh


Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
Myersc
Contributor
Contributor

vCenter shows:

Capacity: 2.23TB

Free Space: 572.50

My report shows:

Capacity: 2281GB

Free Space: 573.01

I actually did a refresh from within vCenter and then ran the report and the difference is still there.  I'm guessing that it has to do with the powercli math and vCenter math.  This really isn't an "issue"  more of an annoyance.

Reply
0 Kudos
LucD
Leadership
Leadership

Strange, I don't see this kind of differences.

What kind of math are you doing with PowerCLI ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
cblomart
Enthusiast
Enthusiast

As for Capacity:

you get 2281GB.

if you round it up: 2.23TB is ok (powershell round also naturaly).

For FreeSpace:

-you got a difference of 522MB ... (less than 0.02 %)

-Still i don't see this kind of difference in our environment (vCenter = PowerCLI):

     get-datastore | select name,@{N="FreeSpaceGB";E={[Math]::Round($_.FreeSpaceMB/1024,2)}}

(i know it sounds idiotic but it might also be a difference in disk usage between when you looked at vCenter and PowerCLI ? log files, vm swap usage...)

Reply
0 Kudos
Myersc
Contributor
Contributor


I tried the syntax that was provided by cblomart and it still shows a difference in the capacity.  I'm probably splitting hairs here but it caught me off guard.  Below is the code that I am using that is giving me a better picture of what is happening but it still does not IMO match what the vCenter or William Lam
healthcheck reports.  I have ran a refresh on vCenter, Get-Datastore -refresh , and then ran all reports.

$Datastores = Get-Datastore
$myCol = @()
ForEach ($Datastore in $Datastores)
{
$myObj = "" | Select-Object Datastore, CapacityGB, UsedGB, FreeGB, PercFree
$myObj.Datastore = $Datastore.Name
$myObj.CapacityGB = "{0:N2}" -f ($Datastore.CapacityMB/1KB)
$myObj.UsedGB = "{0:N2}" -f (($Datastore.CapacityMB - $Datastore.FreeSpaceMB)/1kb)
$myObj.FreeGB = "{0:N2}" -f ($Datastore.FreeSpaceMB/1kb)
$myObj.PercFree = "{0:N}" -f (100 * $Datastore.FreeSpaceMB/$Datastore.CapacityMB)
$myCol += $myObj
}

Reply
0 Kudos
cblomart
Enthusiast
Enthusiast

A (crude) translation to powershell of what can be found in vmwarevSphereHealthCheck.pl from line 2526 to 2538.

$vio_dss = get-view -viewType "Datastore" -property summary,info

$ps_dss = @()

foreach ($vio_ds in $vio_dss) {

if ($vio_ds.Summary.Accessible) {

if (($vio_ds.Summary.FreeSpace -gt 0) -and ($vio_ds.Summary.Capacity -gt 0)) {

$row = "" | select Name,PcFree,Used,Free,Capacity,Block,Version

$row.Name = $vio_ds.Summary.Name

$row.Capacity = [Math]::Round($vio_ds.Summary.Capacity / 1024 / 1000,2)

$row.Used = [Math]::Round(($vio_ds.Summary.Capacity - $vio_ds.Summary.FreeSpace) / 1024 / 1000,2)

$row.Free = [Math]::Round($vio_ds.Summary.FreeSpace / 1024 / 1000,2)

$row.PcFree = [Math]::Round(100 * $row.Free / $row.Capacity,2)

if ( $vio_ds.Summary.Type -eq "VMFS") {

$row.Block = $vio_ds.Info.Vmfs.BlockSizeMb

$row.Version = $vio_ds.Info.Vmfs.Version

}

$ps_dss += ($row)

}

}

}

$ps_dss

Storage sizes reported in the "view" are all in bytes. I don't quite undestand the conversion used by William there (/1024 / 1000) i would have done " /1024/1024" to get Mbytes (MB).

this would nevertheless explain a difference of 0.02%.(i maybe had luck that it didn't show in the rounding to GB of our current infrastucture).

Reply
0 Kudos