From 14eafab0167483b82757adccfd221bd1d2495a54 Mon Sep 17 00:00:00 2001 From: Phil Porada Date: Wed, 19 Feb 2020 08:41:40 -0500 Subject: [PATCH] Adds metrics and tests for UDP receive and send buffer errors (#1534) * Adds metrics for UDP receive and send buffer errors Signed-off-by: Phil Porada --- collector/fixtures/e2e-64k-page-output.txt | 12 +++++++++ collector/fixtures/e2e-output.txt | 12 +++++++++ collector/fixtures/proc/net/snmp | 2 +- collector/fixtures/proc/net/snmp6 | 4 +-- collector/netstat_linux.go | 2 +- collector/netstat_linux_test.go | 30 ++++++++++++++++++++++ 6 files changed, 58 insertions(+), 4 deletions(-) diff --git a/collector/fixtures/e2e-64k-page-output.txt b/collector/fixtures/e2e-64k-page-output.txt index aab19fcb..58ea964d 100644 --- a/collector/fixtures/e2e-64k-page-output.txt +++ b/collector/fixtures/e2e-64k-page-output.txt @@ -1903,6 +1903,12 @@ node_netstat_Udp6_NoPorts 0 # HELP node_netstat_Udp6_OutDatagrams Statistic Udp6OutDatagrams. # TYPE node_netstat_Udp6_OutDatagrams untyped node_netstat_Udp6_OutDatagrams 0 +# HELP node_netstat_Udp6_RcvbufErrors Statistic Udp6RcvbufErrors. +# TYPE node_netstat_Udp6_RcvbufErrors untyped +node_netstat_Udp6_RcvbufErrors 9 +# HELP node_netstat_Udp6_SndbufErrors Statistic Udp6SndbufErrors. +# TYPE node_netstat_Udp6_SndbufErrors untyped +node_netstat_Udp6_SndbufErrors 8 # HELP node_netstat_UdpLite6_InErrors Statistic UdpLite6InErrors. # TYPE node_netstat_UdpLite6_InErrors untyped node_netstat_UdpLite6_InErrors 0 @@ -1921,6 +1927,12 @@ node_netstat_Udp_NoPorts 120 # HELP node_netstat_Udp_OutDatagrams Statistic UdpOutDatagrams. # TYPE node_netstat_Udp_OutDatagrams untyped node_netstat_Udp_OutDatagrams 53028 +# HELP node_netstat_Udp_RcvbufErrors Statistic UdpRcvbufErrors. +# TYPE node_netstat_Udp_RcvbufErrors untyped +node_netstat_Udp_RcvbufErrors 9 +# HELP node_netstat_Udp_SndbufErrors Statistic UdpSndbufErrors. +# TYPE node_netstat_Udp_SndbufErrors untyped +node_netstat_Udp_SndbufErrors 8 # HELP node_network_address_assign_type address_assign_type value of /sys/class/net/. # TYPE node_network_address_assign_type gauge node_network_address_assign_type{device="eth0"} 3 diff --git a/collector/fixtures/e2e-output.txt b/collector/fixtures/e2e-output.txt index 38b76497..d0f49b20 100644 --- a/collector/fixtures/e2e-output.txt +++ b/collector/fixtures/e2e-output.txt @@ -1924,6 +1924,12 @@ node_netstat_Udp6_NoPorts 0 # HELP node_netstat_Udp6_OutDatagrams Statistic Udp6OutDatagrams. # TYPE node_netstat_Udp6_OutDatagrams untyped node_netstat_Udp6_OutDatagrams 0 +# HELP node_netstat_Udp6_RcvbufErrors Statistic Udp6RcvbufErrors. +# TYPE node_netstat_Udp6_RcvbufErrors untyped +node_netstat_Udp6_RcvbufErrors 9 +# HELP node_netstat_Udp6_SndbufErrors Statistic Udp6SndbufErrors. +# TYPE node_netstat_Udp6_SndbufErrors untyped +node_netstat_Udp6_SndbufErrors 8 # HELP node_netstat_UdpLite6_InErrors Statistic UdpLite6InErrors. # TYPE node_netstat_UdpLite6_InErrors untyped node_netstat_UdpLite6_InErrors 0 @@ -1942,6 +1948,12 @@ node_netstat_Udp_NoPorts 120 # HELP node_netstat_Udp_OutDatagrams Statistic UdpOutDatagrams. # TYPE node_netstat_Udp_OutDatagrams untyped node_netstat_Udp_OutDatagrams 53028 +# HELP node_netstat_Udp_RcvbufErrors Statistic UdpRcvbufErrors. +# TYPE node_netstat_Udp_RcvbufErrors untyped +node_netstat_Udp_RcvbufErrors 9 +# HELP node_netstat_Udp_SndbufErrors Statistic UdpSndbufErrors. +# TYPE node_netstat_Udp_SndbufErrors untyped +node_netstat_Udp_SndbufErrors 8 # HELP node_network_address_assign_type address_assign_type value of /sys/class/net/. # TYPE node_network_address_assign_type gauge node_network_address_assign_type{device="eth0"} 3 diff --git a/collector/fixtures/proc/net/snmp b/collector/fixtures/proc/net/snmp index 80a92b47..271073a6 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 8442d98e..3640bb1b 100644 --- a/collector/fixtures/proc/net/snmp6 +++ b/collector/fixtures/proc/net/snmp6 @@ -72,8 +72,8 @@ Udp6InDatagrams 0 Udp6NoPorts 0 Udp6InErrors 0 Udp6OutDatagrams 0 -Udp6RcvbufErrors 0 -Udp6SndbufErrors 0 +Udp6RcvbufErrors 9 +Udp6SndbufErrors 8 Udp6InCsumErrors 0 Udp6IgnoredMulti 0 UdpLite6InDatagrams 0 diff --git a/collector/netstat_linux.go b/collector/netstat_linux.go index f0aca26a..9b4be49f 100644 --- a/collector/netstat_linux.go +++ b/collector/netstat_linux.go @@ -34,7 +34,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 fde77a08..a27382b4 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["Udp6"]["RcvbufErrors"]; want != got { + t.Errorf("want netstat Udp6 RcvbufErrors %s, got %s", want, got) + } + + if want, got := "8", snmp6Stats["Udp6"]["SndbufErrors"]; want != got { + t.Errorf("want netstat Udp6 SndbufErrors %s, got %s", want, got) + } }