VMware Cloud Community
luketheyeti
Contributor
Contributor
Jump to solution

How to format get-stat output on multiple metrics

Hello!

I'm trying to format the output from get-stat with multiple metrics into a format I can graph easily in Excel.  What I get from the command is in the format:

MetricId                Timestamp                          Value Unit    

--------                ---------                          ----- ----     --------

cpu.usage.average       6/19/2018 5:25:00 PM                4.77 %               

cpu.usage.average       6/19/2018 5:20:00 PM                4.66 %               

cpu.usage.average       6/19/2018 5:15:00 PM                4.76 %               

cpu.usage.average       6/19/2018 5:10:00 PM                4.34 %               

cpu.usage.average       6/19/2018 5:05:00 PM                 4.3 %               

cpu.usagemhz.average    6/19/2018 5:25:00 PM                2633 MHz             

cpu.usagemhz.average    6/19/2018 5:20:00 PM                2569 MHz             

cpu.usagemhz.average    6/19/2018 5:15:00 PM                2626 MHz             

cpu.usagemhz.average    6/19/2018 5:10:00 PM                2394 MHz             

cpu.usagemhz.average    6/19/2018 5:05:00 PM                2372 MHz  

and what I want is something like:

Timestampcpu.usage.averagecpu.usagemhz.average
5:25:004.772633
5:20:004.662569
5:15:004.762626
5:10:004.342394
5:05:004.32372

Can someone point me towards the cmdlets that would accomplish this?

Thank you!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this

$esxName = 'MyEsx'

$stat = 'cpu.usage.average','cpu.usagemhz.average'

$esx = Get-VMHost -Name $esxName

Get-Stat -Entity $esx -Stat $stat -Instance '' -Realtime -MaxSamples 5 |

Group-Object -Property Timestamp | %{

   New-Object PSObject -Property ([ordered]@{

   Timestamp = $_.Name

   VMHost = $_.group[0].Entity.Name

   'cpu.usage.average' = $_.Group | where{$_.MetricId -eq 'cpu.usage.average'} | select -ExpandProperty Value

   'cpu.usagemhz.average' = $_.Group | where{$_.MetricId -eq 'cpu.usagemhz.average'} | select -ExpandProperty Value

   })

}

There are more 'grouping' examples in my Statistics posts.


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

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

$esxName = 'MyEsx'

$stat = 'cpu.usage.average','cpu.usagemhz.average'

$esx = Get-VMHost -Name $esxName

Get-Stat -Entity $esx -Stat $stat -Instance '' -Realtime -MaxSamples 5 |

Group-Object -Property Timestamp | %{

   New-Object PSObject -Property ([ordered]@{

   Timestamp = $_.Name

   VMHost = $_.group[0].Entity.Name

   'cpu.usage.average' = $_.Group | where{$_.MetricId -eq 'cpu.usage.average'} | select -ExpandProperty Value

   'cpu.usagemhz.average' = $_.Group | where{$_.MetricId -eq 'cpu.usagemhz.average'} | select -ExpandProperty Value

   })

}

There are more 'grouping' examples in my Statistics posts.


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

0 Kudos
luketheyeti
Contributor
Contributor
Jump to solution

Thanks Luc,

I actually spent a decent amount of last night looking at your posts on collecting stats and I think I finally understand what's going on with your uses of Group-Object and New-Object. I'm admittedly super new to working with anything other than default objects and default object properties so this was way over my head.

Thankfully, learning to manipulate data like this is going to completely change every piece of data I work with going forward :smileygrin:

Lucas

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Keep learning, and please come back if you have questions.


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

0 Kudos