11 Replies Latest reply on Nov 12, 2019 12:45 PM by LucD

    get cluster utilization info

    tdubb123 Master

      hi,

       

      how do I modify the below to show cluster name as well

       

       

      $clusters = get-cluster

      foreach ($clustername in $clusters) {

      $days = 30

      $start = (Get-Date).AddDays(- $days)

      $stat = "cpu.usage.average","mem.usage.average","mem.vmmemctl.average",

        "mem.shared.average","mem.active.average","mem.swapused.average"

       

      $cluster = get-cluster -name $clustername

      $esx = Get-VMHost -Location $cluster

      Get-Stat -Entity $esx -Start $start -Stat $stat |

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

      Select @{N="Cluster";E={$cluster.Name}},

          @{N="VMHost";E={$_.Name}},

          @{N="Total memory";E={$_.Group[0].Entity.MemoryTotalGB}},

          @{N="Total CPU";E={$_.Group[0].Entity.NumCpu}},

          @{N="Average memory used";E={$_.Group | Where {$_.MetricId -eq "mem.usage.average"} |

            Measure-Object -Property Value -Average | Select -ExpandProperty Average}},

          @{N="Average CPU used";E={$_.Group | Where {$_.MetricId -eq "cpu.usage.average" -and $_.Instance -eq ""} |

            Measure-Object -Property Value -Average | Select -ExpandProperty Average}},

          @{N="Average memory ballooning";E={$_.Group | Where {$_.MetricId -eq "mem.vmmemctl.average"} |

            Measure-Object -Property Value -Average | Select -ExpandProperty Average}},

          @{N="Average shared memory";E={$_.Group | Where {$_.MetricId -eq "mem.shared.average"} |

            Measure-Object -Property Value -Average | Select -ExpandProperty Average}},

          @{N="Average active used";E={$_.Group | Where {$_.MetricId -eq "mem.active.average"} |

            Measure-Object -Property Value -Average | Select -ExpandProperty Average}},

          @{N="Average memory swapped";E={$_.Group | Where {$_.MetricId -eq "mem.swapused.average"} |

            Measure-Object -Property Value -Average | Select -ExpandProperty Average}} | export-csv "c:\scripts\clusterreport.csv" -notypeInformation

      }

        • 1. Re: get cluster utilization info
          tdubb123 Master

          I keep getting the error:

           

          Screen Shot 2016-09-27 at 3.42.30 PM.png

          • 2. Re: get cluster utilization info
            LucD Guru
            vExpertUser ModeratorsCommunity Warriors

            Try like this

            Note that some of the metrics you are using require Statistics Level 4 for Historical Interval 3 (Past Month)

             

            $days = 30

            $start = (Get-Date).AddDays(- $days)

            $stat = "cpu.usage.average","mem.usage.average","mem.vmmemctl.average",

              "mem.shared.average","mem.active.average","mem.swapused.average"

             

            $report = foreach ($cluster in Get-Cluster) {

                $esx = Get-VMHost -Location $cluster

                Get-Stat -Entity $esx -Start $start -Stat $stat |

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

                select @{N="Cluster";E={$cluster.Name}},

                    @{N="VMHost";E={$_.Name}},

                    @{N="Total memory";E={$_.Group[0].Entity.MemoryTotalGB}},

                    @{N="Total CPU";E={$_.Group[0].Entity.NumCpu}},

                    @{N="Average memory used";E={$_.Group | Where {$_.MetricId -eq "mem.usage.average"} |

                      Measure-Object -Property Value -Average | Select -ExpandProperty Average}},

                    @{N="Average CPU used";E={$_.Group | Where {$_.MetricId -eq "cpu.usage.average" -and $_.Instance -eq ""} |

                      Measure-Object -Property Value -Average | Select -ExpandProperty Average}},

                    @{N="Average memory ballooning";E={$_.Group | Where {$_.MetricId -eq "mem.vmmemctl.average"} |

                      Measure-Object -Property Value -Average | Select -ExpandProperty Average}},

                    @{N="Average shared memory";E={$_.Group | Where {$_.MetricId -eq "mem.shared.average"} |

                      Measure-Object -Property Value -Average | Select -ExpandProperty Average}},

                    @{N="Average active used";E={$_.Group | Where {$_.MetricId -eq "mem.active.average"} |

                      Measure-Object -Property Value -Average | Select -ExpandProperty Average}},

                    @{N="Average memory swapped";E={$_.Group | Where {$_.MetricId -eq "mem.swapused.average"} |

                      Measure-Object -Property Value -Average | Select -ExpandProperty Average}}

            }

             

            $report | export-csv "c:\scripts\clusterreport.csv" -notypeInformation

             

            • 3. Re: get cluster utilization info
              tdubb123 Master

              Hi LUcd

               

              I am getting the same error

               

              Screen Shot 2016-09-28 at 6.19.08 AM.png

              • 4. Re: get cluster utilization info
                LucD Guru
                vExpertUser ModeratorsCommunity Warriors

                Do you have an empty cluster in your environment?

                A cluster with no ESXi nodes.

                 

                Can you eventually try with a specific cluster (Get-Cluster -Name MyCluster)?

                • 5. Re: get cluster utilization info
                  tdubb123 Master

                  yes I have some empty clusters. IF I do it per cluster it works fine. but I need to get all the hosts from each cluster

                  • 6. Re: get cluster utilization info
                    LucD Guru
                    vExpertUser ModeratorsCommunity Warriors

                    Since there are no ESXi nodes in an empty cluster, you could just generate an entry with the clustername.

                    Something like this

                     

                    $days = 30

                    $start = (Get-Date).AddDays(- $days)

                    $stat = "cpu.usage.average","mem.usage.average","mem.vmmemctl.average",

                      "mem.shared.average","mem.active.average","mem.swapused.average"

                     

                    $report = foreach ($cluster in Get-Cluster) {

                        $esx = Get-VMHost -Location $cluster

                        if($esx){

                            Get-Stat -Entity $esx -Start $start -Stat $stat |

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

                            select @{N="Cluster";E={$cluster.Name}},

                                @{N="VMHost";E={$_.Name}},

                                @{N="Total memory";E={$_.Group[0].Entity.MemoryTotalGB}},

                                @{N="Total CPU";E={$_.Group[0].Entity.NumCpu}},

                                @{N="Average memory used";E={$_.Group | Where {$_.MetricId -eq "mem.usage.average"} |

                                  Measure-Object -Property Value -Average | Select -ExpandProperty Average}},

                                @{N="Average CPU used";E={$_.Group | Where {$_.MetricId -eq "cpu.usage.average" -and $_.Instance -eq ""} |

                                  Measure-Object -Property Value -Average | Select -ExpandProperty Average}},

                                @{N="Average memory ballooning";E={$_.Group | Where {$_.MetricId -eq "mem.vmmemctl.average"} |

                                  Measure-Object -Property Value -Average | Select -ExpandProperty Average}},

                                @{N="Average shared memory";E={$_.Group | Where {$_.MetricId -eq "mem.shared.average"} |

                                  Measure-Object -Property Value -Average | Select -ExpandProperty Average}},

                                @{N="Average active used";E={$_.Group | Where {$_.MetricId -eq "mem.active.average"} |

                                  Measure-Object -Property Value -Average | Select -ExpandProperty Average}},

                                @{N="Average memory swapped";E={$_.Group | Where {$_.MetricId -eq "mem.swapused.average"} |

                                  Measure-Object -Property Value -Average | Select -ExpandProperty Average}}

                        }

                        else{

                            $cluster | select @{N="Cluster";E={$_.Name}},

                                @{N="VMHost";E={}},

                                @{N="Total memory";E={}},

                                @{N="Total CPU";E={}},

                                @{N="Average memory used";E={}},

                                @{N="Average CPU used";E={}},

                                @{N="Average memory ballooning";E={}},

                                @{N="Average shared memory";E={}},

                                @{N="Average active used";E={}},

                                @{N="Average memory swapped";E={}}

                        }

                    }

                     

                    $report | export-csv "c:\scripts\clusterreport.csv" -notypeInformation

                     

                    • 7. Re: get cluster utilization info
                      tdubb123 Master

                      lucd

                       

                      got this error

                       

                      Screen Shot 2016-09-28 at 7.22.29 AM.png

                      • 8. Re: get cluster utilization info
                        LucD Guru
                        vExpertUser ModeratorsCommunity Warriors

                        The 'i' in if was not a normal 'i'.

                        I corrected it above, please try again.

                        • 9. Re: get cluster utilization info
                          tdubb123 Master

                          Thanks Lucd

                          • 10. Re:Solved: get cluster utilization info
                            markshannon Novice

                            Hi LucD. 

                            How would I get this only for Mon-Fri in a month? 

                            Thanks in advance 

                            Mark

                            • 11. Re:Solved: get cluster utilization info
                              LucD Guru
                              vExpertCommunity WarriorsUser Moderators

                              With an additional Where-clause after the Get-Stat.
                              See an examples in my PowerCLI & VSphere Statistics – Part 2 – Come Together post.

                              More specifically the one which uses $_.Timestamp.DayOfWeek