过滤虚拟网卡流量
This commit is contained in:
@@ -912,12 +912,13 @@ func (c *Client) getSystemNetworkStats() (rxBytes, txBytes int64) {
|
|||||||
lines := strings.Split(string(data), "\n")
|
lines := strings.Split(string(data), "\n")
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
line = strings.TrimSpace(line)
|
line = strings.TrimSpace(line)
|
||||||
if strings.HasPrefix(line, "Inter") || strings.HasPrefix(line, "face") || strings.HasPrefix(line, "lo:") {
|
parts := strings.SplitN(line, ":", 2)
|
||||||
|
if len(parts) != 2 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
parts := strings.SplitN(line, ":", 2)
|
iface := strings.TrimSpace(parts[0])
|
||||||
if len(parts) != 2 {
|
if !isPhysicalInterface(iface) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -937,6 +938,21 @@ func (c *Client) getSystemNetworkStats() (rxBytes, txBytes int64) {
|
|||||||
return rxBytes, txBytes
|
return rxBytes, txBytes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var virtualInterfacePrefixes = []string{
|
||||||
|
"lo", "docker", "veth", "br-", "virbr", "vnet",
|
||||||
|
"flannel", "cni", "calico", "tunl", "wg",
|
||||||
|
"tailscale", "tun", "tap", "dummy",
|
||||||
|
}
|
||||||
|
|
||||||
|
func isPhysicalInterface(name string) bool {
|
||||||
|
for _, prefix := range virtualInterfacePrefixes {
|
||||||
|
if strings.HasPrefix(name, prefix) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// AuthError 表示鉴权失败错误。
|
// AuthError 表示鉴权失败错误。
|
||||||
type AuthError struct {
|
type AuthError struct {
|
||||||
Message string
|
Message string
|
||||||
|
|||||||
Reference in New Issue
Block a user