Highlighted
Expert
Expert

Overall VM Utilization summary

Hi All,

I'm trying to pull the VM utilization summary report for all the VM's in the below format, but it runs forever without any output. Can some experts help me resolve this issue.

NamevCPUUtilization % (Peak)Utilization % (Avg)Memory (GB)Utilization % (Peak)Utilization % (Avg)Disk Space (GB)Utilization % (Peak)Utilization % (Avg)vNICUtilization MBps (Peak)Utilization MBps (Avg)

# VM Utilisation Summary ###

$encrypted = Get-Content D:\Scripts\scriptsencrypted_paswd_admin.txt | ConvertTo-SecureString

$Cred = New-Object System.Management.Automation.PsCredential($userbane, $encrypted)

$Cred = New-Object System.Management.Automation.PsCredential($userbane, $encrypted)

$vCenters = (Get-Content "C:\Temp\VC2.txt")

$start = (Get-Date).AddHours(-2)

$performance = @()

foreach ($vcenter in $vcenters) {

  Connect-VIServer $vcenter -Credential $Cred

 

  $vms = Get-VM

$performance += Get-Stat -Entity $vms -Start $start -ErrorAction SilentlyContinue |

Group-Object -Property {$_.Entity.Name} |

Select @{N='VM';E={$_.Name}},

    @{N='Cluster';E={(Get-Cluster -VM $_.Name)}},

    @{N='CPU(%)';E={"{0:N1}" -f ($_.Group | where{$_.MetricId -eq 'cpu.usage.average'} | Measure-Object -Property Value -Average | select -ExpandProperty Average)}},

    @{N='Memory(%)';E={"{0:N1}" -f ($_.Group | where{$_.MetricId -eq 'mem.usage.average'} | Measure-Object -Property Value -Average | select -ExpandProperty Average)}},

    @{N='Net(KBps)';E={"{0:N2}" -f ($_.Group | where{$_.MetricId -eq 'net.usage.average'} | Measure-Object -Property Value -Average | select -ExpandProperty Average)}},

    @{N='Disk(KBps';E={"{0:N2}" -f ($_.Group | where{$_.MetricId -eq 'disk.usage.average'} | Measure-Object -Property Value -Average | select -ExpandProperty Average)}}

   Disconnect-VIServer -Server $vcenter -Confirm:$false

}

    $performance | Export-Csv D:\script\VMperf.csv

0 Kudos
9 Replies
Highlighted
User Moderator
User Moderator

Is that script hanging or does it run for a very long time?
Run a test with a smaller scope.


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

0 Kudos
Highlighted
Expert
Expert

Thank you, LucD. I got the output. Yes, runs for a long time for 1 vCenter and i'm planning to run for 5 to 10 vCenter remote sites, Is it possible to reduce the time interval to generate output.

Is that script hanging or does it run for a very long time? - Yes.

Run a test with a smaller scope.- Yes i tried with 1 VC having 350 VM's.

Thanks

V

0 Kudos
Highlighted
User Moderator
User Moderator

You can always lower the time interval, but if you want data for the last 24 hours, that is not really an option.
Retrieving statistical data from the VCSA might take a long time, depending on how busy your VCSA is.


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

Highlighted
Expert
Expert

LucD,

As per your recommendation, i have reduced the time interval to 2 hours, but it throws an error and no output generates. I'm fine with data is aggregated to 2 hour intervals as well

pastedImage_0.png

Thanks

V

0 Kudos
Highlighted
User Moderator
User Moderator

It looks as if you were not connected to a vCenter when you ran the script.


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

0 Kudos
Highlighted
Expert
Expert

LucD,

But i mentioned in the code for connecting the vcenter and its output is blank. It was working earlier, but when i change the interval to 2 hours, then it throws an error.

$encrypted = Get-Content D:\Scripts\scriptsencrypted_paswd_admin.txt | ConvertTo-SecureString

$Cred = New-Object System.Management.Automation.PsCredential($userbane, $encrypted)

$Cred = New-Object System.Management.Automation.PsCredential($userbane, $encrypted)

  $vCenters = (Get-Content "C:\Temp\VC2.txt")

Thanks

V

0 Kudos
Highlighted
User Moderator
User Moderator

Does it work when you change it back to 24 hours?
I would find that very strange.

I would need to see your current code to check this.


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

0 Kudos
Highlighted
Expert
Expert

LucD,

I just changed the code adding the $vms = Get-VM  after vcenter connnection, then it works. Does it makes any difference while reducing the time interval from 24 to 2 hours and changing the code ?

But still it takes time for 2 hours interval. I have attached the code.

Thanks

v

0 Kudos
Highlighted
User Moderator
User Moderator

That line with Get-VM needs to be there, otherwise, there are no Entities for Get-Stat to retrieve metrics for.

The runtime of the script depends primarily on the Get-Stat cmdlet I assume.

Depending on the number of entities this also depends on the load of the vCenter.

To find out what exactly is taking so long you might want to do some profiling.
I discussed that subject during my recent session at the Belgian VMUG, the slides and code are available.


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