From 8887f10c66bca248f289db8f834ae8f36f9a03a1 Mon Sep 17 00:00:00 2001 From: Monsyne Dragon Date: Mon, 24 Sep 2012 19:38:09 +0000 Subject: Collect more accurate bandwidth data for XenServer This changes the method used to poll xenserver for bandwidth data. The reccomended way of collecting such data from xenserver (namely the RRD files provided by the hosts) do not seem to be reliable, they will sometimes be correct, often will be signifigantly under (> 10%), and occasionally will show artifacts, such as phantom 4gb bandwidth 'spikes'. This patch changes that to use the much simpler method of simply polling the byte counters on the VIF network devices on the host. (We have old non-nova code that does that on xenserver, and that method is known to work). This should also make it much easier for other hypervisors other than xenserver to implement bandwidth polling, as polling the counters is a rather more universal method. Fixes bug 1055737 Change-Id: I6a280d8bbfcc74914f888b11bc09349a270a5f58 --- .../xenserver/xenapi/etc/xapi.d/plugins/bandwidth | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 plugins/xenserver/xenapi/etc/xapi.d/plugins/bandwidth (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/bandwidth b/plugins/xenserver/xenapi/etc/xapi.d/plugins/bandwidth new file mode 100755 index 000000000..171011a06 --- /dev/null +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/bandwidth @@ -0,0 +1,51 @@ +#!/usr/bin/env python + +# Copyright (c) 2012 OpenStack, LLC +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +"""Fetch Bandwidth data from VIF network devices.""" + +import os +import shutil + +import utils + +from pluginlib_nova import * +configure_logging('bandwidth') + + +def _read_proc_net(): + devs = [l.strip() for l in open('/proc/net/dev', 'r').readlines()] + #ignore headers + devs = devs[2:] + dlist = [d.split(':', 1) for d in devs if d.startswith('vif')] + devmap = dict() + for name, stats in dlist: + slist = stats.split() + dom, vifnum = name[3:].split('.', 1) + dev = devmap.get(dom, {}) + # Note, we deliberately swap in and out, as instance traffic + # shows up inverted due to going though the bridge. (mdragon) + dev[vifnum] = dict(bw_in=int(slist[0]), bw_out=int(slist[8])) + devmap[dom] = dev + return devmap + + +def fetch_all_bandwidth(session): + return _read_proc_net() + + +if __name__ == '__main__': + utils.register_plugin_calls(fetch_all_bandwidth) -- cgit