forked from jllopis/mifo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prometheus.go
36 lines (29 loc) · 966 Bytes
/
prometheus.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 mifo
import (
"github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/jllopis/mifo/log"
"github.com/prometheus/client_golang/prometheus"
)
type PrometheusInterceptorConfig struct {
EndPoint string
EnableTimeHistogram bool
}
func (p *PrometheusInterceptorConfig) Init(g *GrpcServer) {
log.Info("called Init on Prometheus Interceptor")
if p.EnableTimeHistogram {
grpc_prometheus.EnableHandlingTimeHistogram()
}
grpc_prometheus.Register(g.GrpcSrv)
}
func (g *GrpcServer) UsePrometheus(conf *PrometheusInterceptorConfig) *GrpcServer {
// Default interceptors, [prometheus, opentracing]
g.UseUnaryInterceptor(grpc_prometheus.UnaryServerInterceptor)
g.UseStreamInterceptor(grpc_prometheus.StreamServerInterceptor)
if conf != nil && conf.EndPoint != "" {
g.HttpMux.Handle(conf.EndPoint, prometheus.Handler())
} else {
g.HttpMux.Handle("/metrics", prometheus.Handler())
}
g.RegisterInterceptorInitializer(conf)
return g
}