package grpcstats
import "go.opencensus.io/plugin/ocgrpc/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.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.
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.
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.
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/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()
}
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/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
}
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.3.0
- Published
- Feb 12, 2018
- Platform
- darwin/amd64
- Imports
- 12 packages
- Last checked
- 1 minute ago –
Tools for package owners.