Automation

 View Only
  • 1.  Cluster health script

    Posted Aug 22, 2017 09:41 AM

    Hello guys,

    As subject I would like to use a powershell script to get cluster health with generic information also about virtual/physical  hardware,

    I already have some script to make these check but if somebody have something specific or suggestion will be appreciate.

    Thanks



  • 2.  RE: Cluster health script

    Posted Aug 22, 2017 10:00 AM

    You will need to be a bit more specific on what you want.

    You could perhaps share you current script, and indicate what you think is missing?



  • 3.  RE: Cluster health script

    Posted Aug 22, 2017 11:26 AM

    Like here I have datastore information:

    Function Percentcal {

        param(

        [parameter(Mandatory = $true)]

        [int]$InputNum1,

        [parameter(Mandatory = $true)]

        [int]$InputNum2)

        $InputNum1 / $InputNum2*100

    }

    $datastores = Get-Datastore | Sort Name

    ForEach ($ds in $datastores)

    {

        if (($ds.Name -match “Shared”) -or ($ds.Name -match “”))

        {

            $PercentFree = Percentcal $ds.FreeSpaceMB $ds.CapacityMB

            $PercentFree = “{0:N2}” -f $PercentFree

            $ds | Add-Member -type NoteProperty -name PercentFree -value $PercentFree

        }

    }

    $datastores | Select Name,@{N=”UsedSpaceGB”;E={[Math]::Round(($_.ExtensionData.Summary.Capacity – $_.ExtensionData.Summary.FreeSpace)/1GB,0)}},@{N=”TotalSpaceGB”;E={[Math]::Round(($_.ExtensionData.Summary.Capacity)/1GB,0)}}

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    Or this one where I can see also memory and CPU for Host

    Get-VMHost -Name tec-vm-pi* , tec-vm-a* |

    Select Name,

        @{N='CPU GHz Capacity';E={[math]::Round($_.CpuTotalMhz/1000,2)}},

        @{N='CPU GHz Used';E={[math]::Round($_.CpuUsageMhz/1000,2)}},

        @{N='CPU GHz Free';E={[math]::Round(($_.CpuTotalMhz - $_.CpuUsageMhz)/1000,2)}},

        @{N='Memory Capacity GB';E={[math]::Round($_.MemoryTotalGB,2)}},

        @{N='Memory Used GB';E={[math]::Round($_.MemoryUsageGB,2)}},

        @{N='Memory Free GB';E={[math]::Round(($_.MemoryTotalGB - $_.MemoryUsageGB),2)}}

    In somehow is in half for a fast check, I would like to have some suggestion, what can be useful to add/check if I want to check host/datastore status/health.



  • 4.  RE: Cluster health script

    Posted Aug 22, 2017 11:56 AM

    Have you already looked at vCheck?

    It will show you most of the common problems if they exist.

    It doesn't give an inventory, but there are quite a bit of those around in this community.

    See for example 108.  Re: PowerCLI script for vSphere capacity planning



  • 5.  RE: Cluster health script

    Posted Aug 23, 2017 07:51 AM

    Hi LucD,

    I found also this interesting:

    #ForEach ($DataCentre in Get-Datacenter){

    # ForEach ($Cluster in ($DataCentre | Get-Cluster))

    Foreach ($cluster in (Get-Cluster | Sort Name)){

    $clustername = Get-cluster $cluster

    $Clusters = Get-cluster $cluster | Get-View

    IF ($cluster | Get-VMHost | Select-Object Count) {

    $Clusters | % {

    $VMHostsView = $null

    $VMHostsView = Get-View $_.Host -Property Name, Hardware, Config

    $VMss         = $clustername | Get-VM

    $HostCount        = ($VMHostsView | Measure-Object).Count

    IF ($HostCount -gt 0){

    $VMCount          = 0 + ($VMss | Measure-Object).Count

    IF ($VMCount){

    $VMsPerHost       = [math]::round(($VMCount/$HostCount), 1)

    $vCPU             = 0 + ($VMss | measure-object -sum -property NumCPU).Sum

    $allocatedram      = 0 + ($VMss | measure-object -sum -property memorygb).Sum

    $avgrampervm      = [math]::round(($allocatedram/$VMCount), 1)

    $pCPUSocket       = ($VMHostsView | % { $_.Hardware.CPUInfo.NumCpuPackages } | Measure-Object -sum).Sum

    $TpCPUSocket      = $pCPUSocket

    $pCPUCore         = ($VMHostsView | % { $_.Hardware.CPUInfo.NumCpuCores } | Measure-Object -sum).Sum

    $CPUSpeed = ($VMHostsView |% {[math]::round($_.Hardware.CpuInfo.Hz / 1000000, 0)}| Measure-Object -sum).Sum

    $OverallCPUSpeed = ($CPUSpeed / $HostCount)

    $TotalCPU = (($VMHostsView |% {[math]::round($_.Hardware.CpuInfo.Hz / 1000000, 0)}| Measure-Object -sum).Sum * $pCPUCore)

    $vCPUPerpCPUCore  = [math]::round(($vCPU/$pCPUCore), 1)

    $TotalClusterRAMGB =[math]::round((Get-cluster $cluster | get-vmhost | % { $_ } | measure-object -property memorytotalGB -sum).sum)

    $TotalClusterRAMusageGB =[math]::round((Get-cluster $cluster | get-vmhost | % { $_ } | measure-object -property memoryusageGB -sum).sum)

    $TotalClusterRAMUsagePercent = [math]::round(($TotalClusterRAMusageGB/$TotalClusterRAMGB)*100)

    $TotalClusterRAMFreeGB = [math]::round(($TotalClusterRAMGB-$TotalClusterRAMUsageGB))

    $TotalClusterRAMReservedGB = [math]::round(($TotalClusterRAMGB/100)*15)

    $TotalClusterRAMAvailable = [math]::round(($TotalClusterRAMFreeGB-$TotalClusterRAMReservedGB))

    $newvmcount = [math]::round(($TotalClusterRAMAvailable/$avgrampervm))

    New-Object PSObject |

    Add-Member -pass NoteProperty "ClusterName"          $clustername.name    |

    Add-Member -pass NoteProperty "TotalClusterHostCount"          $HostCount    |

    Add-Member -pass NoteProperty "TotalClusterVMCount"          $VMCount    |

    Add-Member -pass NoteProperty "TotalClusterVM/Host"          $VMsPerHost    |

    Add-Member -pass NoteProperty "TotalClusterpCPUSocket"          $TpCPUSocket   |

    Add-Member -pass NoteProperty "TotalClusterpCPUCore"          $pCPUCore   |

    Add-Member -pass NoteProperty "TotalClustervCPUCount"          $VCPU    |

    Add-Member -pass NoteProperty "TotalClustervCPU/pCPUCore"          $vcpuperpcpucore  |

    Add-Member -pass NoteProperty "TotalClusterRAMGB"          $TotalClusterRAMGB    |

    Add-Member -pass NoteProperty "TotalClusterRAMUSAGEPercent"          $TotalClusterRAMUsagePercent    |

    Add-Member -pass NoteProperty "TotalClusterRAMUsageGB"     $TotalClusterRAMusageGB    |

    Add-Member -pass NoteProperty "TotalClusterRAMFreeGB"      $TotalClusterRAMfreeGB    |

    Add-Member -pass NoteProperty "TotalClusterRAMReservedGB(15%)"          $TotalClusterRAMReservedGB    |

    Add-Member -pass NoteProperty "RAM Available for NEW VMs in GB"          $TotalClusterRAMAvailable    |

    Add-Member -pass NoteProperty "Allocated RAM per VM on an average"                          $avgrampervm    |

    Add-Member -pass NoteProperty "NEW VM's that can be provisioned based on Average RAM per VM"    $newvmcount |

    Add-Member -pass NoteProperty "Total CPU MHz" $TotalCPU |

    Add-Member -pass NoteProperty "CPU Speed MHz" $OverallCPUSpeed

    }

    }

    }

    }}

    I would like to set this to make csv and/or send by email.



  • 6.  RE: Cluster health script
    Best Answer

    Posted Aug 23, 2017 08:55 AM

    See attached file.



  • 7.  RE: Cluster health script

    Posted Aug 23, 2017 09:10 AM

    Thanks a lot LucD very helpful :smileycool:



  • 8.  RE: Cluster health script

    Posted Jun 27, 2022 09:48 AM

    Hi,

    I am also looking at the cluster and vCenter health check reports powercli.

     

    Could you please share?

     

    Thanks