VMware Cloud Community
esxi1979
Expert
Expert
Jump to solution

cluster stats in last X days for CPU & memory

In below code :-

If i need to add memory & then consolidate both cpu & memory into xls how can i modify this script ?

$start = (Get-Date).Adddays(-1)

$clusters = Get-Cluster |Select -Last 1

Get-Stat -Entity $clusters -Start $start -Stat cpu.usage.average |

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

  $calc = $_.Group | Measure-Object -Property Value -Average -Minimum -Maximum

  New-Object PSObject -Property @{

    Name = $_.Name

    Start = $start

    CpuAvg =  $calc.Average

    CpuMin = $calc.Minimum

    CpuMax = $calc.Maximum

  }

}

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

That should have said $clusters (I corrected the code above)


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

View solution in original post

Reply
0 Kudos
5 Replies
esxi1979
Expert
Expert
Jump to solution

I got this working when i select single cluster

$start = (Get-Date).Adddays(-1)

#$clusters = Get-Cluster -location xx

$clusters = Get-Cluster  cluster1

foreach ($cluster  in $clusters)

{

Get-Stat -Entity $cluster -Start $start -Stat Mem.Usage.Average |`

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

   $calc = $_.Group | Measure-Object -Property Value -Average -Minimum -Maximum

   New-Object PSObject -Property @{

     Name = $_.Name

     StatsForLast7DaysFrom = $start

     MemoryAvg =  $calc.Average

     MemoryMin = $calc.Minimum

     MemoryMax = $calc.Maximum

                                    }

                                                   } |export-csv c:\clutser1.csv

}

But when i do

$start = (Get-Date).Adddays(-1)

$clusters = Get-Cluster -location xx

#$clusters = Get-Cluster  cluster1

foreach ($cluster  in $clusters)

{

Get-Stat -Entity $cluster -Start $start -Stat Mem.Usage.Average |`

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

   $calc = $_.Group | Measure-Object -Property Value -Average -Minimum -Maximum

   New-Object PSObject -Property @{

     Name = $_.Name

     StatsForLast7DaysFrom = $start

     MemoryAvg =  $calc.Average

     MemoryMin = $calc.Minimum

     MemoryMax = $calc.Maximum

                                    }

                                                   } |export-csv c:\clutserX.csv

}

The xls is empty ..

can someone Please take a look

Also the values return in above code are % of memory use looks, correct.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You are overwriting the same CSV file for each cluster.

But there is no need to have a loop over all the clusters, try like this

$start = (Get-Date).Adddays(-1)

$clusters = Get-Cluster -location xx

Get-Stat -Entity $clusters -Start $start -Stat Mem.Usage.Average |

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

   $calc = $_.Group | Measure-Object -Property Value -Average -Minimum -Maximum

   New-Object PSObject -Property @{

     Name = $_.Name

     StatsForLast7DaysFrom = $start

     MemoryAvg =  $calc.Average

     MemoryMin = $calc.Minimum

     MemoryMax = $calc.Maximum

    }

} |export-csv c:\clutserX.csv


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

Reply
0 Kudos
esxi1979
Expert
Expert
Jump to solution

i got error for this

Get-Stat : 12/1/2014 10:50:21 AM    Get-Stat        Value cannot be found for the mandatory parameter Entity

At line:1 char:9

+ Get-Stat <<<<  -Entity $cluster -Start $start -Stat Mem.Usage.Average |

    + CategoryInfo          : NotSpecified: (:) [Get-Stat], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetViStats

Reply
0 Kudos
esxi1979
Expert
Expert
Jump to solution

I think -Finish is missing

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That should have said $clusters (I corrected the code above)


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

Reply
0 Kudos