VMware Cloud Community
bobbinspenguin
Contributor
Contributor
Jump to solution

Get-Cluster memory and cpu performance details

I'm trying to write a script to generate charts based on average memory and cpu usage over the period of the previous month, but I'm trying to do this for each cluster itself without explicity naming them. The chart bit aside (I can use mschart or googlechart for that) I just need to get the actual stats and that's the bit I'm having trouble with because everything I'm seeing with my research pulls the information from the individual VMs or hosts within the cluster.

I'm looking for two values in each case - cluster name and average usage. But the average usage being for the cluster overall and not the indivdual VMs.

I've been looking at this:

powercli script to capture cpu & mem usage stats

But that one uses hosts.

I've attached an image of something I'm looking for, the red line being average in percent and the blue line being average in megabytes. This was exported from vcenter though. I'm just trying to save time.

Thanks in advance

Reply
0 Kudos
1 Solution

Accepted Solutions
MKguy
Virtuoso
Virtuoso
Jump to solution

To get one average datapoint per day you can just add -Interval 86400 to the Get-Stat statement:

Get-Stat -Entity (Get-Cluster Cluster) -Stat $metrics -Start $start -Finish $finish -Interval 86400
MetricId                Timestamp                          Value Unit     Instance
--------                ---------                          ----- ----     --------
cpu.usagemhz.average    14.05.2014 02:00:00                 4298 MHz
cpu.usagemhz.average    13.05.2014 02:00:00                 4109 MHz
cpu.usagemhz.average    12.05.2014 02:00:00                 4163 MHz
cpu.usage.average       14.05.2014 02:00:00                10,74 %        *
cpu.usage.average       13.05.2014 02:00:00                10,27 %        *
cpu.usage.average       12.05.2014 02:00:00                10,41 %        *

Note that it might not include the values of the past day since the database rollup task for daily statistics hasn't run yet.

-- http://alpacapowered.wordpress.com

View solution in original post

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

You can provide a cluster as an Entity parameter, provided you don't ask for Realtime data.

The cluster counters are aggregated data and start in Historical Interval 1

A sample

$stat = "cpu.usage.average"
$entity = Get-Cluster
$start = (Get-Date).AddDays(-7)

Get-Stat -Entity $entity -Start $start -Stat $stat |
Group-Object -Property {$_.Entity.Name} |
Select Name,
   
@{N="CPU average";E={$_.Group | Measure-Object -Property Value -Average | Select -ExpandProperty Average}}


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

Reply
0 Kudos
bobbinspenguin
Contributor
Contributor
Jump to solution

LucD - I appreciate the response and it looks similar to some AD querying I've done in PowerShell, but it doesn't actually produce any results unless you tell it what to output. I'm not sure what to use to pick out the values I need. I'm guessing something along the lines of entity.average and entity.name but as these aren't producing anything could you help me out please?

Thanks

Reply
0 Kudos
bobbinspenguin
Contributor
Contributor
Jump to solution

The above didn't quite work for me but the following code returns the stats for the cluster I need, but does so on a 30 minute interval. I need it to return one per day over the course of a month. Have you got any idea how to accomplish this?

$metrics = "cpu.usagemhz.average", "cpu.usage.average"

$start = (get-date).AddDays(-5)

$finish = get-date

Get-Stat -Entity (Get-Cluster Cluster) -Stat $metrics -Start $start -Finish $finish

This is a test environment without enough data to report too far back so I'll change AddDays -5 to AddMonths -1 when I've got it sorted but how to return one result per day?

Thanks

Reply
0 Kudos
MKguy
Virtuoso
Virtuoso
Jump to solution

To get one average datapoint per day you can just add -Interval 86400 to the Get-Stat statement:

Get-Stat -Entity (Get-Cluster Cluster) -Stat $metrics -Start $start -Finish $finish -Interval 86400
MetricId                Timestamp                          Value Unit     Instance
--------                ---------                          ----- ----     --------
cpu.usagemhz.average    14.05.2014 02:00:00                 4298 MHz
cpu.usagemhz.average    13.05.2014 02:00:00                 4109 MHz
cpu.usagemhz.average    12.05.2014 02:00:00                 4163 MHz
cpu.usage.average       14.05.2014 02:00:00                10,74 %        *
cpu.usage.average       13.05.2014 02:00:00                10,27 %        *
cpu.usage.average       12.05.2014 02:00:00                10,41 %        *

Note that it might not include the values of the past day since the database rollup task for daily statistics hasn't run yet.

-- http://alpacapowered.wordpress.com
Reply
0 Kudos
greybear1223
Contributor
Contributor
Jump to solution

Lucd - I too have a question on how to aggregate the results for a cluster.  Here is the script I am running, but the numbers that are received when totaled up don't equal the same value on the performance chart for Max CPU Usage in MHZ.

$allvms = @()

$allhosts = @()

$hosts = Get-VMHost

$vms = Get-Vm

foreach($vmHost in $hosts){ 

  $hoststat = "" | Select HostName, Cluster, CPUMax, CPUAvg, CPUMin

  $hoststat.HostName = $vmHost.name

  $hoststat.Cluster = $cluster

 

  $statcpu = Get-Stat -Entity ($vmHost)-start (get-date).AddDays(-7) -Finish (Get-Date)-MaxSamples 10000 -stat cpu.usagemhz.average

  $cpu = $statcpu | Measure-Object -Property value -Average -Maximum -Minimum

  $cluster = (Get-Cluster -VMHost $vmHost).Name

  $hoststat.CPUMax = [int]$cpu.Maximum

  $hoststat.CPUAvg = [int]$cpu.Average

  $hoststat.CPUMin = [int]$cpu.Minimum

  $hoststat.Cluster = $cluster

  $allhosts += $hoststat

}

$allhosts | Select HostName, Cluster, CPUMax, CPUAvg, CPUMin | Export-Csv "c:\Hosts.txt" -Delimiter ";" -NoTypeInformation

This script produces the following output:

"HostName";"Cluster";"CPUMax";"CPUAvg";"CPUMin"

"hostclust1-1.vm.local";"Cluster1";"46376";"6292";"4684"

"hostclust1-2.vm.local";"Cluster1";"49635";"7401";"5792"

"hostclust1-3.vm.local";"Cluster1";"51518";"6223";"4475"

"hostclust1-4.vm.local";"Cluster1";"55879";"6756";"4742"

"hostclust1-5.vm.local";"Cluster1";"53818";"6757";"4836"

"hostclust1-6.vm.local";"Cluster1";"57784";"5578";"3771"

"hostclust1-7.vm.local";"Cluster1";"54190";"5567";"3496"

"hostclust1-8.vm.local";"Cluster1";"50340";"6571";"4392"

"hostclust1-9.vm.local";"Cluster1";"58277";"7059";"3895"

"hostclust1-10.vm.local";"Cluster1";"60654";"5089";"3275"

"hostclust1-11.vm.local";"Cluster1";"49669";"6353";"4094"

"hostclust1-12.vm.local";"Cluster1";"42946";"5789";"3769"

"hostclust1-13.vm.local";"Cluster1";"50591";"7800";"5501"

"hostclust1-14.vm.local";"Cluster1";"49325";"5844";"3986"

"hostclust1-15.vm.local";"Cluster1";"60623";"5666";"2485"

"hostclust1-16.vm.local";"Cluster1";"51526";"4869";"3002"

"hostclust2-1.vm.local";"Cluster2";"17465";"2881";"2197"

"hostclust2-2.vm.local";"Cluster2";"28154";"6198";"3962"

"hostclust2-3.vm.local";"Cluster2";"35138";"5819";"4300"

"hostclust2-4.vm.local";"Cluster2";"19091";"2742";"1762"

"hostclust2-5.vm.local";"Cluster2";"24800";"3293";"2481"

"hostclust2-6.vm.local";"Cluster2";"24044";"3093";"2218"

"hostclust2-7.vm.local";"Cluster2";"22093";"2518";"1949"

"hostclust2-8.vm.local";"Cluster2";"20515";"2296";"1850"

"hostclust2-9.vm.local";"Cluster2";"38523";"6052";"4516"

"hostclust2-10.vm.local";"Cluster2";"18869";"3215";"2401"

"hostclust2-11.vm.local";"Cluster2";"20174";"3639";"3010"

"hostclust2-12.vm.local";"Cluster2";"18870";"2411";"1655"

What would I change to give me an output of the following:

"Cluster";"CPUMax";"CPUAvg";"CPUMin"

"Cluster1";"this is max total for all hosts in cluster";"this is average for all hosts in cluster";"This is the min for all hosts in cluster"

"Cluster2";"this is max total for all hosts in cluster";"this is average for all hosts in cluster";"This is the min for all hosts in cluster"

Thanks in advance

Greybear1223

Reply
0 Kudos