Skip to content

Commit

Permalink
Adds metrics and tests for UDP receive and send buffer errors (promet…
Browse files Browse the repository at this point in the history
…heus#1534)

* Adds metrics for UDP receive and send buffer errors

Signed-off-by: Phil Porada <philporada@gmail.com>
  • Loading branch information
pgporada authored and oblitorum committed Apr 9, 2024
1 parent bed646c commit eec00ca
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 4 deletions.
12 changes: 12 additions & 0 deletions collector/fixtures/e2e-64k-page-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/<iface>.
# TYPE node_network_address_assign_type gauge
node_network_address_assign_type{device="eth0"} 3
Expand Down
12 changes: 12 additions & 0 deletions collector/fixtures/e2e-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2196,6 +2196,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
Expand All @@ -2214,6 +2220,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/<iface>.
# TYPE node_network_address_assign_type gauge
node_network_address_assign_type{device="eth0"} 3
Expand Down
2 changes: 1 addition & 1 deletion collector/fixtures/proc/net/snmp
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions collector/fixtures/proc/net/snmp6
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion collector/netstat_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
30 changes: 30 additions & 0 deletions collector/netstat_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand All @@ -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 {
Expand All @@ -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)
}
}

0 comments on commit eec00ca

Please sign in to comment.