Validating high compute usage by hosts and virtual machines (VMs)

Validating high compute usage by hosts and virtual machines (VMs) is important for ensuring the health and performance of your VMware vSphere environment. Esxtop is a powerful command-line utility that provides real-time performance monitoring of ESXi hosts, while PowerShell with VMware PowerCLI allows you to automate data collection and output the results to a file for further analysis. In this guide, we’ll walk through the steps to use esxtop and PowerShell to monitor compute usage and save the data to a file.

1. Using Esxtop to Monitor Compute Usage:

Esxtop provides detailed performance metrics for CPU, memory, storage, network, and other system resources. To monitor CPU usage with esxtop:

  • SSH into your ESXi host using a terminal client.
  • Launch esxtop by typing esxtop and pressing Enter.
  • Press the ‘c’ key to switch to the CPU view.
  • Observe the CPU performance metrics, including %USED, %IDLE, %WAIT, %READY, %CSTP, etc.
  • Press ‘q’ to exit esxtop.

2. Using PowerShell and PowerCLI:

PowerCLI is a PowerShell module for managing and automating VMware vSphere environments. We’ll use it to extract CPU usage information from ESXi hosts and VMs and save the data to a file.

Step 1: Install PowerCLI: If you haven’t installed PowerCLI, download and install it from the PowerShell Gallery using the following command:

Install-Module VMware.PowerCLI -Force

Step 2: Connect to vCenter Server or ESXi Host:

Connect-VIServer -Server <vCenter_Server_or_ESXi_Host> -User <Username> -Password <Password>

Step 3: Get Host CPU Usage:

# Get the ESXi hosts
$hosts = Get-VMHost

# Create an array to store CPU usage data
$cpuData = @()

# Loop through each host and retrieve CPU usage data
foreach ($host in $hosts) {
    $cpuUsage = Get-Stat -Entity $host -Stat cpu.usage.average -Realtime -MaxSamples 1 | Select-Object @{Name = "Host"; Expression = {$_.Entity.Name}}, Value, Timestamp
    $cpuData += $cpuUsage
}

# Export the data to a CSV file
$cpuData | Export-Csv -Path "C:\Temp\Host_CPU_Usage.csv" -NoTypeInformation

Step 4: Get VM CPU Usage:

# Get the VMs
$VMs = Get-VM

# Create an array to store CPU usage data
$cpuData = @()

# Loop through each VM and retrieve CPU usage data
foreach ($VM in $VMs) {
    $cpuUsage = Get-Stat -Entity $VM -Stat cpu.usage.average -Realtime -MaxSamples 1 | Select-Object @{Name = "VM"; Expression = {$_.Entity.Name}}, Value, Timestamp
    $cpuData += $cpuUsage
}

# Export the data to a CSV file
$cpuData | Export-Csv -Path "C:\Temp\VM_CPU_Usage.csv" -NoTypeInformation

Step 5: Disconnect from vCenter Server or ESXi Host:

Disconnect-VIServer -Server <vCenter_Server_or_ESXi_Host> -Confirm:$false

By running the PowerShell scripts above, you will retrieve CPU usage data for both the ESXi hosts and VMs and save it to CSV files named “Host_CPU_Usage.csv” and “VM_CPU_Usage.csv” in the “C:\Temp” directory (you can change the file paths as needed). The CSV files can then be opened with tools like Microsoft Excel for further analysis.

Please note that the examples provided above focus on CPU usage, but you can modify the scripts to gather data for other performance metrics, such as memory, storage, or network usage, by changing the -Stat parameter in the Get-Stat cmdlets.

In conclusion, using esxtop and PowerShell with PowerCLI, you can effectively monitor and validate high compute usage by ESXi hosts and VMs, and save the data to files for in-depth analysis and performance optimization in your VMware vSphere environment.

Leave a comment