From 356c13e20ef4e346b820c156ba244a3379cfe526 Mon Sep 17 00:00:00 2001 From: kralewitz Date: Tue, 9 May 2023 14:33:19 +0200 Subject: [PATCH] Add metric representing bird socket query result (#82) A new gauge metric named `bird_socket_query_success` holds the result of querying the bird socket for protocol status. If set to 1, the socket was queried successfully. If the query fails for any of the configured sockets (IPv4 / IPv6), the value of this metric will be 0. Co-authored-by: Jan Kral --- metric_collector.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/metric_collector.go b/metric_collector.go index e52ba84..2e4fd8e 100644 --- a/metric_collector.go +++ b/metric_collector.go @@ -76,7 +76,17 @@ func exportersForDefault(c *client.BirdClient, descriptionLabels bool) map[proto } } +var socketQueryDesc = prometheus.NewDesc( + "bird_socket_query_success", + "Result of querying bird socket: 0 = failed, 1 = suceeded", + nil, + nil, +) + func (m *MetricCollector) Describe(ch chan<- *prometheus.Desc) { + + ch <- socketQueryDesc + for _, v := range m.exporters { for _, e := range v { e.Describe(ch) @@ -85,7 +95,15 @@ func (m *MetricCollector) Describe(ch chan<- *prometheus.Desc) { } func (m *MetricCollector) Collect(ch chan<- prometheus.Metric) { + protocols, err := m.client.GetProtocols() + + var queryResult float64 = 1 + if err != nil { + queryResult = 0 + } + ch <- prometheus.MustNewConstMetric(socketQueryDesc, prometheus.GaugeValue, queryResult) + if err != nil { log.Errorln(err) return