-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
metrics.go
49 lines (41 loc) · 1.26 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
49
package wsrpc
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
type reqStatus string
const (
statusSuccess reqStatus = "success"
statusFailed reqStatus = "failed"
)
var (
aliveMetric = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "mercury",
Name: "wsrpc_connection_alive",
Help: "Total time spent connected to the Mercury WSRPC server",
})
requestsStatusMetric = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: "mercury",
Name: "wsrpc_requests_status_count",
Help: "Number of request status made to the Mercury WSRPC server",
}, []string{"status"})
requestLatencyMetric = promauto.NewHistogram(prometheus.HistogramOpts{
Namespace: "mercury",
Name: "wsrpc_request_latency",
Help: "Latency of requests made to the Mercury WSRPC server",
Buckets: []float64{10, 30, 100, 200, 250, 300, 350, 400, 500, 750, 1000, 3000, 10000},
})
)
func setLivenessMetric(live bool) {
if live {
aliveMetric.Set(1)
} else {
aliveMetric.Set(0)
}
}
func incRequestStatusMetric(status reqStatus) {
requestsStatusMetric.WithLabelValues(string(status)).Inc()
}
func setRequestLatencyMetric(latency float64) {
requestLatencyMetric.Observe(latency)
}