VMware Cloud Community
beckham007fifa
Jump to solution

power cli commands

guys,

can i get a command for pulling out reports having peak and average values of cpu and memory for all of esx hosts at a time?

please help.

Regards, ABFS
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could do something like this.

It will produce the metrics for the last day (you can play with the value you put in the $start variable.

And you could also use a combination of the Start and Finish parameters on the Get-Stat cmdlet.

$metrics = "cpu.usage.average","mem.usage.average" 
$esx
= Get-VMHost
$start
= (Get-Date).AddDays(-1) $stats = Get-Stat -Entity $esx -Stat $metrics -Start $start
$stats
| Group-Object -Property EntityId | %{     $cpuStat = $_.Group | where {$_.MetricId -eq "cpu.usage.average"} | Measure-Object -Property Value -Average -Maximum
   
$memStat = $_.Group | where {$_.MetricId -eq "mem.usage.average"} | Measure-Object -Property Value -Average -Maximum
    New-Object PSObject -Property @{         Name = $_.Group[0].Entity.Name         CpuMax = "{0:f2}" -f $cpuStat.Maximum         CpuAvg = "{0:f2}" -f $cpuStat.Average         MemMax = "{0:f2}" -f $memStat.Maximum         MemAvg = "{0:f2}" -f $memStat.Maximum     } }

It will display the result on screen.

If you want the results in a CSV file, you can do

$metrics = "cpu.usage.average","mem.usage.average" 
$esx
= Get-VMHost
$start
= (Get-Date).AddDays(-1) $stats = Get-Stat -Entity

$esx
-Stat $metrics -Start $start $stats | Group-Object -Property EntityId | %{     $cpuStat = $_.Group | where {$_.MetricId -eq "cpu.usage.average"} | Measure-Object -Property Value -Average -Maximum
    $memStat = $_.Group | where {$_.MetricId -eq "mem.usage.average"} | Measure-Object -Property Value -Average -Maximum
   
New-Object PSObject -Property @{         Name = $_.Group[0].Entity.Name         CpuMax = "{0:f2}" -f $cpuStat.Maximum         CpuAvg = "{0:f2}" -f $cpuStat.Average         MemMax = "{0:f2}" -f $memStat.Maximum         MemAvg = "{0:f2}" -f $memStat.Maximum     } } | Export-Csv "C:\esx-stat.csv" -NoTypeInformation -UseCulture


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

View solution in original post

0 Kudos
5 Replies
Troy_Clavell
Immortal
Immortal
Jump to solution

thread moved from VMware ESX™ 4 Community to VMware vSphere™ PowerCLI Community

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could do something like this.

It will produce the metrics for the last day (you can play with the value you put in the $start variable.

And you could also use a combination of the Start and Finish parameters on the Get-Stat cmdlet.

$metrics = "cpu.usage.average","mem.usage.average" 
$esx
= Get-VMHost
$start
= (Get-Date).AddDays(-1) $stats = Get-Stat -Entity $esx -Stat $metrics -Start $start
$stats
| Group-Object -Property EntityId | %{     $cpuStat = $_.Group | where {$_.MetricId -eq "cpu.usage.average"} | Measure-Object -Property Value -Average -Maximum
   
$memStat = $_.Group | where {$_.MetricId -eq "mem.usage.average"} | Measure-Object -Property Value -Average -Maximum
    New-Object PSObject -Property @{         Name = $_.Group[0].Entity.Name         CpuMax = "{0:f2}" -f $cpuStat.Maximum         CpuAvg = "{0:f2}" -f $cpuStat.Average         MemMax = "{0:f2}" -f $memStat.Maximum         MemAvg = "{0:f2}" -f $memStat.Maximum     } }

It will display the result on screen.

If you want the results in a CSV file, you can do

$metrics = "cpu.usage.average","mem.usage.average" 
$esx
= Get-VMHost
$start
= (Get-Date).AddDays(-1) $stats = Get-Stat -Entity

$esx
-Stat $metrics -Start $start $stats | Group-Object -Property EntityId | %{     $cpuStat = $_.Group | where {$_.MetricId -eq "cpu.usage.average"} | Measure-Object -Property Value -Average -Maximum
    $memStat = $_.Group | where {$_.MetricId -eq "mem.usage.average"} | Measure-Object -Property Value -Average -Maximum
   
New-Object PSObject -Property @{         Name = $_.Group[0].Entity.Name         CpuMax = "{0:f2}" -f $cpuStat.Maximum         CpuAvg = "{0:f2}" -f $cpuStat.Average         MemMax = "{0:f2}" -f $memStat.Maximum         MemAvg = "{0:f2}" -f $memStat.Maximum     } } | Export-Csv "C:\esx-stat.csv" -NoTypeInformation -UseCulture


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

0 Kudos
beckham007fifa
Jump to solution

Thankyou so much, I am proud to be here with such brilliance of this community.

Regards, ABFS
0 Kudos
andreasbrunner
Contributor
Contributor
Jump to solution

Hi Luc,

I wonder if it would be possible to get the peak and average just for a defined time period like working hours (e.g. between 8-18)

regards

Andreas

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Of course that is possible :smileygrin:

In this case it's a matter of passing the statistics through a where-clause.

Have a look at my PowerCLI & vSphere statistics – Part 2 – Come together post.

In the section, called Business hours/working days, I have a sample script that does exactly that.

Let me know should you have any problems applying that technique on this script


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

0 Kudos