Documentation ¶
Overview ¶
Package grpcmon provides monitoring instrumentation for gRPC clients and servers.
The following metrics are provided:
grpc_client_connections_open [gauge] Number of gRPC client connections open. grpc_client_connections_total [counter] Total number of gRPC client connections opened. grpc_client_requests_pending{service,method} [gauge] Number of gRPC client requests pending. grpc_client_requests_total{service,method,code} [counter] Total number of gRPC client requests completed. grpc_client_latency_seconds{service,method,code} [histogram] Latency of gRPC client requests. grpc_client_recv_bytes{service,method,frame} [histogram] Bytes received in gRPC client responses. grpc_client_sent_bytes{service,method,frame} [histogram] Bytes sent in gRPC client requests. grpc_server_connections_open [gauge] Number of gRPC server connections open. grpc_server_connections_total [counter] Total number of gRPC server connections opened. grpc_server_requests_pending{service,method} [gauge] Number of gRPC server requests pending. grpc_server_requests_total{service,method,code} [counter] Total number of gRPC server requests completed. grpc_server_latency_seconds{service,method,code} [histogram] Latency of gRPC server requests. grpc_server_recv_bytes{service,method,frame} [histogram] Bytes received in gRPC server requests. grpc_server_sent_bytes{service,method,frame} [histogram] Bytes sent in gRPC server responses.
Example ¶
// Create gRPC metrics with selected options and register with monitoring // sytem. clientMetrics := &grpcmon.Metrics{ // ... } // Instrument gRPC client(s). backendConn, err := grpc.Dial(backendAddr, grpcmon.DialOption(clientMetrics)) if err != nil { log.Fatal(err) } serverMetrics := &grpcmon.Metrics{ // ... } // Instrument gRPC server and, optionally, initialize server metrics. srv := grpc.NewServer(grpcmon.ServerOption(serverMetrics)) pb.RegisterFrontendServer(srv, &Server{ backend: bpb.NewBackendClient(backendConn), }) // Listen and serve. lis, err := net.Listen("tcp", addr) if err != nil { log.Fatal(err) } log.Fatal(srv.Serve(lis))
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultBytesBuckets = []float64{0, 32, 64, 128, 256, 512, 1024, 2048, 8192, 32768, 131072, 524288}
DefaultBytesBuckets provides convenient default bytes histogram buckets.
var DefaultLatencyBuckets = []float64{0.001, 0.0025, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10}
DefaultLatencyBuckets provides convenient default latency histogram buckets.
Functions ¶
func ClientStatsHandler ¶
ClientStatsHandler returns gRPC stats.Handler to be used with gRPC clients. It is to be used when clients want to chain multiple stats.Handler implementations.
func DialOption ¶
func DialOption(metrics *Metrics) grpc.DialOption
DialOption returns a gRPC DialOption that instruments metrics for the client connection.
func ServerOption ¶
func ServerOption(metrics *Metrics) grpc.ServerOption
ServerOption returns a gRPC ServerOption that instruments metrics for the server.
func ServerStatsHandler ¶
ServerStatsHandler returns gRPC stats.Handler to be used with gRPC servers. It is to be used when servers want to chain multiple stats.Handler implementations.