grpcmon

package module
v0.0.0-...-086b225 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2018 License: MIT Imports: 7 Imported by: 0

README

grpcmon

GoDoc

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

View Source
var DefaultBytesBuckets = []float64{0, 32, 64, 128, 256, 512, 1024, 2048, 8192, 32768, 131072, 524288}

DefaultBytesBuckets provides convenient default bytes histogram buckets.

View Source
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

func ClientStatsHandler(metrics *Metrics) stats.Handler

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

func ServerStatsHandler(metrics *Metrics) stats.Handler

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.

Types

type Metrics

type Metrics struct {
	ConnsOpen   metrics.Gauge
	ConnsTotal  metrics.Counter
	ReqsPending metrics.Gauge
	ReqsTotal   metrics.Counter
	Latency     metrics.Histogram
	BytesSent   metrics.Histogram
	BytesRecv   metrics.Histogram
	// contains filtered or unexported fields
}

Metrics tracks gRPC metrics.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL