Using virt-top

virt-top is a utility for displaying virtualized domain statistics. Many of the command line options are the same as for regular top.

virt-top uses libvirt, so it can show statistics on a wide variety of virtualization systems.

During monitoring of virtual machines on kvm, the following parameters are displayed:

  • S is virtual machine state.
  • R is for running.
  • RDRQ/WRRQ is disk i/o.
  • RXBY/TXBY is network i/o.

Key operation:

  • 1 - switch to display mode by processors (by processor cores).
  • 2 - view the current i/o on various virtual network interfaces (vnetX, for example).
  • 3 - view the current i/o by virtual disk devices.

To write to a file:

  • virt-top –csv file.csv - so that virt-top writes its data to a file.
  • virt-top –csv file.csv -d 1 - to force to write statistics every second, not 3.
  • virt-top –csv file.csv -d 1 –script - to turn off the display of the main interface virt-top.

Of particular interest is the --csv-file.csv option, which allows to write statistics to a file.csv file. First, a header is written showing the statistics written in each column, then one line is written for each screen refresh. The CSV file can then be loaded by most spreadsheet programs.

Currently, the statistics written to the file varies depending on the versions of virt-top (but the column headers will remain the same, so you can use them to process the CSV file).

Not every version of virt-top supports CSV output - it depends on how the program was compiled (details in the README file in the source distribution).

To save space, you can compress your CSV files (if your shell supports this feature, e.g. bash):

virt-top --csv >(gzip -9 > output.csv.gz)

You can use a similar method to split a CSV file into parts. This example splits the CSV file every 1000 lines into files named output.csv.00, output.csv.01, and so on.:

virt-top --csv >(split -d -l 1000 - output.csv.)

RHEL 6 provides a short Python script called “processcsv.py ” that can be used to post-process the CSV output. The script is launched with the command:

virt-top --csv data.csv
processcsv.py < data.csv

This creates or overwrites the following files in the current directory:

global.csv
domain<NNN>.csv

“global.csv” will contain global data. For each domain, one “domain<NNN>.csv” file with the identifier “NNN” will also be created, containing data for each domain.

More details about the utility can be found in the official documentation.