diff options
author | Jenkins <jenkins@review.openstack.org> | 2012-09-29 01:54:55 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2012-09-29 01:54:55 +0000 |
commit | 7104362abbee82b3d2adebdf5589f859c1b67279 (patch) | |
tree | bbddbe6284d35641f139b21fda59eddca1f178a4 /plugins/xenserver | |
parent | 8e9a2ac7fe19ca8319b27b4cf779b255926033a0 (diff) | |
parent | 8887f10c66bca248f289db8f834ae8f36f9a03a1 (diff) | |
download | nova-7104362abbee82b3d2adebdf5589f859c1b67279.tar.gz nova-7104362abbee82b3d2adebdf5589f859c1b67279.tar.xz nova-7104362abbee82b3d2adebdf5589f859c1b67279.zip |
Merge "Collect more accurate bandwidth data for XenServer"
Diffstat (limited to 'plugins/xenserver')
-rwxr-xr-x | plugins/xenserver/xenapi/etc/xapi.d/plugins/bandwidth | 51 |
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) |