|
|
@ -7,6 +7,7 @@ import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"regexp"
|
|
|
|
"strconv"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
|
@ -18,6 +19,10 @@ const (
|
|
|
|
netDevSubsystem = "network"
|
|
|
|
netDevSubsystem = "network"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
|
|
|
fieldSep = regexp.MustCompile("[ :] *")
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type netDevCollector struct {
|
|
|
|
type netDevCollector struct {
|
|
|
|
config Config
|
|
|
|
config Config
|
|
|
|
metrics map[string]*prometheus.GaugeVec
|
|
|
|
metrics map[string]*prometheus.GaugeVec
|
|
|
@ -95,13 +100,14 @@ func parseNetDevStats(r io.Reader) (map[string]map[string]map[string]string, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
header := strings.Fields(parts[1])
|
|
|
|
header := strings.Fields(parts[1])
|
|
|
|
for scanner.Scan() {
|
|
|
|
for scanner.Scan() {
|
|
|
|
parts := strings.Fields(string(scanner.Text()))
|
|
|
|
line := strings.TrimLeft(string(scanner.Text()), " ")
|
|
|
|
|
|
|
|
parts := fieldSep.Split(line, -1)
|
|
|
|
if len(parts) != 2*len(header)+1 {
|
|
|
|
if len(parts) != 2*len(header)+1 {
|
|
|
|
return nil, fmt.Errorf("Invalid line in %s: %s",
|
|
|
|
return nil, fmt.Errorf("Invalid line in %s: %s",
|
|
|
|
procNetDev, scanner.Text())
|
|
|
|
procNetDev, scanner.Text())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
dev := parts[0][:len(parts[0])-1]
|
|
|
|
dev := parts[0][:len(parts[0])]
|
|
|
|
receive, err := parseNetDevLine(parts[1:len(header)+1], header)
|
|
|
|
receive, err := parseNetDevLine(parts[1:len(header)+1], header)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|