VMware Cloud Community
pe4kin
Enthusiast
Enthusiast
Jump to solution

Find out average CPU and memory utilization during period of time

Hi , there!

Can somebody help me with PowerCLI script to find out average CPU and Memory hosts utilization during period of time?

Thanks

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could do something like this

$now = Get-Date

$start = $now.AddDays(-7)

$finish = $now


$SStat = @{

   Entity = Get-VMHost

   Stat = 'cpu.usage.average', 'mem.usage.average'

   Start = $start

   Finish = $finish

   Instance = '*'

   ErrorAction = 'SilentlyContinue'

}

Get-Stat @sStat |

Group-Object -Property { $_.Entity.Name } |

ForEach-Object -Process {

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

   Host = $_.Name

   Start = $start

   Finish = $finish

   CpuAvgPerc = [math]::Round(($_.Group | where { $_.MetricId -eq 'cpu.usage.average' } | Measure-Object -Property Value -Average).Average, 1)

   MemAvgPerc = [math]::Round(($_.Group | where { $_.MetricId -eq 'mem.usage.average' } | Measure-Object -Property Value -Average).Average, 1)

   })

}

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

Was it helpful? Let us know by completing this short survey here.


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

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

You could do something like this

$now = Get-Date

$start = $now.AddDays(-7)

$finish = $now


$SStat = @{

   Entity = Get-VMHost

   Stat = 'cpu.usage.average', 'mem.usage.average'

   Start = $start

   Finish = $finish

   Instance = '*'

   ErrorAction = 'SilentlyContinue'

}

Get-Stat @sStat |

Group-Object -Property { $_.Entity.Name } |

ForEach-Object -Process {

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

   Host = $_.Name

   Start = $start

   Finish = $finish

   CpuAvgPerc = [math]::Round(($_.Group | where { $_.MetricId -eq 'cpu.usage.average' } | Measure-Object -Property Value -Average).Average, 1)

   MemAvgPerc = [math]::Round(($_.Group | where { $_.MetricId -eq 'mem.usage.average' } | Measure-Object -Property Value -Average).Average, 1)

   })

}

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

Was it helpful? Let us know by completing this short survey here.


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

Reply
0 Kudos
pe4kin
Enthusiast
Enthusiast
Jump to solution

Thanks, Luc.

But how can I get information for business hours in first 7 working days (per every day) in a specific month. And export it to xlsx.

Please help with a script.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I have a section on that in my PowerCLI & VSphere Statistics – Part 2 – Come Together post.


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

pe4kin
Enthusiast
Enthusiast
Jump to solution

Thanks, Luc. I'll try

Reply
0 Kudos