PowerCLI

 View Only
  • 1.  Capturing CPU and MEM Usage

    Posted Sep 05, 2012 12:21 PM

    Hi,

    I run the below powercli code to capture the avg cpu and mem usage of the clusters by running the following:

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

    $statmem = Get-Stat -Entity ($cluster) -start (get-date).AddDays(-7) -Finish (Get-Date) -MaxSamples 10000 -stat mem.usage.average

    Now my question is suppose one of the host is placed in maintenance mode due to some maintenance activity then will the above code discard this host while capturing avg mem and cpu usage and if not then how to capture the avg mem and cpu usage of a cluster without considering the host which is placed into maintenance mode.



  • 2.  RE: Capturing CPU and MEM Usage

    Posted Sep 05, 2012 12:29 PM

    No, the time interval you specified (7 days back) will also include the ESXi that are currently in maintenance mode.

    The CPU and memory metrics for a cluster are aggregated metrics, in other words these metrics are calculated through the aggregation jobs that run on the DB server that hosts the vCenter DB. These metrics are not directly obtained from the ESXi nodes in the cluster.

    To exclude ESXi hosts that are in maintenance, you will have to do the aggregation yourself I'm afraid.

    Get all the ESXi hosts in the cluster, excluding the ones in maintenance, and calculate the average of the metrics that are returned.



  • 3.  RE: Capturing CPU and MEM Usage

    Posted Sep 05, 2012 12:33 PM

    Hi LucD,

    Thanks for your reply.

    Can you please give some sample code to get all the ESXi hosts in the cluster, excluding the ones in maintenance, and calculate the average of the metrics that are returned as I am not that good in powercli.



  • 4.  RE: Capturing CPU and MEM Usage

    Posted Sep 05, 2012 01:02 PM

    Try something like this

    $clusterName = "MyCluster"
    $esx = Get-Cluster -Name $clusterName | Get-VMHost | where {$_.State -eq "Connected"} $start = (Get-Date).AddDays(-7) $stats = Get-Stat -Entity $esx -Stat "cpu.usage.average" -Start $start $stats | where {$_.Instance -eq ""} | Group-Object -Property Timestamp | %{   New-Object PSObject -Property @{     Cluster = $clusterName
       
    Timestamp = $_.Values[0]     AvgCpu = $_.Group | Measure-Object -Property Value -Average |
         
    select -ExpandProperty Average
        Unit = $_.Group[0].Unit
        MetricId = $_.Group[0].MetricId
       
    Description = $_.Group[0].Description
       
    IntervalSecs = $_.Group[0].IntervalSecs
      } }

    This is only for the CPU average, but the memory average will be the same and could be done in 1 call to Get-Stat.