how to limit the output of vmware esxtop to feed a monitoring system

To reduce the size of your esxtop output by selectively include only the statistics you are interested in. This way you save a lot of time collecting the data and this makes the command usefull for monitoring systems like Nagios. Here’s how you can narrow down the collected stats for easier analysis and smaller output:

Enter ESXTOP in interactive mode on the Service Console by simply typing esxtop at the # prompt

Switch to a component you are NOT interested in capturing statistics on by pressing the corresponding menu option (c: ESX cpu, m: ESX memory, d: ESX disk adapter, u: ESX disk device, v: ESX disk VM).

Press f when viewing the component you do not want to capture. A list of fields will be displayed. You can toggle the fields on and off by pressing the letter corresponding to each field. An * indicates that the field is on. You want to turn off all of the fields you don’t want to collect.

Repeat steps 2 & 3 for the remaining components, leaving only what you want to capture.

Switch to the component you want to capture in batch mode and repeat step #3, except you will now enable what you want to capture.

Press W (capital W - case sensitive) to write out the ESXTOP configuration file. You can accept the default or create new configuration files. You may want to create a CPU-only config file, memory-only, and so forth.

Press CTRL+C to stop ESXTOP.

Now, invoke ESXTOP in batch mode, calling your updated or new configuration file you created in step 6 using the -c switch. Here’s an example: esxtop -b -d 30 -n 480 -c .esxtopcpustats > /tmp/esxtop_cpu_stats.csv where .esxtopcpustats is an ESXTOP config file with only CPU stats. -d sets your capture interval to 30 seconds, and -n sets the number of samples to 480 (or 4 hours with a delay of 30 seconds).

Once your capture is complete you can replay the sampling in ESXTOP using replay mode (-R), or you can copy the .csv to a Windows system and use PERFMON or Excel to analyze the stats. If using PERFMON or Excel you will notice that the system summary information displayed at the top of an interactive ESXTOP session is included in the output (console memory, console cpu, etc.). As far as I know, there is no way to disable this, nor would you want to as it includes the time stamp necessary to interpret your data.

to collect the data via ssh from a remote host:

ssh -qttt esxihost esxtop -b -c esxtoprc-{cpu,disk,mem,net} -n 1 -l -d 2 |

the ssh args, -qttt, make it quieter, and force a terminal. otherwise, all this is for nothing.

another way to make the output available is to run netcat on the esxi host with the -l and -k options so that it remains listening on a port:

cd /
exec </dev/null >/dev/null 2>/dev/null
while true
        esxtop -b -c esxtoprc-{cpu,disk,mem,net} -n 1 -l -d 2 |
        nc -l -k 2222

of course, that will prob’ly need some refinement…

download from another host, strip out the escape sequences with:

nc esxihost 2222 | perl -pe 's/\e\[?.*?[\@-~]_g' | nc graphite 2003

this will require opening a hole in the firewall on port 2222.

or… use inetd:

  • add an entry to /etc/services:

    stats           2222/tcp
  • add to /var/run/inetd.conf:

    stats   stream    tcp  nowait   root   /bin/cat /esxtop.out           cat
  • start inetd: /bin/inetd