|
|
|
|
@ -26,40 +26,49 @@ import ( |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
type ( |
|
|
|
|
udpQueuesCollector struct { |
|
|
|
|
udpCollector struct { |
|
|
|
|
fs procfs.FS |
|
|
|
|
desc *prometheus.Desc |
|
|
|
|
queues *prometheus.Desc |
|
|
|
|
drops *prometheus.Desc |
|
|
|
|
logger *slog.Logger |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func init() { |
|
|
|
|
registerCollector("udp_queues", defaultEnabled, NewUDPqueuesCollector) |
|
|
|
|
registerCollector("udp", defaultEnabled, NewUDPCollector) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewUDPqueuesCollector returns a new Collector exposing network udp queued bytes.
|
|
|
|
|
func NewUDPqueuesCollector(logger *slog.Logger) (Collector, error) { |
|
|
|
|
func NewUDPCollector(logger *slog.Logger) (Collector, error) { |
|
|
|
|
fs, err := procfs.NewFS(*procPath) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, fmt.Errorf("failed to open procfs: %w", err) |
|
|
|
|
} |
|
|
|
|
return &udpQueuesCollector{ |
|
|
|
|
return &udpCollector{ |
|
|
|
|
fs: fs, |
|
|
|
|
desc: prometheus.NewDesc( |
|
|
|
|
queues: prometheus.NewDesc( |
|
|
|
|
prometheus.BuildFQName(namespace, "udp", "queues"), |
|
|
|
|
"Number of allocated memory in the kernel for UDP datagrams in bytes.", |
|
|
|
|
[]string{"queue", "ip"}, nil, |
|
|
|
|
), |
|
|
|
|
drops: prometheus.NewDesc( |
|
|
|
|
prometheus.BuildFQName(namespace, "udp", "drops_total"), |
|
|
|
|
"Total number of datagrams dropped.", |
|
|
|
|
[]string{"ip"}, nil, |
|
|
|
|
), |
|
|
|
|
logger: logger, |
|
|
|
|
}, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (c *udpQueuesCollector) Update(ch chan<- prometheus.Metric) error { |
|
|
|
|
func (c *udpCollector) Update(ch chan<- prometheus.Metric) error { |
|
|
|
|
|
|
|
|
|
s4, errIPv4 := c.fs.NetUDPSummary() |
|
|
|
|
if errIPv4 == nil { |
|
|
|
|
ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s4.TxQueueLength), "tx", "v4") |
|
|
|
|
ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s4.RxQueueLength), "rx", "v4") |
|
|
|
|
ch <- prometheus.MustNewConstMetric(c.queues, prometheus.GaugeValue, float64(s4.TxQueueLength), "tx", "v4") |
|
|
|
|
ch <- prometheus.MustNewConstMetric(c.queues, prometheus.GaugeValue, float64(s4.RxQueueLength), "rx", "v4") |
|
|
|
|
if s4.Drops != nil { |
|
|
|
|
ch <- prometheus.MustNewConstMetric(c.drops, prometheus.CounterValue, float64(*s4.Drops), "v4") |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if errors.Is(errIPv4, os.ErrNotExist) { |
|
|
|
|
c.logger.Debug("not collecting ipv4 based metrics") |
|
|
|
|
@ -70,8 +79,11 @@ func (c *udpQueuesCollector) Update(ch chan<- prometheus.Metric) error { |
|
|
|
|
|
|
|
|
|
s6, errIPv6 := c.fs.NetUDP6Summary() |
|
|
|
|
if errIPv6 == nil { |
|
|
|
|
ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s6.TxQueueLength), "tx", "v6") |
|
|
|
|
ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s6.RxQueueLength), "rx", "v6") |
|
|
|
|
ch <- prometheus.MustNewConstMetric(c.queues, prometheus.GaugeValue, float64(s6.TxQueueLength), "tx", "v6") |
|
|
|
|
ch <- prometheus.MustNewConstMetric(c.queues, prometheus.GaugeValue, float64(s6.RxQueueLength), "rx", "v6") |
|
|
|
|
if s6.Drops != nil { |
|
|
|
|
ch <- prometheus.MustNewConstMetric(c.drops, prometheus.CounterValue, float64(*s6.Drops), "v6") |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if errors.Is(errIPv6, os.ErrNotExist) { |
|
|
|
|
c.logger.Debug("not collecting ipv6 based metrics") |
|
|
|
|
|