@@ -27,42 +27,48 @@ import (
27
27
)
28
28
29
29
type (
30
- udpQueuesCollector struct {
30
+ udpCollector struct {
31
31
fs procfs.FS
32
- desc * prometheus.Desc
32
+ queues * prometheus.Desc
33
+ drops * prometheus.Desc
33
34
logger * slog.Logger
34
35
}
35
36
)
36
37
37
38
func init () {
38
- registerCollector ("udp_queues " , defaultEnabled , NewUDPqueuesCollector )
39
+ registerCollector ("udp " , defaultEnabled , NewUDPCollector )
39
40
}
40
41
41
42
// 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 ) {
43
44
fs , err := procfs .NewFS (* procPath )
44
45
if err != nil {
45
46
return nil , fmt .Errorf ("failed to open procfs: %w" , err )
46
47
}
47
- return & udpQueuesCollector {
48
+ return & udpCollector {
48
49
fs : fs ,
49
- desc : prometheus .NewDesc (
50
+ queues : prometheus .NewDesc (
50
51
prometheus .BuildFQName (namespace , "udp" , "queues" ),
51
52
"Number of allocated memory in the kernel for UDP datagrams in bytes." ,
52
53
[]string {"queue" , "ip" }, nil ,
53
54
),
55
+ drops : prometheus .NewDesc (
56
+ prometheus .BuildFQName (namespace , "udp" , "drops_total" ),
57
+ "Total number of datagrams dropped." ,
58
+ []string {"ip" }, nil ,
59
+ ),
54
60
logger : logger ,
55
61
}, nil
56
62
}
57
63
58
- func (c * udpQueuesCollector ) Update (ch chan <- prometheus.Metric ) error {
64
+ func (c * udpCollector ) Update (ch chan <- prometheus.Metric ) error {
59
65
60
66
s4 , errIPv4 := c .fs .NetUDPSummary ()
61
67
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" )
64
70
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" )
66
72
}
67
73
} else {
68
74
if errors .Is (errIPv4 , os .ErrNotExist ) {
@@ -74,10 +80,10 @@ func (c *udpQueuesCollector) Update(ch chan<- prometheus.Metric) error {
74
80
75
81
s6 , errIPv6 := c .fs .NetUDP6Summary ()
76
82
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" )
79
85
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" )
81
87
}
82
88
} else {
83
89
if errors .Is (errIPv6 , os .ErrNotExist ) {
0 commit comments