Skip to content

Commit

Permalink
Add metric representing bird socket query result (#82)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kralewitz and Jan Kral authored May 9, 2023
1 parent ca13cd9 commit 356c13e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions metric_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 356c13e

Please sign in to comment.