Collecting VirtualBox VM resource usage stats with VBoxManage metrics

VirtualBox exposes stats about a running VM, such as network transmit rates, ram usage, and cpu usage. This post shows how to start collecting and how to retrieve the stats and where to learn more.

We will be using VBoxManage, the command-line interface to VirtualBox. VBoxManage is located in the install directory of VirtualBox, e.g. “C:\Program Files\Oracle\VirtualBox”

Run the command “VBoxManage metrics list” to see a list of stats you can collect. For example:

C:\Program Files\Oracle\VirtualBox>vboxmanage metrics list
Object Metric Unit Minimum Maximum Period Count Description
---------- -------------------- ---- ---------- ---------- ---------- ---------- -----------
host CPU/Load/User % 0 100000 0 0 Percentage of processor time spent in user mode.
host CPU/Load/User:avg % 0 100000 0 1
host CPU/Load/User:min % 0 100000 0 1
host CPU/Load/User:max % 0 100000 0 1
host CPU/Load/Kernel % 0 100000 0 0 Percentage of processor time spent in kernel mode.

To start collecting stats, use the “setup” subcommand:
VBoxManage metrics setup acm-docker2 Guest/CPU/Load,Guest/RAM/Usage
This command tells VirtualBox to collect CPU and RAM stats for my VM, “acm-docker2”. By default VirtualBox samples once per second and saves one sample.

To retrieve the states, use the “query” subcommand:

VBoxManage metrics query acm-docker2 Guest/CPU/Load/User,Guest/CPU/Load/Kernel,Guest/RAM/Usage/Total


Object Metric Values
---------- -------------------- --------------------------------------------
acm-docker2 Guest/CPU/Load/User 28.00%
acm-docker2 Guest/CPU/Load/Kernel 5.00%
acm-docker2 Guest/RAM/Usage/Total 4048380 kB

For my purpose I found it easier to keep one sample only and use a separate script to poll for the stats, do some simple manipulation to massage it into a format that’s easy for visualization.

To learn more about VBoxManage metrics, see their documentation here: https://www.virtualbox.org/manual/ch08.html#metrics

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s