diff --git a/collector/fixtures/proc/net/sockstat_rhe4 b/collector/fixtures/proc/net/sockstat_rhe4 new file mode 100644 index 00000000..1e178f36 --- /dev/null +++ b/collector/fixtures/proc/net/sockstat_rhe4 @@ -0,0 +1,5 @@ +sockets: used 229 +TCP: inuse 4 orphan 0 tw 4 alloc 17 mem 1 +UDP: inuse 0 +RAW: inuse 0 +FRAG: inuse 0 memory 0 diff --git a/collector/sockstat_linux.go b/collector/sockstat_linux.go index bafa49ab..0223fe43 100644 --- a/collector/sockstat_linux.go +++ b/collector/sockstat_linux.go @@ -117,11 +117,13 @@ func parseSockStats(r io.Reader, fileName string) (map[string]map[string]string, sockStat["TCP"]["mem_bytes"] = strconv.Itoa(pageCount * pageSize) // Update the UDP mem from page count to bytes. - pageCount, err = strconv.Atoi(sockStat["UDP"]["mem"]) - if err != nil { - return nil, fmt.Errorf("invalid value %s in sockstats: %s", sockStat["UDP"]["mem"], err) + if udpMem := sockStat["UDP"]["mem"]; udpMem != "" { + pageCount, err = strconv.Atoi(udpMem) + if err != nil { + return nil, fmt.Errorf("invalid value %s in sockstats: %s", sockStat["UDP"]["mem"], err) + } + sockStat["UDP"]["mem_bytes"] = strconv.Itoa(pageCount * pageSize) } - sockStat["UDP"]["mem_bytes"] = strconv.Itoa(pageCount * pageSize) return sockStat, nil } diff --git a/collector/sockstat_linux_test.go b/collector/sockstat_linux_test.go index 989a93b3..fce81104 100644 --- a/collector/sockstat_linux_test.go +++ b/collector/sockstat_linux_test.go @@ -20,7 +20,12 @@ import ( ) func TestSockStats(t *testing.T) { - file, err := os.Open("fixtures/proc/net/sockstat") + testSockStats(t, "fixtures/proc/net/sockstat") + testSockStats(t, "fixtures/proc/net/sockstat_rhe4") +} + +func testSockStats(t *testing.T, fixture string) { + file, err := os.Open(fixture) if err != nil { t.Fatal(err) }