Gathering esxtop performance data using cronjobs
search cancel

Gathering esxtop performance data using cronjobs

book

Article ID: 323138

calendar_today

Updated On:

Products

VMware vSphere ESXi

Issue/Introduction

This article provides steps for setting up a scheduled cron job to run esxtop in batch mode. The esxtop utility redirects the output to a .csv file.

Environment

VMware vSphere ESXi 6.x
 
VMware vSphere ESXi 7.x

VMware vSphere ESXi 8.x

Resolution

You need to edit the crontab configuration file to create scheduled tasks on ESXi/ESX. For more information, see Editing configuration files in VMware ESXi and ESX (1017022) .

Before creating a scheduled task, ensure that the ESXi/ESX host's date and time are correct. For more information, see Verifying time synchronization across an ESXi/ESX host environment (1003736) .
 

Scheduling the task in ESXi using cron

 
  • First take a backup of the crontabs file to another location before editing.
cat /var/spool/cron/crontabs/root > /vmfs/volumes/<Datastore>/<folder>/crontab-$(hostname).txt
 
  • ​​​​​​Open the root crontab file located in /var/spool/cron/crontabs using the vi editor:
# vi /var/spool/cron/crontabs/root
 
  • Open To enter insert mode in vi and make changes to the file press "i"
  1. To start esxtop at the desired time, append the crontab file with the esxtop command using the syntax explained below:
Crontab Syntax
 
Minutes  Hour(24 hour format)   Date   Month  Day_of_Week   /usr/sbin/esxtop -b -d ## -n #### > path/name-of-the-file.csv
 
-b : Signifies batch mode
-d : Sampling Frequency in seconds
-n : Total number of samples.
 
For example, to collect the esxtop data in batch mode every night regardless of date, month or day of week at 2:20 am with frequency of sampling set to 5 seconds for 180 samples, while saving the collected data as "batch.csv" on your VMFS datastore "datastore1", the entry in crontabs/root will have to look like this:
20 2 *  *  * /usr/sbin/esxtop -b -d 5 -n 180 > /vmfs/volumes/datastore1/esxtop-batch.csv
The above command generates 15 minutes (5 x 180 seconds) worth of data for analysis.
 
 

Scheduling a rolling ESXtop using cron.

In the event of a collecting performance data where it is difficult to collect or predict when an issue may occur you may be able to set a rolling collection of performance data.

The cron job command in the code block below will place a place a mark the logs at the start of the performance data collection. Below is an example of what you may see in the vmkernel:
xxx-xx-xxTxx:xx:xxZ esxcfg-syslog[2233321]: mark: ESXTOP-CRONJOB-xxxx-xx-xxTxx:xx.csv

While collecting a rolling 15 minutes of performance data into individual files on the specified datastore.
You may notice that the files are marked by the time when we start the collection and cover the proceeding 15 minutes.

NOTE: This operation will create many files and will continue to consume space if not continuously monitored please remove the old file that do not cover the time in question and select the files with the appropriate date and time that could cover the time of interest:
*/16  *  *  *  *  localcli system syslog mark --message=ESXTOP-CRONJOB-$(date +"%FT%H:%M").csv;esxtop -ba -d 5 -n 180 >/vmfs/volumes/datastore1/folder/esxtop-$(hostname)-$(date +"%FT%H:%M").csv

 



Saving the file crontab file once changes have been made:

  1. Save the file.
    Note: By default, this file is read-only. However, you can write changes to the file using pressing "Esc" ":" followed by "wq!" key combination in the vi editor.
     
  2. To apply the new cron schedule, you will have to restart crond. Run this command to determine the process ID of the crond process:

    # cat /var/run/crond.pid

    You see output similar to:

    1234

    Where 1234 is the Process ID of the crond process.
     
  3. Run this command to stop and restart the crond process:

    # kill -HUP 1234
     
  4. In order to restart the crond process use this command:
# /usr/lib/vmware/busybox/bin/busybox crond

As soon as these changes have been made, esxtop will start at the next scheduled time.
 
Note: The configuration changes on ESXi do not persist across reboots. To revert the change without rebooting, remove the esxtop line from the crontab file and kill the crond process and restart the crond process again.


Additional Information