Performance is a hot topic with the Intel security flaws Meltdown and Spectre. What is the impact of the patch on your environment? Is there enough server capacity available? Performance testing is key, and any valuable data helps to determine the overall impact. In this blog post, I will share how to capture VMware ESXtop data with PowerShell, fully automated!

Requirement for SSH

Like my previous post (XenServer) an SSH connection is required to fully automate the data capture. With the Posh-SSH PowerShell module, we are able to connect to the ESX host and invoke the command to capture the ESXtop data.

Please note: an internet connection is required. You also can download the package to use it in an offline scenario.

if (!(Get-PackageProvider | Where-Object {$_.Name -eq "NuGet"})) { Write-Host "Default NuGet package provider not installed." Write-Host "Installing NuGet package provider." Install-PackageProvider -Name "NuGet" -Confirm:$false -Force Set-PSRepository -Name "PSGallery" -InstallationPolicy "Trusted" } if (!((Get-Module -ListAvailable *) | Where-Object {$_.Name -eq "Posh-SSH"})) { Write-Host "SSH module not found, installing missing module." Install-Module -Name Posh-SSH -Confirm:$false -Force }

SSH key

To create an SSH session to an ESX host requires an SSH key. So before we can start capturing the performance data we need to generate the key. The following knowledge base article explains how to generate the SSH key. In order to add the correct key to the authorized_keys file, you can use the following command. For more information please check this blog post.

cat /root/.ssh/id.dsa.pub | ssh root@<esx host> ‘cat >> /etc/ssh/keys-root/authorized_keys’

Capture the ESXtop data

So right now we have the generated key and should be able to set up an SSH session to the ESX host. There are a couple variables in the script below that need to be assigned. First, it is important to specify the ESX host, username, password and the generated key. The credentials and key will be used to set up the SSH session. The test name will be used as the primary name for the CSV which will contain the ESXtop data. In the example, the data will be captured for 1 hour with an interval of 30 seconds. The CSV file will be captured in the “/tmp/” location. It is recommended to use a PowerShell job to capture the data so other tasks can be executed during the ESXtop capture.

This example captures the default ESXtop data set. More information about ESXtop can be found here.

$HostName = "Esx01.local.lab" $EsxUserName = "root" $EsxPassword = "Password123!" $EsxKey = "Esx01.key" $TestName = "Logitblog-exmaple-" + (Get-Date -format 'MMddyy_HHmm').ToString() $delay = 30 $samples = 120 # * 30 = 3600 sec $path = "/tmp/$TestName.csv" $command = "esxtop -b -d $delay -n $samples > $path" $password = ConvertTo-SecureString $EsxPassword -AsPlainText -Force $hostCredential = New-Object System.Management.Automation.PSCredential($EsxUserName, $password) Start-Job -Scriptblock { Param( [PSCredential]$jobCred, [string]$jobHost, [string]$jobCommand, [string]$jobKey ) $session = New-SSHSession -ComputerName $jobHost -Credential $jobCred -KeyFile $jobKey -AcceptKey Invoke-SSHCommand -Index $session.SessionId -Command $jobCommand Get-SSHSession | Remove-SSHSession | Out-Null } -ArgumentList @($hostCredential, $HostName, $command, $EsxKey)

Download the ESXtop data

Once the capture is done it is useful to automatically download the CSV file. The Posh-SSH module comes with the Get-SCPFile command which allows you to download the file. The following example will download the CSV file to %tmp%.

$localFile = "$env:Temp\" + $TestName + ".csv" Get-SCPFile -HostName $HostName -RemoteFile $path -LocalFile $localFile -AcceptKey -KeyFile $EsxKey -Credential $hostCredential

A quick tip! With the PPD you can quickly create charts in Microsoft Excel out of the ESXtop performance data! More info here .

Conclusion

To do proper performance research you need to have valuable data. It is common to include the performance data from a hypervisor like VMware ESX. With PowerShell, you are able to start and download the data capture fully automated. This way you can automate your test process to have consistent data. If you have any comments or questions, please leave them below.

Photo by Thomas Kvistholt on Unsplash