in providers/linux/host_linux.go [113:135]
func (h *host) NetworkCounters() (*types.NetworkCountersInfo, error) {
snmpFile := h.procFS.path("net/snmp")
snmpRaw, err := os.ReadFile(snmpFile)
if err != nil {
return nil, fmt.Errorf("error fetching net/snmp file %s: %w", snmpFile, err)
}
snmp, err := getNetSnmpStats(snmpRaw)
if err != nil {
return nil, fmt.Errorf("error parsing SNMP stats: %w", err)
}
netstatFile := h.procFS.path("net/netstat")
netstatRaw, err := os.ReadFile(netstatFile)
if err != nil {
return nil, fmt.Errorf("error fetching net/netstat file %s: %w", netstatFile, err)
}
netstat, err := getNetstatStats(netstatRaw)
if err != nil {
return nil, fmt.Errorf("error parsing netstat file: %w", err)
}
return &types.NetworkCountersInfo{SNMP: snmp, Netstat: netstat}, nil
}