sslobodr | d046be8 | 2019-01-16 10:02:22 -0500 | [diff] [blame^] | 1 | // Copyright 2016 Michal Witkowski. All Rights Reserved. |
| 2 | // See LICENSE for licensing terms. |
| 3 | |
| 4 | // gRPC Prometheus monitoring interceptors for client-side gRPC. |
| 5 | |
| 6 | package grpc_prometheus |
| 7 | |
| 8 | import ( |
| 9 | prom "github.com/prometheus/client_golang/prometheus" |
| 10 | ) |
| 11 | |
| 12 | var ( |
| 13 | // DefaultClientMetrics is the default instance of ClientMetrics. It is |
| 14 | // intended to be used in conjunction the default Prometheus metrics |
| 15 | // registry. |
| 16 | DefaultClientMetrics = NewClientMetrics() |
| 17 | |
| 18 | // UnaryClientInterceptor is a gRPC client-side interceptor that provides Prometheus monitoring for Unary RPCs. |
| 19 | UnaryClientInterceptor = DefaultClientMetrics.UnaryClientInterceptor() |
| 20 | |
| 21 | // StreamClientInterceptor is a gRPC client-side interceptor that provides Prometheus monitoring for Streaming RPCs. |
| 22 | StreamClientInterceptor = DefaultClientMetrics.StreamClientInterceptor() |
| 23 | ) |
| 24 | |
| 25 | func init() { |
| 26 | prom.MustRegister(DefaultClientMetrics.clientStartedCounter) |
| 27 | prom.MustRegister(DefaultClientMetrics.clientHandledCounter) |
| 28 | prom.MustRegister(DefaultClientMetrics.clientStreamMsgReceived) |
| 29 | prom.MustRegister(DefaultClientMetrics.clientStreamMsgSent) |
| 30 | } |
| 31 | |
| 32 | // EnableClientHandlingTimeHistogram turns on recording of handling time of |
| 33 | // RPCs. Histogram metrics can be very expensive for Prometheus to retain and |
| 34 | // query. This function acts on the DefaultClientMetrics variable and the |
| 35 | // default Prometheus metrics registry. |
| 36 | func EnableClientHandlingTimeHistogram(opts ...HistogramOption) { |
| 37 | DefaultClientMetrics.EnableClientHandlingTimeHistogram(opts...) |
| 38 | prom.Register(DefaultClientMetrics.clientHandledHistogram) |
| 39 | } |