summaryrefslogtreecommitdiffstats
path: root/plugins/xenserver/xenapi
diff options
context:
space:
mode:
authorMonsyne Dragon <mdragon@rackspace.com>2012-09-24 19:38:09 +0000
committerMonsyne Dragon <mdragon@rackspace.com>2012-09-25 20:36:55 +0000
commit8887f10c66bca248f289db8f834ae8f36f9a03a1 (patch)
tree3347a2976f0fcc005e5fcf65cd3fa38701e0f4d6 /plugins/xenserver/xenapi
parent6e89cd0b8cec0c233e55ea8f4e2bf4f2855073af (diff)
downloadnova-8887f10c66bca248f289db8f834ae8f36f9a03a1.tar.gz
nova-8887f10c66bca248f289db8f834ae8f36f9a03a1.tar.xz
nova-8887f10c66bca248f289db8f834ae8f36f9a03a1.zip
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
Diffstat (limited to 'plugins/xenserver/xenapi')
-rwxr-xr-xplugins/xenserver/xenapi/etc/xapi.d/plugins/bandwidth51
1 files changed, 51 insertions, 0 deletions
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)