2019-01-12 04:58:27 +00:00
|
|
|
// Copyright 2016 Michal Witkowski. All Rights Reserved.
|
|
|
|
// See LICENSE for licensing terms.
|
|
|
|
|
|
|
|
// gRPC Prometheus monitoring interceptors for client-side gRPC.
|
|
|
|
|
|
|
|
package grpc_prometheus
|
|
|
|
|
|
|
|
import (
|
2019-09-27 21:51:53 +00:00
|
|
|
prom "github.com/prometheus/client_golang/prometheus"
|
2019-01-12 04:58:27 +00:00
|
|
|
)
|
|
|
|
|
2019-09-27 21:51:53 +00:00
|
|
|
var (
|
|
|
|
// DefaultClientMetrics is the default instance of ClientMetrics. It is
|
|
|
|
// intended to be used in conjunction the default Prometheus metrics
|
|
|
|
// registry.
|
|
|
|
DefaultClientMetrics = NewClientMetrics()
|
2019-01-12 04:58:27 +00:00
|
|
|
|
2019-09-27 21:51:53 +00:00
|
|
|
// UnaryClientInterceptor is a gRPC client-side interceptor that provides Prometheus monitoring for Unary RPCs.
|
|
|
|
UnaryClientInterceptor = DefaultClientMetrics.UnaryClientInterceptor()
|
2019-01-12 04:58:27 +00:00
|
|
|
|
2019-09-27 21:51:53 +00:00
|
|
|
// StreamClientInterceptor is a gRPC client-side interceptor that provides Prometheus monitoring for Streaming RPCs.
|
|
|
|
StreamClientInterceptor = DefaultClientMetrics.StreamClientInterceptor()
|
|
|
|
)
|
2019-01-12 04:58:27 +00:00
|
|
|
|
2019-09-27 21:51:53 +00:00
|
|
|
func init() {
|
|
|
|
prom.MustRegister(DefaultClientMetrics.clientStartedCounter)
|
|
|
|
prom.MustRegister(DefaultClientMetrics.clientHandledCounter)
|
|
|
|
prom.MustRegister(DefaultClientMetrics.clientStreamMsgReceived)
|
|
|
|
prom.MustRegister(DefaultClientMetrics.clientStreamMsgSent)
|
2019-01-12 04:58:27 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 21:51:53 +00:00
|
|
|
// EnableClientHandlingTimeHistogram turns on recording of handling time of
|
|
|
|
// RPCs. Histogram metrics can be very expensive for Prometheus to retain and
|
|
|
|
// query. This function acts on the DefaultClientMetrics variable and the
|
|
|
|
// default Prometheus metrics registry.
|
|
|
|
func EnableClientHandlingTimeHistogram(opts ...HistogramOption) {
|
|
|
|
DefaultClientMetrics.EnableClientHandlingTimeHistogram(opts...)
|
|
|
|
prom.Register(DefaultClientMetrics.clientHandledHistogram)
|
2019-01-12 04:58:27 +00:00
|
|
|
}
|