Listing all vCenter performance metrics with PowerCLI

Posted by

Our big data team recently approached me and wanted to know if I could gather real time performance metrics on vCenter virtual machines and publish them to their API.  I asked which metrics they wanted they said, “all of them.”  I proceeded with gathering all of them but wanted to give them a list of all metrics so that they could pick and choose which ones they wanted.  I needed the name of the metric, the stat level it’s recorded at (in case they later wanted something other than real time metrics) and a description of the metric as they aren’t familiar with VMware.

I had never used PowerCLI to gather vCenter performance metrics so my first step was to see how to interact with vCenter and to see which performance metrics were available.  The method that I’m going to describe actually list all vCenter performance metrics and not just virtual machine metrics.  I ended up not using this in my final script to gather virtual machine performance data, but thought it may be useful to be able to look at spreadsheet with the performance metrics so I could easily sort, filter, etc.

I poked around on LucD’s page for information on how to get started.  I’d recommend that you’d check out the links below if you’re interested in using PowerCLI to gather vCenter performance metrics:

In an upcoming post I’ll describe the script I made to gather virtual machine performance metrics and publish them to an API.  For now, here is the script to generate a CSV file with all vCenter performance metrics.

# define where we will save our performance metrics.
$outputFile = "C:\Users\chris\Desktop\perfdumps\vCenterMetrics.csv"

# define a new Powershell credential and log into vCenter with the credentials
$creds = Get-Credential
$vCenter = Connect-VIServer vc6b.vmware.local -Credential $creds -SaveCredentials

# define our vCenter service instance and performance manager.
$serviceInstance = Get-View ServiceInstance -Server $vCenter
$perfMgr = Get-View $serviceInstance.Content.PerfManager -Server $vCenter

# get all available performance counters
$counters = $perfMgr.PerfCounter

# create an array where we will store each of our custom objects that will contain the information that we want.
$metrics = @()

foreach ($counter in $counters) {
# create a custom Powershell object and define attributes such as the performance metric's name, rollup type, stat level, summary, etc
$metric = New-Object System.Object
$metric | Add-Member -type NoteProperty -name GroupKey   -value $counter.GroupInfo.Key
$metric | Add-Member -type NoteProperty -name NameKey    -value $counter.NameInfo.Key
$metric | Add-Member -type NoteProperty -name Rolluptype -value $counter.RollupType
$metric | Add-Member -type NoteProperty -name Level      -value $counter.Level
$metric | Add-Member -type NoteProperty -name FullName   -value "$($counter.GroupInfo.Key).$($counter.NameInfo.Key).$($counter.RollupType)"
$metric | Add-Member -type NoteProperty -name Summary    -value $counter.NameInfo.Summary

# add the custom object to our array
$metrics += $metric

# each metric object will look simliar to the following.  We can use a select command to gather which attributes we want and export them to a CSV file.
#   GroupKey   : vsanDomObj
#   NameKey    : writeAvgLatency
#   Rolluptype : average
#   Level      : 4
#   FullName   : vsanDomObj.writeAvgLatency.average
#   Summary    : Average write latency in ms

$metrics | select fullname, level, summary | Export-Csv -NoTypeInformation $outputFile

You can view the results on my vCenter 6.0 appliance here.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s