fix: return error when requested interface has no stats available (#17666)

This commit is contained in:
drivebyer 2023-07-17 16:14:01 +08:00 committed by GitHub
parent d118031ed6
commit 9b5c2c386a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -18,6 +18,8 @@
package net
import (
"fmt"
"github.com/prometheus/procfs"
)
@ -31,5 +33,9 @@ func GetInterfaceNetStats(interf string) (procfs.NetDevLine, error) {
if err != nil {
return procfs.NetDevLine{}, err
}
return netDev[interf], nil
ndl, ok := netDev[interf]
if !ok {
return procfs.NetDevLine{}, fmt.Errorf("%v interface not found", interf)
}
return ndl, nil
}