https://github.com/bsm/omgrpc
OpenMetrics instrumentation for gRPC in Go
https://github.com/bsm/omgrpc
Last synced: about 1 year ago
JSON representation
OpenMetrics instrumentation for gRPC in Go
- Host: GitHub
- URL: https://github.com/bsm/omgrpc
- Owner: bsm
- License: apache-2.0
- Created: 2021-08-04T08:32:21.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-08-19T08:14:39.000Z (almost 5 years ago)
- Last Synced: 2025-04-13T05:54:45.948Z (about 1 year ago)
- Language: Go
- Size: 119 KB
- Stars: 0
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# omgrpc - [OpenMetrics](https://github.com/bsm/openmetrics) [gRPC](https://github.com/grpc/grpc-go) middleware
[](https://github.com/bsm/omgrpc/actions/workflows/lint.yml)
[](https://github.com/bsm/omgrpc/actions/workflows/test.yml)
## Quickstart
```go
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)),
)
}
```