package grpcstats
import "go.opencensus.io/plugin/grpc/grpcstats"
Package grpcstats provides OpenCensus stats support for gRPC clients and servers.
Index ¶
- Variables
- type ClientStatsHandler
- func NewClientStatsHandler() *ClientStatsHandler
- func (h *ClientStatsHandler) HandleConn(ctx context.Context, s stats.ConnStats)
- func (h *ClientStatsHandler) HandleRPC(ctx context.Context, s stats.RPCStats)
- func (h *ClientStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context
- func (h *ClientStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context
- type ServerStatsHandler
- func NewServerStatsHandler() *ServerStatsHandler
- func (h *ServerStatsHandler) HandleConn(ctx context.Context, s stats.ConnStats)
- func (h *ServerStatsHandler) HandleRPC(ctx context.Context, s stats.RPCStats)
- func (h *ServerStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context
- func (h *ServerStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context
Examples ¶
Variables ¶
var ( // Available client measures RPCClientErrorCount *stats.MeasureInt64 RPCClientRoundTripLatency *stats.MeasureFloat64 RPCClientRequestBytes *stats.MeasureInt64 RPCClientResponseBytes *stats.MeasureInt64 RPCClientStartedCount *stats.MeasureInt64 RPCClientFinishedCount *stats.MeasureInt64 RPCClientRequestCount *stats.MeasureInt64 RPCClientResponseCount *stats.MeasureInt64 // Predefined client views RPCClientErrorCountView *stats.View RPCClientRoundTripLatencyView *stats.View RPCClientRequestBytesView *stats.View RPCClientResponseBytesView *stats.View RPCClientRequestCountView *stats.View RPCClientResponseCountView *stats.View RPCClientRoundTripLatencyMinuteView *stats.View RPCClientRequestBytesMinuteView *stats.View RPCClientResponseBytesMinuteView *stats.View RPCClientErrorCountMinuteView *stats.View RPCClientStartedCountMinuteView *stats.View RPCClientFinishedCountMinuteView *stats.View RPCClientRequestCountMinuteView *stats.View RPCClientResponseCountMinuteView *stats.View RPCClientRoundTripLatencyHourView *stats.View RPCClientRequestBytesHourView *stats.View RPCClientResponseBytesHourView *stats.View RPCClientErrorCountHourView *stats.View RPCClientStartedCountHourView *stats.View RPCClientFinishedCountHourView *stats.View RPCClientRequestCountHourView *stats.View RPCClientResponseCountHourView *stats.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.
var ( // Available server measures RPCServerErrorCount *stats.MeasureInt64 RPCServerServerElapsedTime *stats.MeasureFloat64 RPCServerRequestBytes *stats.MeasureInt64 RPCServerResponseBytes *stats.MeasureInt64 RPCServerStartedCount *stats.MeasureInt64 RPCServerFinishedCount *stats.MeasureInt64 RPCServerRequestCount *stats.MeasureInt64 RPCServerResponseCount *stats.MeasureInt64 // Predefined server views RPCServerErrorCountView *stats.View RPCServerServerElapsedTimeView *stats.View RPCServerRequestBytesView *stats.View RPCServerResponseBytesView *stats.View RPCServerRequestCountView *stats.View RPCServerResponseCountView *stats.View RPCServerServerElapsedTimeMinuteView *stats.View RPCServerRequestBytesMinuteView *stats.View RPCServerResponseBytesMinuteView *stats.View RPCServerErrorCountMinuteView *stats.View RPCServerStartedCountMinuteView *stats.View RPCServerFinishedCountMinuteView *stats.View RPCServerRequestCountMinuteView *stats.View RPCServerResponseCountMinuteView *stats.View RPCServerServerElapsedTimeHourView *stats.View RPCServerRequestBytesHourView *stats.View RPCServerResponseBytesHourView *stats.View RPCServerErrorCountHourView *stats.View RPCServerStartedCountHourView *stats.View RPCServerFinishedCountHourView *stats.View RPCServerRequestCountHourView *stats.View RPCServerResponseCountHourView *stats.View )
The following variables are measures and views made available for gRPC clients. Server needs to use a ServerStatsHandler in order to enable collection.
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.
Code:play
Example¶
package main
import (
"log"
"go.opencensus.io/plugin/grpc/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()
}
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 ¶
func (h *ClientStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context
TagConn adds connection related data to the given context and returns the new context.
func (*ClientStatsHandler) TagRPC ¶
func (h *ClientStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context
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.
Code:play
Example¶
package main
import (
"log"
"go.opencensus.io/plugin/grpc/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
}
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 ¶
func (h *ServerStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context
TagConn adds connection related data to the given context and returns the new context.
func (*ServerStatsHandler) TagRPC ¶
func (h *ServerStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context
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.
Source Files ¶
client_handler.go client_metrics.go grpcstats.go server_handler.go server_metrics.go
- Version
- v0.1.0
- Published
- Dec 15, 2017
- Platform
- js/wasm
- Imports
- 11 packages
- Last checked
- 4 hours ago –
Tools for package owners.