Automation

 View Only
  • 1.  Cluster capacity info through script..

    Posted Aug 02, 2011 03:56 PM

    I'm looking for a powershell script which can pull out the following info..

    Cluster Name, Total CPU, Total Memory, Total Storage, Available CPU, Available Memory and Available Storage..

    I'm trying this to start with.. but doesn't seem to work for some reason.. Any other script or corrections to this script please?

    $clusters = Get-Cluster | Sort Name

    ForEach ($cluster in $clusters)
    {
        $vmhosts = Get-VMHost -Location $cluster
       
        ForEach ($VMhostView in ($vmhosts | Get-View))
        {
            $TotalHostMemory += $vmhostView.Hardware.MemorySize
            $TotalHostCPU += $VMhostView.Hardware.NumCpuPkgs
        }
       
        $NumHosts = ($vmhosts | Measure-Object).Count
       
        $vms = Get-VM -Location $cluster | Where {$_.PowerState -eq "PoweredOn"}
        $NumVMs = $vms.Length
        $TotalRAM_GB = [math]::Round($TotalHostMemory/1GB,$digits)
       
        $TotalVMMemoryMB = $vms | Measure-Object -Property MemoryMB -Sum
        $TotalVMCPU = $vms | Measure-Object -Property NumCPU -Sum
        $AssignedRAM_GB = [math]::Round($TotalVMMemoryMB.Sum/1024,$digits)
        $PercentageMemUsed = [math]::Round((($TotalVMMemoryMB.Sum/1024)/($TotalHostMemory/1GB))*100)
        $PercentageCPUUsed = [Math]::Round(($TotalVMCPU/$TotalHostCPU)*100)
       
        $report = @()
       
        $Details = "" | Select "Cluster Name", TotalCPU, TotalMemory, TotalVMs, "% Cluster Memory Used", "% Cluster CPU Used"
        $Details."Cluster Name" = $Cluster.Name
        $Details.TotalCPU =  $TotalHostCPU
        $Details.TotalMemory = $TotalHostMemory
        $Details.TotalVMs = $NumVMs
        $Details."% CPU Used" = $PercentageCPUUsed
        $Details."% Memory Used" = $PercentageMemUsed
        $report += $Details
       
        $report | ConvertTo-Html -title "Cluster Information" -body "<H3>Cluster Information</H3>" | Out-File -Append $filelocation
       
    Disconnect-VIServer * -Confirm:$false
    }

    VMSavvy



  • 2.  RE: Cluster capacity info through script..

    Posted Aug 02, 2011 05:07 PM

    This will produce the html report.

    $fileLocation = "C:\report.html"

    $clusters = Get-Cluster | Sort Name foreach ($cluster in $clusters) {     $vmhosts = Get-VMHost -Location $cluster     $TotalHostMemory = $TotalHostCPU = 0
        $vmhosts | %{         $TotalHostMemory += $_.Extensiondata.Hardware.MemorySize         $TotalHostCPU += $_.Extensiondata.Hardware.CpuInfo.NumCpuPackages     }     $NumHosts = $vmhosts.Count     $vms = Get-VM -Location $cluster | where {$_.PowerState -eq "PoweredOn"}     $NumVMs = $vms.Length     $TotalRAM_GB = [math]::Round($TotalHostMemory / 1GB,$digits)     $TotalVMMemoryMB = $vms | Measure-Object -Property MemoryMB -Sum
       
    $TotalVMCPU = $vms | Measure-Object -Property NumCPU -Sum
        $AssignedRAM_GB = [math]::Round($TotalVMMemoryMB.Sum/1024,$digits)     $PercentageMemUsed = [math]::Round((($TotalVMMemoryMB.Sum/1024)/($TotalHostMemory / 1GB))*100)     $PercentageCPUUsed = [Math]::Round(($TotalVMCPU.Sum / $TotalHostCPU)*100)     $report = @()     $Details = "" | Select "Cluster Name", TotalCPU, TotalMemory, TotalVMs, "% Cluster Memory Used", "% Cluster CPU Used"
        $Details."Cluster Name" = $Cluster.Name     $Details.TotalCPU = $TotalHostCPU
        $Details.TotalMemory = $TotalHostMemory
        $Details.TotalVMs = $NumVMs
        $Details."% Cluster CPU Used" = $PercentageCPUUsed
        $Details."% Cluster Memory Used" = $PercentageMemUsed
        $report += $Details     $report | ConvertTo-Html -title "Cluster Information" -body "<H3>Cluster Information</H3>" | Out-File -Append $filelocation      Disconnect-VIServer * -Confirm:$false
    }

    Invoke-Item $fileLocation

    I'm not sure what you are trying to do with the "%  Cluster CPU Used" property though ?



  • 3.  RE: Cluster capacity info through script..

    Posted Aug 02, 2011 05:16 PM

    "% Cluster CPU Used" was just a thought... to get know how much of CPU % is used in the cluster..so we can find how much is free.. but thats doesn't look good enough to me..

    Can you help me with these counters please..?

    Total Storage, Available CPU, Available Memory and Available Storage..

    VMSavvy..



  • 4.  RE: Cluster capacity info through script..
    Best Answer

    Posted Aug 02, 2011 06:21 PM

    There are several values that you could display to help you in determining if a cluster has spare capacity or not.

    Some examples:

    • A ratio between the physical CPUs in the cluster and the number of vCPU that are active. Something like 96:137. It depends of course if your guests that use these vCPU are CPU intensive or not.
    • Which brings us to another value. Display the cpu.usage.average for the cluster. This values can be obtained with the Get-Stat cmdlet. You can report on the current value, or the average over the last hour for example.
    • Sometimes the cpu.ready.summation is a good indicator as well. It can show you if your guests have to wait rather long before they get access to a CPU resource.

    That's only a few sample value from the top of my head, there are many others.

    Have a look at the links in the Introduction of my PowerCLI & vSphere statistics – Part 1 – The basics post. These documents give many more values that you can monitor.