-
Notifications
You must be signed in to change notification settings - Fork 175
/
observer.go
36 lines (30 loc) · 957 Bytes
/
observer.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
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"google.golang.org/grpc/codes"
)
type ObserverMetrics interface {
RecordRPC(handler, rpc string, code codes.Code)
}
type ObserverCollector struct {
rpcs *prometheus.CounterVec
}
var _ ObserverMetrics = (*ObserverCollector)(nil)
func NewObserverCollector() *ObserverCollector {
return &ObserverCollector{
rpcs: promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: namespaceObserver,
Subsystem: subsystemObserverGRPC,
Name: "handler_grpc_counter",
Help: "tracking error/success rate of each rpc for the observer service",
}, []string{"handler", "grpc_method", "grpc_code"}),
}
}
func (oc *ObserverCollector) RecordRPC(handler, rpc string, code codes.Code) {
oc.rpcs.With(prometheus.Labels{
"handler": handler,
"grpc_method": rpc,
"grpc_code": code.String(),
}).Inc()
}