forked from kbudde/rabbitmq_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exporter_connections.go
67 lines (54 loc) · 1.79 KB
/
exporter_connections.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
60
61
62
63
64
65
66
67
package main
import (
"github.com/prometheus/client_golang/prometheus"
)
func init() {
RegisterExporter("connections", newExporterConnections)
}
var (
connectionLabels = []string{"vhost", "node", "peer_host", "user"}
connectionGaugeVec = map[string]*prometheus.GaugeVec{
"channels": newGaugeVec("connection_channels", "number of channels in use", connectionLabels),
"recv_oct": newGaugeVec("connection_received_bytes", "received bytes", connectionLabels),
"recv_cnt": newGaugeVec("connection_received_packets", "received packets", connectionLabels),
"send_oct": newGaugeVec("connection_send_bytes", "send bytes", connectionLabels),
"send_cnt": newGaugeVec("connection_send_packets", "send packets", connectionLabels),
"send_pend": newGaugeVec("connection_send_pending", "Send queue size", connectionLabels),
}
)
type exporterConnections struct {
metricsGV map[string]*prometheus.GaugeVec
}
func newExporterConnections() Exporter {
return exporterConnections{
metricsGV: connectionGaugeVec,
}
}
func (e exporterConnections) String() string {
return "Exporter connections"
}
func (e exporterConnections) Collect(ch chan<- prometheus.Metric) error {
connectionData, err := getStatsInfo(config, "connections", connectionLabels)
if err != nil {
return err
}
for _, gauge := range e.metricsGV {
gauge.Reset()
}
for key, gauge := range e.metricsGV {
for _, connD := range connectionData {
if value, ok := connD.metrics[key]; ok {
gauge.WithLabelValues(connD.labels["vhost"], connD.labels["node"], connD.labels["peer_host"], connD.labels["user"]).Add(value)
}
}
}
for _, gauge := range e.metricsGV {
gauge.Collect(ch)
}
return nil
}
func (e exporterConnections) Describe(ch chan<- *prometheus.Desc) {
for _, nodeMetric := range e.metricsGV {
nodeMetric.Describe(ch)
}
}