-
-
Notifications
You must be signed in to change notification settings - Fork 269
/
metrics.go
56 lines (45 loc) · 1.33 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
package gateway
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/brocaar/lora-gateway-bridge/internal/metrics"
)
var (
gatewayEventCounter func(string)
gatewayWriteUDPTimer func(string, func() error) error
gatewayHandleTimer func(string, func() error) error
gatewayConfigHandleTimer func(func() error) error
)
func init() {
ec := metrics.MustRegisterNewCounter(
"gateway_event",
"Per event type counter.",
[]string{"event"},
)
wt := metrics.MustRegisterNewTimerWithError(
"gateway_udp_write",
"Per message-type UDP write duration tracking.",
[]string{"type"},
)
ht := metrics.MustRegisterNewTimerWithError(
"gateway_udp_received_handle",
"Per message-type received UDP handling duration tracking.",
[]string{"type"},
)
ch := metrics.MustRegisterNewTimerWithError(
"gateway_config_handle",
"Tracks the duration of configuration handling.",
[]string{},
)
gatewayEventCounter = func(event string) {
ec(prometheus.Labels{"event": event})
}
gatewayWriteUDPTimer = func(mType string, f func() error) error {
return wt(prometheus.Labels{"type": mType}, f)
}
gatewayHandleTimer = func(mType string, f func() error) error {
return ht(prometheus.Labels{"type": mType}, f)
}
gatewayConfigHandleTimer = func(f func() error) error {
return ch(prometheus.Labels{}, f)
}
}