diff --git a/collector/fixtures/proc/net/snmp b/collector/fixtures/proc/net/snmp index 80a92b4730..271073a642 100644 --- a/collector/fixtures/proc/net/snmp +++ b/collector/fixtures/proc/net/snmp @@ -7,6 +7,6 @@ IcmpMsg: 104 120 Tcp: RtoAlgorithm RtoMin RtoMax MaxConn ActiveOpens PassiveOpens AttemptFails EstabResets CurrEstab InSegs OutSegs RetransSegs InErrs OutRsts InCsumErrors Tcp: 1 200 120000 -1 3556 230 341 161 0 57252008 54915039 227 5 1003 0 Udp: InDatagrams NoPorts InErrors OutDatagrams RcvbufErrors SndbufErrors InCsumErrors -Udp: 88542 120 0 53028 0 0 0 +Udp: 88542 120 0 53028 9 8 0 UdpLite: InDatagrams NoPorts InErrors OutDatagrams RcvbufErrors SndbufErrors InCsumErrors UdpLite: 0 0 0 0 0 0 0 diff --git a/collector/fixtures/proc/net/snmp6 b/collector/fixtures/proc/net/snmp6 index 8442d98e74..c5990270ae 100644 --- a/collector/fixtures/proc/net/snmp6 +++ b/collector/fixtures/proc/net/snmp6 @@ -80,6 +80,6 @@ UdpLite6InDatagrams 0 UdpLite6NoPorts 0 UdpLite6InErrors 0 UdpLite6OutDatagrams 0 -UdpLite6RcvbufErrors 0 -UdpLite6SndbufErrors 0 +UdpLite6RcvbufErrors 9 +UdpLite6SndbufErrors 8 UdpLite6InCsumErrors 0 diff --git a/collector/netstat_linux.go b/collector/netstat_linux.go index d5eed69603..b7c85b1f54 100644 --- a/collector/netstat_linux.go +++ b/collector/netstat_linux.go @@ -33,7 +33,7 @@ const ( ) var ( - netStatFields = kingpin.Flag("collector.netstat.fields", "Regexp of fields to return for netstat collector.").Default("^(.*_(InErrors|InErrs)|Ip_Forwarding|Ip(6|Ext)_(InOctets|OutOctets)|Icmp6?_(InMsgs|OutMsgs)|TcpExt_(Listen.*|Syncookies.*|TCPSynRetrans)|Tcp_(ActiveOpens|InSegs|OutSegs|PassiveOpens|RetransSegs|CurrEstab)|Udp6?_(InDatagrams|OutDatagrams|NoPorts))$").String() + netStatFields = kingpin.Flag("collector.netstat.fields", "Regexp of fields to return for netstat collector.").Default("^(.*_(InErrors|InErrs)|Ip_Forwarding|Ip(6|Ext)_(InOctets|OutOctets)|Icmp6?_(InMsgs|OutMsgs)|TcpExt_(Listen.*|Syncookies.*|TCPSynRetrans)|Tcp_(ActiveOpens|InSegs|OutSegs|PassiveOpens|RetransSegs|CurrEstab)|Udp6?_(InDatagrams|OutDatagrams|NoPorts|RcvbufErrors|SndbufErrors))$").String() ) type netStatCollector struct { diff --git a/collector/netstat_linux_test.go b/collector/netstat_linux_test.go index fde77a08dc..dae3d7ac86 100644 --- a/collector/netstat_linux_test.go +++ b/collector/netstat_linux_test.go @@ -20,6 +20,7 @@ import ( func TestNetStats(t *testing.T) { testNetStats(t, "fixtures/proc/net/netstat") + testSNMPStats(t, "fixtures/proc/net/snmp") testSNMP6Stats(t, "fixtures/proc/net/snmp6") } @@ -44,6 +45,27 @@ func testNetStats(t *testing.T, fileName string) { } } +func testSNMPStats(t *testing.T, fileName string) { + file, err := os.Open(fileName) + if err != nil { + t.Fatal(err) + } + defer file.Close() + + snmpStats, err := parseNetStats(file, fileName) + if err != nil { + t.Fatal(err) + } + + if want, got := "9", snmpStats["Udp"]["RcvbufErrors"]; want != got { + t.Errorf("want netstat Udp RcvbufErrors %s, got %s", want, got) + } + + if want, got := "8", snmpStats["Udp"]["SndbufErrors"]; want != got { + t.Errorf("want netstat Udp SndbufErrors %s, got %s", want, got) + } +} + func testSNMP6Stats(t *testing.T, fileName string) { file, err := os.Open(fileName) if err != nil { @@ -63,4 +85,12 @@ func testSNMP6Stats(t *testing.T, fileName string) { if want, got := "8", snmp6Stats["Icmp6"]["OutMsgs"]; want != got { t.Errorf("want netstat ICPM6 OutMsgs %s, got %s", want, got) } + + if want, got := "9", snmp6Stats["UdpLite6"]["RcvbufErrors"]; want != got { + t.Errorf("want netstat UdpLite6 RcvbufErrors %s, got %s", want, got) + } + + if want, got := "8", snmp6Stats["UdpLite6"]["SndbufErrors"]; want != got { + t.Errorf("want netstat UdpLite6 SndbufErrors %s, got %s", want, got) + } }