forked from kbudde/rabbitmq_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exporter_federation.go
59 lines (47 loc) · 1.47 KB
/
exporter_federation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"context"
"github.com/prometheus/client_golang/prometheus"
)
func init() {
RegisterExporter("federation", newExporterFederation)
}
var (
federationLabels = []string{"cluster", "vhost", "node", "queue", "exchange", "self", "status"}
federationLabelsKeys = []string{"vhost", "status", "node", "queue", "exchange"}
)
type exporterFederation struct {
stateMetric *prometheus.GaugeVec
}
func newExporterFederation() Exporter {
return exporterFederation{
stateMetric: newGaugeVec("federation_state", "A metric with a value of constant '1' for each federation in a certain state", federationLabels),
}
}
func (e exporterFederation) Collect(ctx context.Context, ch chan<- prometheus.Metric) error {
e.stateMetric.Reset()
federationData, err := getStatsInfo(config, "federation-links", federationLabelsKeys)
if err != nil {
return err
}
cluster := ""
if n, ok := ctx.Value(clusterName).(string); ok {
cluster = n
}
selfNode := ""
if n, ok := ctx.Value(nodeName).(string); ok {
selfNode = n
}
for _, federation := range federationData {
self := "0"
if federation.labels["node"] == selfNode {
self = "1"
}
e.stateMetric.WithLabelValues(cluster, federation.labels["vhost"], federation.labels["node"], federation.labels["queue"], federation.labels["exchange"], self, federation.labels["status"]).Set(1)
}
e.stateMetric.Collect(ch)
return nil
}
func (e exporterFederation) Describe(ch chan<- *prometheus.Desc) {
e.stateMetric.Describe(ch)
}