-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmetrics.go
48 lines (39 loc) · 1.25 KB
/
metrics.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
package shoveler
import (
"net/http"
"strconv"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
PacketsReceived = promauto.NewCounter(prometheus.CounterOpts{
Name: "shoveler_packets_received",
Help: "The total number of packets received",
})
ValidationsFailed = promauto.NewCounter(prometheus.CounterOpts{
Name: "shoveler_validations_failed",
Help: "The total number of packets that failed validation",
})
RabbitmqReconnects = promauto.NewCounter(prometheus.CounterOpts{
Name: "shoveler_rabbitmq_reconnects",
Help: "The total number of reconnections to rabbitmq bus",
})
QueueSize = promauto.NewGauge(prometheus.GaugeOpts{
Name: "shoveler_queue_size",
Help: "The number of messages in the queue",
})
)
func StartMetrics(metricsPort int) {
// Listen to the metrics requests in a separate thread
go func() {
listenAddress := ":" + strconv.Itoa(metricsPort)
log.Debugln("Starting metrics at " + listenAddress + "/metrics")
http.Handle("/metrics", promhttp.Handler())
err := http.ListenAndServe(listenAddress, nil)
if err != nil {
log.Errorln("Failed to listen and serve metrics:", err)
return
}
}()
}