-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
82 lines (77 loc) · 2.15 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"fortio.org/fortio/fhttp"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func NewMetrics(reg prometheus.Registerer) *Metrics {
m := &Metrics{
RequestsReceivedTotal: prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "slackproxy",
Name: "requests_received_total",
Help: "The total number of requests received",
},
[]string{"channel"},
),
RequestsFailedTotal: prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "slackproxy",
Name: "requests_failed_total",
Help: "The total number of requests failed",
},
[]string{"channel"},
),
RequestsRetriedTotal: prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "slackproxy",
Name: "requests_retried_total",
Help: "The total number of requests retried",
},
[]string{"channel"},
),
RequestsSucceededTotal: prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "slackproxy",
Name: "requests_succeeded_total",
Help: "The total number of requests retried",
},
[]string{"channel"},
),
RequestsNotProcessed: prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "slackproxy",
Name: "requests_not_processed_total",
Help: "The total number of requests not processed",
},
[]string{"channel"},
),
QueueSize: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "slackproxy",
Name: "queue_size",
Help: "The current size of the queue",
},
nil,
),
}
reg.MustRegister(m.RequestsReceivedTotal)
reg.MustRegister(m.RequestsFailedTotal)
reg.MustRegister(m.RequestsRetriedTotal)
reg.MustRegister(m.RequestsSucceededTotal)
reg.MustRegister(m.RequestsNotProcessed)
reg.MustRegister(m.QueueSize)
return m
}
func StartMetricServer(reg *prometheus.Registry, addr string) {
mux, _ := fhttp.HTTPServer("metrics", addr)
mux.Handle("/metrics", promhttp.HandlerFor(
reg,
promhttp.HandlerOpts{
// Opt into OpenMetrics to support exemplars.
EnableOpenMetrics: true,
// Pass custom registry
Registry: reg,
},
))
}