VMware Cloud Community
bolsen
Enthusiast
Enthusiast

How to use Get-stat for performance averages?

All,

I'm trying to write a script that queries performance stats over a 1 week period of time. Is it possible to report performance stats (such as avg memory / CPU used) at a host/cluster level instead of a host level? If I have to query the stats at the host level, how can I report them as one number (instead of individual numbers for each host)?

0 Kudos
7 Replies
bolsen
Enthusiast
Enthusiast

This is the syntax I'm working with and I can't get it to return a value. 😕

get-vmhost $hostname | get-stat -Stat cpu.usage.average -MaxSamples 9999 -Start (get-date).adddays(-7) -Finish (get-date)

0 Kudos
LucD
Leadership
Leadership

The data you can get via the Get-Stat cmdlet is determined by:

1) the available statistics for each type of resource (see Appendix A in the Programming Guide.

2) what is collected and kept by the VC (see

In your example this would work:

get-stat -Entity (Get-Cluster -Name <cluster-name>) -Stat cpu.usagemhz.average -MaxSamples 9999 -Start (get-date).adddays(-7) -Finish (get-date)

In Appendix A you can find that "usage" is only collected for virtual machines and hosts.

The counter "usagemhz" is also collected for compute resources and hence a cluster.

If you want the cpu.usage.average for a cluster you would have to do some calculus based on the data you get for all the cluster-nodes (hosts).


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

0 Kudos
Niket
Enthusiast
Enthusiast

Hi,

Please use the below script

$hostname = get-viserver -server

Get-Stat -Entity (Get-VMHost) -Stat cpu.usagemhz.average -MaxSamples 9999 -Start (get-date).adddays(-7) -Finish (get-date)

I hope it resolve your issue of output.

Thanks

Niket

0 Kudos
admin
Immortal
Immortal

This is the syntax I'm working with and I can't get it to return a value. 😕

get-vmhost $hostname | get-stat -Stat cpu.usage.average -MaxSamples 9999 -Start (get-date).adddays(-7) -Finish (get-date)

First question, are you using VC? ESX hosts don't keep that much information as far as I know.

If you are using VC, try tweaking the -intervalmins parameter of get-stat. Based on how VC does rollups there is often no data at the granularity corresponding to the default value of intervalmins (which, I believe, is 60). Good values to try are 12 hours (-intervalmins 720) and 24 hours (-intervalmins 1440).

P.S. this is something we're trying to improve for our GA release. I've had this problem quite a number of times myself.

0 Kudos
nnedev
VMware Employee
VMware Employee


Realtime statistics

You can alway get output for powered on VM if you run "Get-Stats -Realtime".

-


Non realtime statistics

For statistics that are not realtime by default sampling intervals are:

5 minutes (statistics are kept for 1 day)

30 minutes (statistics are kept for 1 week)

120 minutes (2 hours) (statistics are kept for 1 month)

1440 minutes (1 day) (statistics are kept for 1 year)

So good values for -IntervalMins parameter are 5, 30, 120, 1440. I suggest 5 because this is the smallest interval and samples are generated every 5 minutes.

-


Vi Client

You can see/edit sampling intervals from VI Client -&gt; Administration menu -&gt; Virtual Center Management Server Configuration... -&gt; Statistics

You can see statistics when you select entity and click on performance tab

You can use VI Client to see if you have statistics with specific sampling interval. Click on "Change Chart Options" and select time span. If you see output for "Past Day" you'll get output from "Get-Stat -IntervalMins 5".

-


Note

When the VM is not powered on no statistics are generated.

Regards, Nedko Nedev PowerCLI Development Team
0 Kudos
LucD
Leadership
Leadership

The Get-Stat cmdlet still seems to have a lot of pecularities.

I did a quick report on the memory statistics for VMHosts that can be obtained via the Get-Stat -Stat mem.... variant of the cmdlet.

See attached html file.

The results were a bit surprising to say the least.

1) Realtime statistics only seem to return averages

2) the sysUsage and reservedCapacity type don't seem to return anything at all

3) The IntervalMins parameter seems to switch the reported interval on other values then those that were mentioned before.

For example: when you specify 780 for IntervalMins you get statistics at 2 hour intervals, when you specify 781 you get statistics at 24 hour intervals

4) where are the 20 second interval statistics coming from. Obviously not the VC. Directly from the VMHost ?

If someone feels intrigued, don't hold back doing a similar exercise for the other statistics that are available.

cpu, rescpu, mem (for the other available entities), net, disk, sys, clusterServices.


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

0 Kudos
kaizenwerks
Contributor
Contributor

I ran into two issues when I tried obtaining the same statistics for ESXi hosts..

1)

When I run "Get-Stat -Entity (Get-VMHost) -Stat cpu.usagemhz.average

-IntervalMins 120 | Export-Csv c:\VMware_HostUsage2.csv" when

connecting to a VC server, it only runs against ESX servers

successfully and when it tries to run against ESXi servers it returns

with:

-


Get-Stat : 9/21/2009 4:18:50 PM Get-Stat The metric counter "cpu.usagemhz.average" doesn't exist for entity "server".

-


2) Interestingly

enough when I run the same line directly to a ESXi server, it runs but

with one caveat. No matter how I alter the IntervalMins it always

defaults to 20 seconds and outputs only 1hr of data.

Perhaps I am experiencing a similar result to what LucD did in his 4th point.

Any thoughts? Thanks in advance.

0 Kudos