Skip to content

Commit 13f019f

Browse files
committed
Break udp_queues into udp_{queues,drops_total}
This separates the gauges related to udp_queues and the counter related to the total number of drops, but keeps them under the same namespace. Signed-off-by: Chris Cleeland <[email protected]>
1 parent 62b30d6 commit 13f019f

File tree

5 files changed

+31
-21
lines changed

5 files changed

+31
-21
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ thermal | Exposes thermal statistics like `pmset -g therm`. | Darwin
158158
thermal\_zone | Exposes thermal zone & cooling device statistics from `/sys/class/thermal`. | Linux
159159
time | Exposes the current system time. | _any_
160160
timex | Exposes selected adjtimex(2) system call stats. | Linux
161-
udp_queues | Exposes UDP total lengths of the rx_queue and tx_queue from `/proc/net/udp` and `/proc/net/udp6`. | Linux
161+
udp | Exposes UDP statistics from `/proc/net/udp` and `/proc/net/udp6`. | Linux
162162
uname | Exposes system information as provided by the uname system call. | Darwin, FreeBSD, Linux, OpenBSD
163163
vmstat | Exposes statistics from `/proc/vmstat`. | Linux
164164
watchdog | Exposes statistics from `/sys/class/watchdog` | Linux

collector/fixtures/e2e-64k-page-output.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2991,7 +2991,7 @@ node_scrape_collector_success{collector="tapestats"} 1
29912991
node_scrape_collector_success{collector="textfile"} 1
29922992
node_scrape_collector_success{collector="thermal_zone"} 1
29932993
node_scrape_collector_success{collector="time"} 1
2994-
node_scrape_collector_success{collector="udp_queues"} 1
2994+
node_scrape_collector_success{collector="udp"} 1
29952995
node_scrape_collector_success{collector="vmstat"} 1
29962996
node_scrape_collector_success{collector="watchdog"} 1
29972997
node_scrape_collector_success{collector="wifi"} 1
@@ -3242,9 +3242,11 @@ node_time_clocksource_current_info{clocksource="tsc",device="0"} 1
32423242
# TYPE node_time_seconds gauge
32433243
# HELP node_time_zone_offset_seconds System time zone offset in seconds.
32443244
# TYPE node_time_zone_offset_seconds gauge
3245+
# HELP node_udp_drops_total Total number of datagrams dropped.
3246+
# TYPE node_udp_drops_total counter
3247+
node_udp_drops_total{ip="v4"} 100
32453248
# HELP node_udp_queues Number of allocated memory in the kernel for UDP datagrams in bytes.
3246-
# TYPE node_udp_queues counter
3247-
node_udp_queues{ip="v4",queue="drops"} 100
3249+
# TYPE node_udp_queues gauge
32483250
node_udp_queues{ip="v4",queue="rx"} 0
32493251
node_udp_queues{ip="v4",queue="tx"} 21
32503252
# HELP node_vmstat_oom_kill /proc/vmstat information field oom_kill.

collector/fixtures/e2e-output.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3013,7 +3013,7 @@ node_scrape_collector_success{collector="tapestats"} 1
30133013
node_scrape_collector_success{collector="textfile"} 1
30143014
node_scrape_collector_success{collector="thermal_zone"} 1
30153015
node_scrape_collector_success{collector="time"} 1
3016-
node_scrape_collector_success{collector="udp_queues"} 1
3016+
node_scrape_collector_success{collector="udp"} 1
30173017
node_scrape_collector_success{collector="vmstat"} 1
30183018
node_scrape_collector_success{collector="watchdog"} 1
30193019
node_scrape_collector_success{collector="wifi"} 1
@@ -3264,9 +3264,11 @@ node_time_clocksource_current_info{clocksource="tsc",device="0"} 1
32643264
# TYPE node_time_seconds gauge
32653265
# HELP node_time_zone_offset_seconds System time zone offset in seconds.
32663266
# TYPE node_time_zone_offset_seconds gauge
3267+
# HELP node_udp_drops_total Total number of datagrams dropped.
3268+
# TYPE node_udp_drops_total counter
3269+
node_udp_drops_total{ip="v4"} 100
32673270
# HELP node_udp_queues Number of allocated memory in the kernel for UDP datagrams in bytes.
3268-
# TYPE node_udp_queues counter
3269-
node_udp_queues{ip="v4",queue="drops"} 100
3271+
# TYPE node_udp_queues gauge
32703272
node_udp_queues{ip="v4",queue="rx"} 0
32713273
node_udp_queues{ip="v4",queue="tx"} 21
32723274
# HELP node_vmstat_oom_kill /proc/vmstat information field oom_kill.

collector/udp_queues_linux.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,42 +27,48 @@ import (
2727
)
2828

2929
type (
30-
udpQueuesCollector struct {
30+
udpCollector struct {
3131
fs procfs.FS
32-
desc *prometheus.Desc
32+
queues *prometheus.Desc
33+
drops *prometheus.Desc
3334
logger *slog.Logger
3435
}
3536
)
3637

3738
func init() {
38-
registerCollector("udp_queues", defaultEnabled, NewUDPqueuesCollector)
39+
registerCollector("udp", defaultEnabled, NewUDPCollector)
3940
}
4041

4142
// NewUDPqueuesCollector returns a new Collector exposing network udp queued bytes.
42-
func NewUDPqueuesCollector(logger *slog.Logger) (Collector, error) {
43+
func NewUDPCollector(logger *slog.Logger) (Collector, error) {
4344
fs, err := procfs.NewFS(*procPath)
4445
if err != nil {
4546
return nil, fmt.Errorf("failed to open procfs: %w", err)
4647
}
47-
return &udpQueuesCollector{
48+
return &udpCollector{
4849
fs: fs,
49-
desc: prometheus.NewDesc(
50+
queues: prometheus.NewDesc(
5051
prometheus.BuildFQName(namespace, "udp", "queues"),
5152
"Number of allocated memory in the kernel for UDP datagrams in bytes.",
5253
[]string{"queue", "ip"}, nil,
5354
),
55+
drops: prometheus.NewDesc(
56+
prometheus.BuildFQName(namespace, "udp", "drops_total"),
57+
"Total number of datagrams dropped.",
58+
[]string{"ip"}, nil,
59+
),
5460
logger: logger,
5561
}, nil
5662
}
5763

58-
func (c *udpQueuesCollector) Update(ch chan<- prometheus.Metric) error {
64+
func (c *udpCollector) Update(ch chan<- prometheus.Metric) error {
5965

6066
s4, errIPv4 := c.fs.NetUDPSummary()
6167
if errIPv4 == nil {
62-
ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s4.TxQueueLength), "tx", "v4")
63-
ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s4.RxQueueLength), "rx", "v4")
68+
ch <- prometheus.MustNewConstMetric(c.queues, prometheus.GaugeValue, float64(s4.TxQueueLength), "tx", "v4")
69+
ch <- prometheus.MustNewConstMetric(c.queues, prometheus.GaugeValue, float64(s4.RxQueueLength), "rx", "v4")
6470
if s4.Drops != nil {
65-
ch <- prometheus.MustNewConstMetric(c.desc, prometheus.CounterValue, float64(*s4.Drops), "drops", "v4")
71+
ch <- prometheus.MustNewConstMetric(c.drops, prometheus.CounterValue, float64(*s4.Drops), "v4")
6672
}
6773
} else {
6874
if errors.Is(errIPv4, os.ErrNotExist) {
@@ -74,10 +80,10 @@ func (c *udpQueuesCollector) Update(ch chan<- prometheus.Metric) error {
7480

7581
s6, errIPv6 := c.fs.NetUDP6Summary()
7682
if errIPv6 == nil {
77-
ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s6.TxQueueLength), "tx", "v6")
78-
ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s6.RxQueueLength), "rx", "v6")
83+
ch <- prometheus.MustNewConstMetric(c.queues, prometheus.GaugeValue, float64(s6.TxQueueLength), "tx", "v6")
84+
ch <- prometheus.MustNewConstMetric(c.queues, prometheus.GaugeValue, float64(s6.RxQueueLength), "rx", "v6")
7985
if s6.Drops != nil {
80-
ch <- prometheus.MustNewConstMetric(c.desc, prometheus.CounterValue, float64(*s6.Drops), "drops", "v6")
86+
ch <- prometheus.MustNewConstMetric(c.drops, prometheus.CounterValue, float64(*s6.Drops), "v6")
8187
}
8288
} else {
8389
if errors.Is(errIPv6, os.ErrNotExist) {

end-to-end-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ enabled_collectors=$(cat << COLLECTORS
4747
sysctl
4848
textfile
4949
thermal_zone
50-
udp_queues
50+
udp
5151
vmstat
5252
watchdog
5353
wifi

0 commit comments

Comments
 (0)