grpcstats

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package grpcstats provides OpenCensus stats support for gRPC clients and servers.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// Available client measures
	RPCClientErrorCount       *stats.Int64Measure
	RPCClientRoundTripLatency *stats.Float64Measure
	RPCClientRequestBytes     *stats.Int64Measure
	RPCClientResponseBytes    *stats.Int64Measure
	RPCClientStartedCount     *stats.Int64Measure
	RPCClientFinishedCount    *stats.Int64Measure
	RPCClientRequestCount     *stats.Int64Measure
	RPCClientResponseCount    *stats.Int64Measure

	// Predefined client views
	RPCClientErrorCountView       *view.View
	RPCClientRoundTripLatencyView *view.View
	RPCClientRequestBytesView     *view.View
	RPCClientResponseBytesView    *view.View
	RPCClientRequestCountView     *view.View
	RPCClientResponseCountView    *view.View
)

The following variables are measures and views made available for gRPC clients. Client connection needs to use a ClientStatsHandler in order to enable collection.

View Source
var (
	KeyMethod tag.Key
	KeyStatus tag.Key
)

The following variables define the default hard-coded auxiliary data used by both the default GRPC client and GRPC server metrics. These are Go objects instances mirroring the some of the proto definitions found at "github.com/google/instrumentation-proto/census.proto". A complete description of each can be found there. TODO(acetechnologist): This is temporary and will need to be replaced by a mechanism to load these defaults from a common repository/config shared by all supported languages. Likely a serialized protobuf of these defaults.

View Source
var (
	// Available server measures
	RPCServerErrorCount        *stats.Int64Measure
	RPCServerServerElapsedTime *stats.Float64Measure
	RPCServerRequestBytes      *stats.Int64Measure
	RPCServerResponseBytes     *stats.Int64Measure
	RPCServerStartedCount      *stats.Int64Measure
	RPCServerFinishedCount     *stats.Int64Measure
	RPCServerRequestCount      *stats.Int64Measure
	RPCServerResponseCount     *stats.Int64Measure

	// Predefined server views
	RPCServerErrorCountView        *view.View
	RPCServerServerElapsedTimeView *view.View
	RPCServerRequestBytesView      *view.View
	RPCServerResponseBytesView     *view.View
	RPCServerRequestCountView      *view.View
	RPCServerResponseCountView     *view.View
)

The following variables are measures and views made available for gRPC clients. Server needs to use a ServerStatsHandler in order to enable collection.

Functions

This section is empty.

Types

type ClientStatsHandler

type ClientStatsHandler struct{}

ClientStatsHandler is a stats.Handler implementation that collects stats for a gRPC client. Predefined measures and views can be used to access the collected data.

func NewClientStatsHandler

func NewClientStatsHandler() *ClientStatsHandler

NewClientStatsHandler returns a stats.Handler implementation that collects stats for a gRPC client. Predefined measures and views can be used to access the collected data.

Example
package main

import (
	"log"

	"go.opencensus.io/plugin/ocgrpc/grpcstats"
	"google.golang.org/grpc"
)

func main() {
	// Subscribe to collect client request count.
	if err := grpcstats.RPCClientRequestCountView.Subscribe(); err != nil {
		log.Fatal(err)
	}

	// Set up a new client connection with the OpenCensus
	// stats handler to enable stats collection from the views.
	conn, err := grpc.Dial("address", grpc.WithStatsHandler(grpcstats.NewClientStatsHandler()))
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}
	defer conn.Close()
}
Output:

func (*ClientStatsHandler) HandleConn

func (h *ClientStatsHandler) HandleConn(ctx context.Context, s stats.ConnStats)

HandleConn processes the connection events.

func (*ClientStatsHandler) HandleRPC

func (h *ClientStatsHandler) HandleRPC(ctx context.Context, s stats.RPCStats)

HandleRPC processes the RPC events.

func (*ClientStatsHandler) TagConn

TagConn adds connection related data to the given context and returns the new context.

func (*ClientStatsHandler) TagRPC

TagRPC gets the tag.Map populated by the application code, serializes its tags into the GRPC metadata in order to be sent to the server.

type ServerStatsHandler

type ServerStatsHandler struct{}

ServerStatsHandler is a stats.Handler implementation that collects stats for a gRPC server. Predefined measures and views can be used to access the collected data.

func NewServerStatsHandler

func NewServerStatsHandler() *ServerStatsHandler

NewServerStatsHandler returns a stats.Handler implementation that collects stats for a gRPC server. Predefined measures and views can be used to access the collected data.

Example
package main

import (
	"log"

	"go.opencensus.io/plugin/ocgrpc/grpcstats"
	"google.golang.org/grpc"
)

func main() {
	// Subscribe to collect server request count.
	if err := grpcstats.RPCServerRequestCountView.Subscribe(); err != nil {
		log.Fatal(err)
	}

	// Set up a new server with the OpenCensus stats handler
	// to enable stats collection from the views.
	s := grpc.NewServer(grpc.StatsHandler(grpcstats.NewClientStatsHandler()))
	_ = s // use s
}
Output:

func (*ServerStatsHandler) HandleConn

func (h *ServerStatsHandler) HandleConn(ctx context.Context, s stats.ConnStats)

HandleConn processes the connection events.

func (*ServerStatsHandler) HandleRPC

func (h *ServerStatsHandler) HandleRPC(ctx context.Context, s stats.RPCStats)

HandleRPC processes the RPC events.

func (*ServerStatsHandler) TagConn

TagConn adds connection related data to the given context and returns the new context.

func (*ServerStatsHandler) TagRPC

TagRPC gets the metadata from gRPC context, extracts the encoded tags from it and creates a new tag.Map and puts them into the returned context.

Jump to

Keyboard shortcuts

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