promgrpc

package module
v2.0.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2018 License: MIT Imports: 10 Imported by: 0

README

promgrpc Build Status

GoDoc

Library allows to monitor gRPC based client and server applications.

Metrics

Client
  • grpc_client_connections
  • grpc_client_reconnects_total
  • grpc_client_errors_total
  • grpc_client_requests
  • grpc_client_requests_total
  • grpc_client_request_duration_seconds
  • grpc_client_request_duration_seconds_sum
  • grpc_client_request_duration_seconds_count
  • grpc_client_received_messages_total
  • grpc_client_send_messages_total
Server
  • grpc_server_connections
  • grpc_server_errors_total
  • grpc_server_requests
  • grpc_server_requests_total
  • grpc_server_request_duration_seconds
  • grpc_server_request_duration_seconds_sum
  • grpc_server_request_duration_seconds_count
  • grpc_server_received_messages_total
  • grpc_server_send_messages_total

Example

ict := promgrpc.NewInterceptor(promgrpc.InterceptorOpts{})
dop := []grpc.DialOption{
	grpc.WithDialer(ict.Dialer(func(addr string, timeout time.Duration) (net.Conn, error) {
		return net.DialTimeout("tcp", addr, timeout)
	})),
	grpc.WithStreamInterceptor(ict.StreamClient()),
	grpc.WithUnaryInterceptor(ict.UnaryClient()),
}

sop := []grpc.ServerOption{
	grpc.StatsHandler(ict),
	grpc.StreamInterceptor(ict.StreamServer()),
	grpc.UnaryInterceptor(ict.UnaryServer()),
}

prometheus.DefaultRegisterer.Register(ict)

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterInterceptor added in v0.3.0

func RegisterInterceptor(s ServiceInfoProvider, i *Interceptor) (err error)

RegisterInterceptor preallocates possible dimensions of every metric. If peer tracking is enabled, nothing will happen. If you register interceptor very frequently (for example during tests) it can allocate huge amount of memory.

Types

type Interceptor

type Interceptor struct {
	// contains filtered or unexported fields
}

Interceptor ...

func NewInterceptor

func NewInterceptor(opts InterceptorOpts) *Interceptor

NewInterceptor implements both prometheus Collector interface and methods required by grpc Interceptor.

func (*Interceptor) Collect added in v0.8.0

func (i *Interceptor) Collect(in chan<- prometheus.Metric)

Collect implements prometheus Collector interface.

func (*Interceptor) Describe added in v0.8.0

func (i *Interceptor) Describe(in chan<- *prometheus.Desc)

Describe implements prometheus Collector interface.

func (*Interceptor) Dialer

func (i *Interceptor) Dialer(f func(string, time.Duration) (net.Conn, error)) func(string, time.Duration) (net.Conn, error)

Dialer ...

Example
package main

import (
	"net"
	"time"

	"github.com/piotrkowalczuk/promgrpc"
	"google.golang.org/grpc"
)

func main() {
	interceptor := promgrpc.NewInterceptor(promgrpc.InterceptorOpts{})

	var opts []grpc.DialOption
	opts = append(opts, grpc.WithDialer(interceptor.Dialer(func(addr string, timeout time.Duration) (net.Conn, error) {
		return net.DialTimeout("tcp", addr, timeout)
	})))
}
Output:

func (*Interceptor) HandleConn added in v0.9.0

func (i *Interceptor) HandleConn(ctx context.Context, stat stats.ConnStats)

HandleConn implements stats Handler interface.

func (*Interceptor) HandleRPC added in v0.9.0

func (i *Interceptor) HandleRPC(ctx context.Context, stat stats.RPCStats)

HandleRPC implements stats Handler interface.

func (*Interceptor) StreamClient

func (i *Interceptor) StreamClient() grpc.StreamClientInterceptor

StreamClient ...

func (*Interceptor) StreamServer

func (i *Interceptor) StreamServer() grpc.StreamServerInterceptor

StreamServer ...

func (*Interceptor) TagConn added in v0.9.0

func (i *Interceptor) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context

TagConn implements stats Handler interface.

func (*Interceptor) TagRPC added in v0.9.0

func (i *Interceptor) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context

TagRPC implements stats Handler interface.

func (*Interceptor) UnaryClient

func (i *Interceptor) UnaryClient() grpc.UnaryClientInterceptor

UnaryClient ...

func (*Interceptor) UnaryServer

func (i *Interceptor) UnaryServer() grpc.UnaryServerInterceptor

UnaryServer ...

type InterceptorOpts added in v0.5.0

type InterceptorOpts struct {
	// TrackPeers allow to turn on peer tracking.
	// For more info about peers please visit https://godoc.org/google.golang.org/grpc/peer.
	// peer is not bounded dimension so it can cause performance loss.
	// If its turn on Interceptor will not init metrics on startup.
	TrackPeers bool
}

InterceptorOpts ...

type ServiceInfoProvider added in v1.0.0

type ServiceInfoProvider interface {
	// GetServiceInfo returns a map from service names to ServiceInfo.
	// Service names include the package names, in the form of <package>.<service>.
	GetServiceInfo() map[string]grpc.ServiceInfo
}

ServiceInfoProvider is simple wrapper around GetServiceInfo method. This interface is implemented by grpc Server.

Jump to

Keyboard shortcuts

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