From 66c5b5e05ce663795443da570c86a4eb0180ecff Mon Sep 17 00:00:00 2001 From: "zhiqiang.wang" Date: Tue, 21 Jun 2022 13:41:08 +0800 Subject: [PATCH] fix: https://github.com/cppla/ServerStatus/issues/176#issuecomment-1161143160 --- client/base.go | 24 +++++++++++++++++------- client/client.go | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/client/base.go b/client/base.go index a38fa5a..cd2f1f0 100644 --- a/client/base.go +++ b/client/base.go @@ -81,7 +81,6 @@ func (c *Client) getTraffic(ret *update) { var inters = []string{ "lo", - "eth", "tun", "docker", "veth", @@ -89,17 +88,28 @@ func (c *Client) getTraffic(ret *update) { "vmbr", "vnet", "kube", + "ip_", } - for _, info := range items { - for _, v := range inters { - if !strings.Contains(info.Name, v) { - continue + var contains = func(s string, subStr []string) bool { + for _, v := range subStr { + if strings.Contains(s, v) { + + return true } + } + + return false + } + + for _, info := range items { + if contains(info.Name, inters) { - data.in += info.BytesRecv - data.out += info.BytesSent + continue } + + data.in += info.BytesRecv + data.out += info.BytesSent } ret.NetWorkIn = data.in diff --git a/client/client.go b/client/client.go index 0f3b1e0..818d923 100644 --- a/client/client.go +++ b/client/client.go @@ -12,7 +12,7 @@ import ( "time" ) -const Version = 0.13 +const Version = 0.14 const DefaultServer = "127.0.0.1" const DefaultPort = 35601 const DefaultInterval = 1