VMware Cloud Community
astrolab
Contributor
Contributor
Jump to solution

Get-stat monthly CPU utilization

I am trying to get a report of how much CPU + Memory has been utilized by VMs in the last month. Being a PS newbie I have tried (for days) pasting several pieces of code I found in this forum together, no luck, the ugliness of my scripts is haunting me......just can't get the GET-stat cmdlet right. Could I get some help?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

It would help if you said what statistic values you like to see and in which format (on screen, TXT file, CSV file...)

In any case this a straightforward example that give the average CPU and Memory use for each VM over a 30 day period.

The output is not very pretty or usable, it's just to show you what is possible.

get-vm | %{
  Get-Stat -Entity ($vm) `
           -start (get-date).AddDays(-30) `
           -stat cpu.usage.average | select Entity, Timestamp, MetricId, Value, Unit
  Get-Stat -Entity ($vm) `
           -start (get-date).AddDays(-30) `
           -stat mem.usage.average | select Entity, Timestamp, MetricId, Value, Unit
}


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

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

It would help if you said what statistic values you like to see and in which format (on screen, TXT file, CSV file...)

In any case this a straightforward example that give the average CPU and Memory use for each VM over a 30 day period.

The output is not very pretty or usable, it's just to show you what is possible.

get-vm | %{
  Get-Stat -Entity ($vm) `
           -start (get-date).AddDays(-30) `
           -stat cpu.usage.average | select Entity, Timestamp, MetricId, Value, Unit
  Get-Stat -Entity ($vm) `
           -start (get-date).AddDays(-30) `
           -stat mem.usage.average | select Entity, Timestamp, MetricId, Value, Unit
}


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

0 Kudos
astrolab
Contributor
Contributor
Jump to solution

Luc, thanks for the quick reply. I was adding Export-Csv to output to csv format. The metric I was mostly intersted in was cpu.usagemhz.average and mem.usage.average

So it would look like this:

Get-VIServer -Server <server> -User <user> -Password <pw> get-vm | %{ Get-Stat -Entity ($vm) ` -start (get-date).AddDays(-30) ` -stat cpu.usage.average | select Entity,

Timestamp, MetricId, Value, Unit Get-Stat -Entity ($vm) ` -start (get-date).AddDays(-30) ` -stat

mem.usage.average | select Entity, Timestamp, MetricId, Value, Unit }

0 Kudos
astrolab
Contributor
Contributor
Jump to solution

Sorry, can't get it to work....the PowerGui debugger reports A parameter cannot be found that matches parameter name ' -start'.

0 Kudos
Rajeev_S
Expert
Expert
Jump to solution

Hi, you need to type the script in the next line after using the symbol ` This symbol determines the continuation of the script in next line. If you type the script in the same line you need to remove the symbol '

This might be the issue. Hope this helps.

astrolab
Contributor
Contributor
Jump to solution

Thanks for the reply. So, I am struggling a bit. THis is what my (not really ) script looks like at the moment:

get-viserver -server <server> -credentials (get-credential) get-vm | %{ Get-Stat -Entity ($vm) `

-start (get-date).AddDays(-30) -stat cpu.usage.average | select Entity, Timestamp, MetricId, Value, Unit Get-Stat `

-Entity ($vm) -start (get-date).AddDays(-30) -stat mem.usage.average | select Entity, Timestamp, MetricId, Value, Unit}

Debugger spits out: A parameter cannot be found that matches parameter name 'Get-Stat'

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The forum SW seems to act up with some browsers.

I attached the script to make sure you get the correct version.


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