From c253f75cff669108a820fd4d5b9a96361af3d56f Mon Sep 17 00:00:00 2001 From: ubuntu Date: Tue, 29 Jan 2019 15:44:30 +0800 Subject: [PATCH] filter kvm or bridge traffic statustics --- clients/client-linux.py | 9 +++++---- clients/client-psutil.py | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/clients/client-linux.py b/clients/client-linux.py index 0a1b1cbc..bf408033 100755 --- a/clients/client-linux.py +++ b/clients/client-linux.py @@ -91,9 +91,9 @@ def get(self): for dev in net_dev[2:]: dev = dev.split(':') 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]: + 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] or "kube" in dev[0]: continue dev = dev[1].split() avgrx += int(dev[0]) @@ -122,7 +122,8 @@ def liuliang(): if netinfo: if netinfo[0][0] == 'lo' or 'tun' in netinfo[0][0] \ or 'docker' in netinfo[0][0] or 'veth' in netinfo[0][0] \ - or 'br-' in netinfo[0][0] \ + or 'br-' in netinfo[0][0] or 'vmbr' in netinfo[0][0] \ + or 'vnet' in netinfo[0][0] or 'kube' in netinfo[0][0] \ or netinfo[0][1]=='0' or netinfo[0][9]=='0': continue else: diff --git a/clients/client-psutil.py b/clients/client-psutil.py index b611247b..39cf0510 100755 --- a/clients/client-psutil.py +++ b/clients/client-psutil.py @@ -65,7 +65,7 @@ def get(self): 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: + or "vnet" in name or "kube" in name: continue avgrx += stats.bytes_recv avgtx += stats.bytes_sent @@ -89,9 +89,10 @@ def liuliang(): NET_OUT = 0 net = psutil.net_io_counters(pernic=True) for k, v in net.items(): - if k == 'lo' or 'tun' in k \ - or 'br-' in k \ - or 'docker' in k or 'veth' in k: + if 'lo' in k or 'tun' in k \ + or 'docker' in k or 'veth' in k \ + or 'br-' in k or 'vmbr' in k \ + or 'vnet' in k or 'kube' in k: continue else: NET_IN += v[1]