ESXi Management and Monitoring using ESXTOP and ESXCLI
Mastering ESXCLI and ESXTOP

Mastering ESXCLI and ESXTOP

VMware ESXi, the industry-leading hypervisor, offers a wide range of management and monitoring capabilities to efficiently administer virtualized environments. Among these capabilities, two powerful command-line tools stand out: ESXCLI and ESXTOP. In this comprehensive guide, we will delve into the world of ESXCLI and ESXTOP, exploring their features, functionalities, and practical usage. By mastering these tools, system administrators and virtualization enthusiasts can gain deep insights into their ESXi hosts, effectively manage virtual machines, monitor performance metrics, and troubleshoot issues. So, let's embark on a journey to unleash the potential of ESXCLI and ESXTOP!

I. Understanding ESXCLI

ESXCLI is a command-line interface that enables users to manage various aspects of an ESXi host, ranging from networking and storage to virtual machines and system settings. With its extensive command set, ESXCLI provides a robust and flexible means to control and configure ESXi hosts efficiently. Here are some key areas where ESXCLI excels:

Managing Virtual Machines

ESXCLI allows users to perform essential operations on virtual machines (VMs), such as starting, stopping, suspending, and restarting them. With a simple command like esxcli vm process list, administrators can obtain a list of all running VMs, along with their corresponding World IDs. This information proves invaluable for troubleshooting or performing specific actions on individual VMs.

PowerShell Code Showcase

esxcli vm process list - List all running virtual machines
esxcli vm process start --vmid=  -  Power on a virtual machine
esxcli vm process kill --type=soft --world-id= - Power off a virtual machine
esxcli vm process kill --type=force --world-id= - Forcefully power off a virtual machine
esxcli vm process suspend --world-id= - Suspend a virtual machine
esxcli vm process resume --world-id= - Resume a suspended virtual machine
esxcli vm process list - List virtual machine information
esxcli vm process status get --world-id= - Get virtual machine details
        

Network Configuration and Troubleshooting

Network configuration plays a vital role in virtualized environments, and ESXCLI provides a comprehensive set of commands to manage network interfaces, switch configurations, and virtual switches. Administrators can use commands like esxcli network nic list to view information about network adapters, their link state, speed, and other relevant details. Advanced network configurations, such as VLAN tagging or configuring Jumbo Frames, can also be achieved through ESXCLI commands.

JavaScript Code Showcase

esxcli network nic list - List network adapters
esxcli network nic set --speed= --nic-name= - Set the speed of a network adapter
esxcli network nic up --nic-name= - Enable a network adapter
esxcli network nic down --nic-name= - Disable a network adapter
esxcli network ip netstack list - List TCP/IP stack information
esxcli network ip interface ipv4 get - List the network interfaces and their IP configurations
Config an IPv4 address on a network
esxcli network ip interface ipv4 set --interface-name= --ipv4=/"" 
Restart the management network
esxcli network ip interface set --interface-name=vmk0 --ipv4=none && esxcli network ip interface set --interface-name=vmk0 --ipv4=dhcp      
        

Storage Management

ESXCLI empowers administrators to manage storage resources efficiently. With commands like esxcli storage core device list, users can obtain a detailed list of storage devices attached to the ESXi host, including information about device names, capacity, and paths. These commands prove valuable when diagnosing storage-related issues, identifying device mappings, or configuring storage policies.

JavaScript Code Showcase

esxcli storage core device list - List storage devices
esxcli storage core adapter rescan - Rescan storage adapters
esxcli storage core path list - List storage paths
esxcli storage core device stats get --device= - Display storage device details
esxcli storage filesystem list - List storage filesystems
esxcli storage vmfs mount -l  - Mount a VMFS datastore
Mount a VMFS datastore - Unmount a VMFS datastore
esxcli storage vmfs extent resize -s  -u  - Expand a VMFS datastore     
        

System Settings and Health Monitoring

ESXCLI offers commands to manage various system settings and monitor the health of an ESXi host. Users can access configuration information, network settings, advanced options, and more. Additionally, ESXCLI commands enable the retrieval of crucial system health information, such as CPU and memory usage, power supply status, fan speed, and temperature.

JavaScript Code Showcase

esxcli system version get - Display ESXi version and build information
esxcli hardware platform get - List system hardware information
esxcli hardware cpu list - Retrieve CPU information
esxcli hardware memory get - Check memory usage
esxcli hardware power supply list - View power supply status
esxcli hardware fan list - Monitor fan speed
esxcli hardware temperature list - Check temperature sensors
esxcli hardware cpu list - Monitor CPU usage  
        

PowerCLI and ESXCLI

The combination of PowerCLI and ESXCLI provides a powerful approach to managing and automating storage rescan operations in VMware ESXi hosts. The below is the example to integrate PowerCLI and ESXCLI.

PowerShell Code Showcase

# Connect host using PowerCLI
Connect-VIServer -Server  -User  -Password 

# Create an ESXCLI object
$esxcli = Get-EsxCli -VMHost 

# Rescan storage adapters
$esxcli.storage.core.adapter.rescan.Invoke()

# To Change the filewall rules.
$arguments = $esxcli.network.firewall.ruleset.set.CreateArgs()
$arguments.enabled = $true
$arguments.rulesetid = “sshClient”
$esxcli.network.firewall.ruleset.set.invoke($arguments)

# Disconnect from the ESXi host
Disconnect-VIServer -Server  -Confirm:$false
        

II. Exploring ESXTOP

ESXTOP is a powerful real-time performance monitoring and troubleshooting tool that provides deep insights into the performance metrics of an ESXi host. By using ESXTOP, administrators can monitor resource utilization, identify performance bottlenecks, and make informed decisions to optimize their virtual infrastructure.

Launching ESXTOP and Navigating Views

To start ESXTOP, simply enter the esxtop command in the ESXi Shell or SSH client. Upon launching, users are presented with a real-time performance dashboard that displays statistics for various system resources. ESXTOP provides different views accessible via function keys, such as CPU, memory, network, disk, and more. Pressing the corresponding key switches to the desired view, allowing administrators to focus on specific metrics.

Analyzing CPU Performance

In the CPU view of ESXTOP, administrators can monitor key CPU-related metrics such as %USED, %WAIT, %READY, and more. By observing these metrics, users can identify CPU bottlenecks, determine the distribution of CPU resources among virtual machines, and pinpoint any excessive CPU usage that may impact overall performance.

Monitoring Memory Utilization

ESXTOP's memory view provides valuable insights into memory usage and allocation. Metrics such as MEMCTL (Memory Controlling), SWAP (Swap Usage), and MCTL (Memory Ballooning) assist administrators in monitoring memory consumption, identifying memory contention issues, and ensuring optimal allocation of memory resources to virtual machines.

Analyzing Network Performance

The network view in ESXTOP displays statistics related to network interfaces, including packets transmitted and received, network throughput (KB/s), and packet loss. By closely monitoring these metrics, administrators can identify network congestion, troubleshoot connectivity issues, and optimize network configurations to ensure smooth data transmission.

Monitoring Disk Performance

ESXTOP's disk view provides insights into storage performance by showcasing metrics such as GAVG (Guest Average Latency), KAVG (Kernel Average Latency), and DAVG (Device Average Latency). By analyzing these metrics, administrators can identify storage bottlenecks, disk latency issues, and potential I/O congestion that might impact the performance of virtual machines.

PowerCLI and ESXTOP

ESXTOP is a powerful command-line tool for monitoring and analyzing the performance of VMware ESXi hosts. While ESXTOP itself is not directly accessible through PowerCLI, you can invoke ESXTOP commands and capture their output using PowerCLI. Here's an example of extracting CPU usage:

PowerShell Code Showcase

$avgSize= 5
$OutputData = foreach ($vm1 in (Get-VM | where powerstate -eq poweredon))
 {

    $USAGE =  (get-stat -Entity $vm1 -Stat cpu.usage.average -Realtime| where {!$_.instance}|select -last $avgSize| Measure-Object -Property value -Average).average

    $RDY = (get-stat -Entity $vm1 -Stat cpu.ready.summation -Realtime| where {!$_.instance}|select -last $avgSize| Measure-Object -Property value -Average).average/200

    $CSTP = (get-stat -Entity $vm1 -Stat cpu.costop.summation -Realtime| where {!$_.instance}|select -last $avgSize| Measure-Object -Property value -Average).average/200

    $USED = (get-stat -Entity $vm1 -Stat cpu.used.summation -Realtime| where {!$_.instance}|select -last $avgSize| Measure-Object -Property value -Average).average/200

    [pscustomobject]@{
        VM = $vm1.name
        Usage = "$([math]::round($USAGE,2))%"
        "%RDY" = $RDY
        "%CSTP" = $CSTP
        "%USED" = $USED
    }

}
        

III. Harnessing the Power of ESXCLI and ESXTOP

  • Efficient Management: ESXCLI simplifies management tasks by providing a versatile command set to configure virtual machines, network settings, storage devices, and system configurations. It enables administrators to automate repetitive tasks, streamline operations, and ensure consistent configurations across ESXi hosts.
  • Real-Time Performance Monitoring: ESXTOP's real-time monitoring capabilities empower administrators to proactively monitor performance metrics, identify bottlenecks, and troubleshoot issues. By leveraging the insights provided by ESXTOP, administrators can make data-driven decisions to optimize resource utilization, improve performance, and deliver a seamless experience to end-users.
  • Troubleshooting and Root Cause Analysis: Both ESXCLI and ESXTOP play crucial roles in troubleshooting and root cause analysis. ESXCLI commands assist in diagnosing and resolving specific issues at the host and virtual machine level, while ESXTOP provides a holistic view of performance metrics, aiding administrators in identifying underlying problems and their impacts on the overall system.

Conclusion

ESXCLI and ESXTOP are indispensable tools for managing and monitoring VMware ESXi hosts. With ESXCLI, administrators gain fine-grained control over host configurations, virtual machines, and network/storage resources. On the other hand, ESXTOP provides real-time performance monitoring, enabling administrators to optimize resource allocation, troubleshoot performance bottlenecks, and maintain a healthy virtual infrastructure. By mastering these tools, system administrators can enhance efficiency, minimize downtime, and ensure optimal performance in their VMware environments. So, embrace the power of ESXCLI and ESXTOP, and unlock the full potential of your VMware ESXi infrastructure.


Siddartha Kumar Das
About Siddartha Kumar Das

Tech Enthusiast

Topics