From ec5a651276aec4ba5d83656cb0e9d3f5745a35df Mon Sep 17 00:00:00 2001 From: ubuntu Date: Tue, 29 Jan 2019 14:55:12 +0800 Subject: [PATCH] filter localhost, docker, kvm, bridge virtual-network --- clients/client-linux.py | 13 +++++++------ clients/client-psutil.py | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/clients/client-linux.py b/clients/client-linux.py index 0c0e992..0a1b1cb 100755 --- a/clients/client-linux.py +++ b/clients/client-linux.py @@ -1,9 +1,9 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- +# coding: utf-8 # Update by : https://github.com/cppla/ServerStatus # 支持Python版本:2.7 to 3.5 # 支持操作系统: Linux, OSX, FreeBSD, OpenBSD and NetBSD, both 32-bit and 64-bit architectures -# 时间: 20180828 +# 时间: 20190128 SERVER = "127.0.0.1" @@ -37,7 +37,7 @@ def get_memory(): for line in open('/proc/meminfo'): match = re_parser.match(line) if not match: - continue; + continue key, value = match.groups(['key', 'value']) result[key] = int(value) @@ -90,9 +90,10 @@ class Traffic: for dev in net_dev[2:]: dev = dev.split(':') - if dev[0].strip() == "lo" or dev[0].find("tun") > -1 \ - or dev[0].find("docker") > -1 or dev[0].find("veth") > -1 \ - or dev[0].find("br-") > -1: + if "lo" in dev[0] or "tun" in dev[0] \ + or "docker" in dev[0] or "veth" in dev[0] \ + or "br-" in dev[0] or "vmbr" in dev[0] \ + or "vnet" in dev[0]: continue dev = dev[1].split() avgrx += int(dev[0]) diff --git a/clients/client-psutil.py b/clients/client-psutil.py index 4fd3224..b611247 100755 --- a/clients/client-psutil.py +++ b/clients/client-psutil.py @@ -1,10 +1,10 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- +# coding: utf-8 # Update by : https://github.com/cppla/ServerStatus # 依赖于psutil跨平台库: -# 支持Python版本:2.6 to 3.5 (users of Python 2.4 and 2.5 may use 2.1.3 version) +# 支持Python版本:2.7 to 3.5 # 支持操作系统: Linux, Windows, OSX, Sun Solaris, FreeBSD, OpenBSD and NetBSD, both 32-bit and 64-bit architectures -# 时间: 20180828 +# 时间: 20190128 SERVER = "127.0.0.1" PORT = 35601 @@ -62,9 +62,10 @@ class Traffic: def get(self): avgrx = 0; avgtx = 0 for name, stats in psutil.net_io_counters(pernic=True).iteritems(): - if name == "lo" or name.find("tun") > -1 \ - or name.find("docker") > -1 or name.find("veth") > -1 \ - or name.find("br-") > -1: + if "lo" in name or "tun" in name \ + or "docker" in name or "veth" in name \ + or "br-" in name or "vmbr" in name \ + or "vnet" in name: continue avgrx += stats.bytes_recv avgtx += stats.bytes_sent