blob: 751a4c72d7ece6fd81e97527bae90624181fd2eb [file] [log] [blame]
khenaidooab1f7bd2019-11-14 14:00:27 -05001// Copyright 2016 Michal Witkowski. All Rights Reserved.
2// See LICENSE for licensing terms.
3
4// gRPC Prometheus monitoring interceptors for client-side gRPC.
5
6package grpc_prometheus
7
8import (
9 prom "github.com/prometheus/client_golang/prometheus"
10)
11
12var (
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
25func 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.
36func EnableClientHandlingTimeHistogram(opts ...HistogramOption) {
37 DefaultClientMetrics.EnableClientHandlingTimeHistogram(opts...)
38 prom.Register(DefaultClientMetrics.clientHandledHistogram)
39}