forked from Syncano/rabbitmq_exporter
-
Notifications
You must be signed in to change notification settings - Fork 197
/
exporter_federation.go
56 lines (44 loc) · 1.46 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
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 := selfLabel(config, federation.labels["node"] == selfNode)
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)
}