VMware Cloud Community
jmsloane
Contributor
Contributor

PowerCLI script for gathering data metrics for $fullname, please help!

@Not sure where I found this script but it is quite amazing! I would like to modify this script to get all of the available metrics and values for each of the $fullname variables. I am new to PowerCLI and the terminology but the output of this script shows all variables, the levels and the definition as it states in the script memos. I need to gather all of the vmhost averages and values. I would love to be able to configure the script to also show the values in %'s / gb / ms etc etc. Please help? I know the output currently generates an error, I am unable to get the values from the fullnames.

# define where we will save our performance metrics.   

Tags (1)
15 Replies
LucD
Leadership
Leadership

That script has some serious flaws, not sure how someone ever got it to run and produce some output.

The script seems to query all Realtime performance metrics for all ESXi nodes over 1 hour, and then average the returned values.

I'm not sure what the purpose of that exercise would be.

Further, not all performance metrics are available for ESXi nodes, some are intended for clusters, VMs, datastores...
So you will most probably get some errors there as well.

Perhaps you can explain what exactly do you want to report upon?

Which performance metrics? And that for each ESXi node individually, or an average over all ESXi nodes?


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

Reply
0 Kudos
jmsloane
Contributor
Contributor

LucD,

If i removed the average line it would produce a listing of all the metrics on the hosts. I would love to be able to run one script that measures all of the measurable data points. Kavg, gavg, davg, read write, cmds, latencies. I would like to get a spreadsheet that shows all of the available data points that have any values to use as a baseline datapoint for daily statistics. Sorry I am having issues really explaining what I am looking for.

Basically I need any available measurable data points and their averages for points in time, example: i'd run this script in the morning, during high traffic and before i leave. We will take these to compare when we move over to our new 3par to have something to compare against for our networks daily averages.

I have included the output file from when I had the basic script working. I need the values/averages for the FullName column and possibly have it translated to gb/mb/ms/% but is not required.

I want to run this script to scan all of my hosts.

Reply
0 Kudos
LucD
Leadership
Leadership

I;m afraid that first sentence "If i removed the average line it would produce a listing of all the metrics on the hosts." shows where the confusion is.

Yes, that would give you a list of all performance counters collected by the ESXi nodes.

But not all performance counters make sens for ESXi nodes.

For example, the counter clusterservices.cpufairness.latest makes no sense for an ESXi node, you will get an error on that Get-Stat cmdlet.

All the performance counters that are collected are documented on the PerformanceManager page.

You could also have a look at my Stats Toolbox post which shows those performance counters in a somewhat friendlier way.

You could limit to specific groups of performance counters, but even that would cause errors.

For example, in the cpu group, the cpu.corecount.provisioned.average metrics is only intended for Resourcepools.

Only metrics that have the indication HostSystem makes sense for ESXi nodes.

cpuperf.png

So I repeat my question, which metrics do you need to collect to be able to evaluate the performance before and after the 3Par migration.


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

jmsloane
Contributor
Contributor

LucD,

I am sorry, I am incredibly new at this.

I would like to gather cpu, mem, I/O, usage averages, esxtop outputs as well such as DAVG, KAVG, read/write and latency statistics.

Thank you for the page link, I will read through that as I await your response.

I was using this and running down the list of the FullName that is generated with the original script and recording anything that was actually generating a result but that is over 300 entries to attempt.

get-vmhost | Select Name, @{n="AVG Max Latency (ms)";e={[Math]::round((get-stat -Entity $_ -Stat Disk.queuelatency.average -Start (Get-Date).AddDays(-7) -Realtime | Measure Value -Average ).Average)}}

Reply
0 Kudos
LucD
Leadership
Leadership

Ok, let's keep the regular performance data and esxtop data separate for now, they require 21 completely ways of getting the data.

In the meantime, the following script uses the QueryAvailablePerfMetric method to limit the performance counters to ESXi nodes.

In a normal environment this gives about 500+ performance counters.

Note that for the last hour you fall in the Readtime interval, which means that all performance counters are available, no impact from the Statistics Levels.

Have a look at the list. For most metrics there is an average, minimum and maximum.

Do you actually need those?

And what do you do with rollup types like summation, latest...

It makes absolutely no sense to average these values over an hour.

You could look at the deltas of these metrics, and average those.

$vCenter = 'MyVC'

$si = Get-View ServiceInstance -Server $vCenter

$perfMgr = Get-View -Id $si.Content.PerfManager

$esx = Get-VMHost

$metricsRaw = $perfMgr.QueryAvailablePerfMetric($esx[0].ExtensionData.MoRef,$null,$null,20)

$metricsId = $metricsRaw.CounterId | Sort-Object -Unique

$metricTab = @{}

$perfMgr.PerfCounter | %{

    if($_.RollupType -ne 'none'){

        $metricTab.Add($_.Key,("{0}.{1}.{2}" -f ($_.GroupInfo.Key,$_.NameInfo.Key,$_.RollupType)))   

    }

}

$metricTab.GetEnumerator()


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

Reply
0 Kudos
jmsloane
Contributor
Contributor

I get this error message     Exception calling "Add" with "2" argument(s): "Item has already been added. Key in dictionary: '593'  Key being added: '593'"     At line:25 char:9     +        $metricTab.Add($_.Key,("{0}.{1}.{2}" -f ($_.GroupInfo.Key,$_. ...     +        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException     + FullyQualifiedErrorId : ArgumentException The end result of what I am going for is a script that will get the most important metrics from. I know of the few scripts out there that will give me standard metric points but I was hoping to find other data points that might give us a broad understanding of exactly how each host is functioning and what the averages are for its performance. I want to take all of these data points to a spreadsheet for when the 3par is set up and we move to the new environment. I want to be able to compare as many data points from the old environment to the new one to see if/how much different their performance is. This script basically just told me the 600+ counters available. As for your question in regards to do i need the min and max? I dont believe so, but wouldn't hurt to have them. Also, I guess having it scan for over the past 24 hours would be good. That way it covers all the time its been running.

Reply
0 Kudos
LucD
Leadership
Leadership

Which vSphere version is that?

There is an issue with duplicate performance counter IDs in older versions.

In any case, try like this

$vCenter = 'MyVC'

$si = Get-View ServiceInstance -Server $vCenter

$perfMgr = Get-View -Id $si.Content.PerfManager

$esx = Get-VMHost

$metricsRaw = $perfMgr.QueryAvailablePerfMetric($esx[0].ExtensionData.MoRef,$null,$null,20)

$metricsId = $metricsRaw.CounterId | Sort-Object -Unique

$metricTab = @{}

$perfMgr.PerfCounter | %{

   if($_.RollupType -ne 'none' -and -not $metricTab.ContainsKey($_.Key) ){

   $metricTab.Add($_.Key,("{0}.{1}.{2}" -f ($_.GroupInfo.Key,$_.NameInfo.Key,$_.RollupType)))

   }

}

$metricTab.GetEnumerator()

Your new requirement to have this over the last 24 hours, vs the last hour, changes the playing field.

The last 24 hours means that you now look at the Past Day historical interval.

Then it depends on the setting of the Statistics Level for that interval on how many performance metrics are kept in the vCenter DB.

At what value is the Statistics Level set in your environment?

Also note that with the Historical interval you get additional performance metrics.
In the aggregation steps on the vCenter metrics for clusters and resourcepools are added.

The drawback is that the Past Day interval uses 5 minute intervals (vs the 20 second intervals of the Realtime interval). So you loose some granularity, in other words peaks will be a bit less outspoken.


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

Reply
0 Kudos
jmsloane
Contributor
Contributor

Same weird error message, it comes out with the common names and in reverse order. We are on vSphere 6.5

Reply
0 Kudos
LucD
Leadership
Leadership

Are you perhaps connected to more than 1 vSphere server?

Check what is in $global:defaultviservers


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

Reply
0 Kudos
jmsloane
Contributor
Contributor

No Sir,

Originally I would run the script that connects me then disconnects me from our 3 vcenters.

Reply
0 Kudos
LucD
Leadership
Leadership

Can you run with the additional debugging line, and give the lines before and after the error occurs?

$vCenter = 'MyVC'

$si = Get-View ServiceInstance -Server $vCenter

$perfMgr = Get-View -Id $si.Content.PerfManager

$esx = Get-VMHost

$metricsRaw = $perfMgr.QueryAvailablePerfMetric($esx[0].ExtensionData.MoRef,$null,$null,20)

$metricsId = $metricsRaw.CounterId | Sort-Object -Unique

$metricTab = @{}

$perfMgr.PerfCounter | %{

   Write-Host "Key $($_.Key)"

   if($_.RollupType -ne 'none' -and -not $metricTab.ContainsKey($_.Key) ){

   $metricTab.Add($_.Key,("{0}.{1}.{2}" -f ($_.GroupInfo.Key,$_.NameInfo.Key,$_.RollupType)))

   }

}

$metricTab.GetEnumerator()


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

Reply
0 Kudos
jmsloane
Contributor
Contributor

Attached the reports.

Reply
0 Kudos
LucD
Leadership
Leadership

Sorry, but I don't see that error you said was there.


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

Reply
0 Kudos
jmsloane
Contributor
Contributor

I had to open powershell cli and connect to one viserver in order to run the script you posted.

Reply
0 Kudos
LucD
Leadership
Leadership

But you told me "same weird error" earlier.
How many vCenters were you connected to at that moment?


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

Reply
0 Kudos