in providers/linux/procnet.go [82:104]
func parseNetFile(body string) (map[string]map[string]uint64, error) {
fileMetrics := make(map[string]map[string]uint64)
bodySplit := strings.Split(strings.TrimSpace(body), "\n")
// There should be an even number of lines. If not, something is wrong.
if len(bodySplit)%2 != 0 {
return nil, fmt.Errorf("badly parsed body: %s", body)
}
// in the network counters, data is divided into two-line sections: a line of keys, and a line of values
// With each line
for index := 0; index < len(bodySplit); index += 2 {
keysSplit := strings.Split(bodySplit[index], ":")
valuesSplit := strings.Split(bodySplit[index+1], ":")
if len(keysSplit) != 2 || len(valuesSplit) != 2 {
return nil, fmt.Errorf("wrong number of keys: %#v", keysSplit)
}
valMap, err := parseEntry(keysSplit[1], valuesSplit[1])
if err != nil {
return nil, fmt.Errorf("error parsing lines: %w", err)
}
fileMetrics[valuesSplit[0]] = valMap
}
return fileMetrics, nil
}