PKania
Contributor
Contributor

Used Space per each thin VMDK

Hello guys,

is it possible to track the actual used space per each thin VMDK in a VM?

I know that it's possible to track the used space per VM with $VM.UsedSpaceGb, but this is not helping in my case.

The background for this is overcommitment from think disks. Have to scan each vmdk and track if its possible that this VMDK can grow larger then free Space on the Datastore where this VMDK is located.

Currently I work with $VM.UsedSpaceGb but this is not accurate enough.

I dug through the PowerCLI API but found nothing about this, also the WWW also nothing found.

Perhaps someone can help me Smiley Happy

Thanks

Kind Regards

Philipp Kania

0 Kudos
8 Replies
LucD
Leadership
Leadership

Have a look at yadr – A vdisk reporter


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

Borja_Mari
Virtuoso
Virtuoso

Hello,

i have mainly used/modified this script to get almost what you want.

It doesn't distinguish between thin and thick vdisks.

From a virtual machine perspective, it calculates the total size of the virtual machines' vdisks (thick and thin).

The space that the thin vdisks can grow is known as "uncommitted".

This is the script:

$debug = $False # Set to $False if you just want to show the virtual machine with thin vdisks that maybe can overcommit the datastore where are placed

$max_percent = 90 # The maximum percent of the datastore used space (threshold) that the virtual machine (thin + thick) vdisks can consume

$vcenter_ip = "IP"

Connect-VIServer -Server $vcenter_ip | out-null

$report = @()

$allvms = Get-VM

foreach ($vm in $allvms) {

     $vmview = $vm | Get-View

     foreach($disk in $vmview.Storage.PerDatastoreUsage){

             $dsview = (Get-View $disk.Datastore)

             $dsview.RefreshDatastoreStorageInfo()

          $row = "" | select VmName, DataStore, DataStoreSizeGB, DataStoreFreeSpaceGB, VmVdisksPerDatastoreTotalSizeGB, VmVdisksPerDatastoreCommittedSizeGB, VmVdisksPerDatastoreCommittedPercent, VmVdisksPerDatastoreMaximumPercent

      

          # Virtual machine's name

          $row.VmName = $vmview.Config.Name

      

          # Datastore's name where the virtual machine has vdisk(s) placed

          $row.DataStore = $dsview.Name

      

          # The capacity of the Datastore

          $row.DataStoreSizeGB = ((Get-VM -Name $row.VmName | Get-Datastore -Name $row.DataStore).CapacityMB/1024)

      

          # The free space of the Datastore

          $row.DataStoreFreeSpaceGB = ((Get-VM -Name $row.VmName | Get-Datastore -Name $row.DataStore).FreeSpaceMB/1024)

      

          # The maximum size of the thick and thin (all space committed) vdisks of the virtual machine placed in the $row.DataStore datastore

          $row.VmVdisksPerDatastoreTotalSizeGB = (($disk.Committed+$disk.Uncommitted)/1024/1024/1024)

      

          # The size of the thick and thin (just actually committed space) vdisks of the virtual machine placed in the $row.DataStore datastore

          $row.VmVdisksPerDatastoreCommittedSizeGB = (($disk.Committed)/1024/1024/1024)

      

          # The usage's percent of the actually committed space of all virtual machine's vdisks (thin & thick) placed in the $row.DataStore datastore                

          $row.VmVdisksPerDatastoreCommittedPercent = (($row.VmVdisksPerDatastoreCommittedSizeGB/$row.VmVdisksPerDatastoreTotalSizeGB)*100)

      

          #  The percent of the datastore used space if all the virtual machine (thin + thick) vdisks space is committed             

          $row.VmVdisksPerDatastoreMaximumPercent = (($row.VmVdisksPerDatastoreTotalSizeGB - $row.VmVdisksPerDatastoreCommittedSizeGB)/$row.DataStoreFreeSpaceGB)*100

      

      

          if ($debug) {$report += $row }

          else { if ($row.VmVdisksPerDatastoreMaximumPercent -cgt $max_percent)  {$report += $row } }

   }

}

$report

Disconnect-VIServer $vcenter_ip -Confirm:$False

} # End Try

Catch { $_.Exception.Message}

Hope it helps Smiley Wink

Best regards,

Pablo

Message was edited by: Pablo (some little modifications in the script)

------------------------------------------------------------------------------------------------- PLEASE CONSIDER AWARDING any HELPFUL or CORRECT reply. Thanks!! Por favor CONSIDERA PREMIAR cualquier respuesta ÚTIL o CORRECTA . ¡¡Muchas gracias!! VCP3, VCP4, VCP5-DCV (VCP550), vExpert 2010, 2014 BLOG: http://communities.vmware.com/blogs/VirtuallyAnITNoob
Borja_Mari
Virtuoso
Virtuoso

Hello,

my script helped you? Smiley Happy

Best regards,

Pablo

------------------------------------------------------------------------------------------------- PLEASE CONSIDER AWARDING any HELPFUL or CORRECT reply. Thanks!! Por favor CONSIDERA PREMIAR cualquier respuesta ÚTIL o CORRECTA . ¡¡Muchas gracias!! VCP3, VCP4, VCP5-DCV (VCP550), vExpert 2010, 2014 BLOG: http://communities.vmware.com/blogs/VirtuallyAnITNoob
0 Kudos
PKania
Contributor
Contributor

Hello Pablo,

sry didn't test your script. Some other stuff to do Smiley Happy.

I will give you a Feedback.

Thanks

Best regards,

Phil

0 Kudos
Borja_Mari
Virtuoso
Virtuoso

Ok,

hehehe Smiley Wink

I have in my TODO list to improve this script, to report more information about thin disks.

Anyway, right now, it should do the trick! Smiley Happy

Best regards,

Pablo

------------------------------------------------------------------------------------------------- PLEASE CONSIDER AWARDING any HELPFUL or CORRECT reply. Thanks!! Por favor CONSIDERA PREMIAR cualquier respuesta ÚTIL o CORRECTA . ¡¡Muchas gracias!! VCP3, VCP4, VCP5-DCV (VCP550), vExpert 2010, 2014 BLOG: http://communities.vmware.com/blogs/VirtuallyAnITNoob
0 Kudos
PKania
Contributor
Contributor

Hello Pablo,

just tested your script in my local environment.

Works well but it still report the total of all vmdks of a virtual machine right?

Not every single vmdk or I'm wrong?

Best regards

Phil

0 Kudos
Borja_Mari
Virtuoso
Virtuoso

Hello,

you're right.

Right now my script just reports if individual virtual machines can potentially over-commit the datastore where are placed its thin and thick vdisks.

The situation when a individual virtual machine can over-commit the datastore space is when its thin vdisk(s) grows to the maximum size (all space is committed).

In my future release of my script, my idea is also show the potentially used space by the thin vdisks, but in a datastore perspective, not just from a vm's perspective like now.

Then, when a individual vm can over-commit a datastatore, show its thin disk(s).

AFAIK (i have to investigate more Smiley Happy), it's not possible to check the current committed space of individual thin vdisks.

Just it can be checked from a virtual machine or datastore point of view.

Best regards,

Pablo

------------------------------------------------------------------------------------------------- PLEASE CONSIDER AWARDING any HELPFUL or CORRECT reply. Thanks!! Por favor CONSIDERA PREMIAR cualquier respuesta ÚTIL o CORRECTA . ¡¡Muchas gracias!! VCP3, VCP4, VCP5-DCV (VCP550), vExpert 2010, 2014 BLOG: http://communities.vmware.com/blogs/VirtuallyAnITNoob
0 Kudos
PKania
Contributor
Contributor

Hello Pablo,

then we are at the same point Smiley Happy. Thanks for that.

I also searching the whole internet and also the api for that to scan each individual vmdk for overcommitment.

But i don't know who .... thats fraught me ... Smiley Happy

But good to know that I'm not alone.

Best regards

Phil

0 Kudos