VMware vSphere

 View Only
  • 1.  export list of virtual machines that use most CPU and memory in cluster

    Posted 21 days ago

    Hi

    We are moving some virtual machines from one cluster to another. However we have some issues that some machines are using more CPU or memory than the others however cannot find what they are. Not sure if there is a script that would show me CPU and memory usage over period of time in cluster so that I would separate vms when we move them powered off to a new cluster. Most VMs cannot be live motioned we will shut them down

    But now they still seat on old cluster and it would be interesting to see which machines in individual cluster use most CPU and memory resources so we would separate them. these machines will cause host to choke because they are very intensive but not all the time

    We would use like 90 days and basically base our decision on that not perfect but it would give us some ideas

    i know I can get this info with vROPS however we dont have that



  • 2.  RE: export list of virtual machines that use most CPU and memory in cluster

    Posted 8 days ago
    Edited by Andrea Consalvi 8 days ago

    Hi,

    You can get this data via PowerCLI if you don't have vROps. Here's a basic example to export top CPU and memory consuming VMs over the last 90 days:

    # Connect to vCenter
    Connect-VIServer -Server your-vcenter

    # Set the date range
    $start = (Get-Date).AddDays(-90)

    # Get performance metrics
    $metrics = Get-Stat -Entity (Get-VM) -Stat cpu.usage.average, mem.usage.average -Start $start

    # Group and calculate averages
    $summary = $metrics |
        Group-Object {$_.Entity.Name + '-' + $_.MetricId} |
        ForEach-Object {
            [PSCustomObject]@{
                VM = ($_.Group[0].Entity.Name)
                Metric = ($_.Group[0].MetricId)
                Average = ($_.Group | Measure-Object -Property Value -Average).Average
            }
        }

    # Pivot to show CPU and MEM side by side
    $pivot = $summary | Group-Object VM | ForEach-Object {
        $cpu = ($_.Group | Where-Object { $_.Metric -eq "cpu.usage.average" }).Average
        $mem = ($_.Group | Where-Object { $_.Metric -eq "mem.usage.average" }).Average
        [PSCustomObject]@{
            VM = $_.Name
            CPU_Usage_Avg = [math]::Round($cpu, 2)
            MEM_Usage_Avg = [math]::Round($mem, 2)
        }
    }

    # Export to CSV
    $pivot | Sort-Object -Property CPU_Usage_Avg -Descending | Export-Csv -Path "TopVMs.csv" -NoTypeInformation

    This gives you a rough but actionable overview. You can tweak thresholds or add filtering for specific clusters if needed.




  • 3.  RE: export list of virtual machines that use most CPU and memory in cluster

    Posted 8 days ago

    Where I would put cluster name for example cluster name is LABCLUSTER

    This will give me all the machines which doesnt make sense as machines in another cluster would have different values and I am trying to get values just for one cluster to balance it




  • 4.  RE: export list of virtual machines that use most CPU and memory in cluster

    Posted 8 days ago

    Good point. If you want to scope the stats to a specific cluster (like LABCLUSTER), just filter the VMs before passing them to Get-Stat. You can do it like this:

    # Get only VMs in the target cluster
    $clusterName = "LABCLUSTER"
    $vms = Get-Cluster -Name $clusterName | Get-VM

    # Then use these in the stat collection
    $metrics = Get-Stat -Entity $vms -Stat cpu.usage.average, mem.usage.average -Start $start

    That way, the stats and export will only include the VMs from LABCLUSTER