Categorygithub.com/bsm/omgrpc
modulepackage
0.3.0
Repository: https://github.com/bsm/omgrpc.git
Documentation: pkg.go.dev

# README

omgrpc - OpenMetrics gRPC middleware

Lint Test

Quickstart

import (
  "github.com/bsm/omgrpc"
  "github.com/bsm/openmetrics"
  "google.golang.org/grpc"
)

func initGRPCServer(
  fooServer yourproto.FooServer,

  callCount openmetrics.CounterFamily,      // with tags: "method", "status"
  callDuration openmetrics.HistogramFamily, // with tags: "method", "status"
  activeConns openmetrics.GaugeFamily,      // no tags
) *grpc.Server {
  server := grpc.NewServer(
    grpc.WithStats(omgrpc.InstrumentCallCount(callCount)),
    grpc.WithStats(omgrpc.InstrumentCallDuration(callDuration)),
    grpc.WithStats(omgrpc.InstrumentActiveConns(activeConns)),
  )
  yourproto.RegisterFooServer(server, fooServer)
  return server
}

func initGRPCClient(
  ctx context.Context,
  target string,

  callCount openmetrics.CounterFamily,      // with tags: "method", "status"
  callDuration openmetrics.HistogramFamily, // with tags: "method", "status"
  activeConns openmetrics.GaugeFamily,      // no tags
) (*grpc.Conn, error) {
  return grpc.DialContext(
    ctx,
    target,

    grpc.WithStatsHandler(omgrpc.InstrumentCallCount(callCount)),
    grpc.WithStatsHandler(omgrpc.InstrumentCallDuration(callDuration)),
    grpc.WithStatsHandler(omgrpc.InstrumentActiveConns(activeConns)),
  )
}

# Functions

InstrumentActiveConns returns default stats.Handler to instrument number of active gRPC connections.
InstrumentCallCount returns default stats.Handler to instrument RPC call count.
InstrumentCallDuration returns default stats.Handler to instrument RPC call duration in units configured for metric.

# Constants

No description provided by the author
No description provided by the author

# Structs

CallStats holds all the RPC call-related data that can be collected by stats handler.
ConnStats holds connection stats.

# Type aliases

CallStatsHandler implements https://pkg.go.dev/google.golang.org/grpc/stats#Handler for RPC calls.
ConnStatsHandler implements https://pkg.go.dev/google.golang.org/grpc/stats#Handler for RPC connections.
ConnStatus holds connection status.