[ovirt-users] Cumulative VM network usage

Lior Vernia lvernia at redhat.com
Tue Nov 11 05:07:58 EST 2014


The need to monitor cumulative VM network usage has come up several
times in the past; while this should be handled as part of
(https://bugzilla.redhat.com/show_bug.cgi?id=1063343), in the mean time
I've written a small Python script that monitors those statistics,
attached here.

The script polls the engine via RESTful API periodically and dumps the
up-to-date total usage into a file. The output is a multi-level
map/dictionary in JSON format, where:
* The top level keys are VM names.
* Under each VM, the next level keys are vNIC names.
* Under each vNIC, there are keys for total 'rx' (received) and 'tx'
(transmitted), where the values are in Bytes.

The script is built to run forever. It may be stopped at any time, but
while it's not running VM network usage data will "be lost". When it's
re-run, it'll go back to accumulating data on top of its previous data.

A few disclaimers:
* I haven't tested this with any edge cases (engine service dies, etc.).
* Tested this with tens of VMs, not sure it'll work fine with hundreds.
* The PERIOD_TIME (polling interval) should be set so that it matches
both the engine's and vdsm's polling interval (see comments inside the
script), otherwise data will be either lost or counted multiple times.
>From 3.4 onwards, default configuration should be fine with 15 seconds.
* The precision of traffic measurement on a NIC is 0.1% of the
interface's speed over each PERIOD_TIME interval. For example, on a
1Gbps vNIC, when PERIOD_TIME = 15s, data will only be measured in 15Mb
(~2MB) quanta. Specifically what this means is, that in this example,
any traffic smaller than 2MB over a 15-second period would be negligible
and wouldn't be recorded.

Knock yourselves out :)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ovirt-vm-monitor.py
Type: text/x-python
Size: 2745 bytes
Desc: not available
URL: <http://lists.ovirt.org/pipermail/users/attachments/20141111/66ec3283/attachment.py>

More information about the Users mailing list