diff --git a/metrics/grpc/client.go b/metrics/grpc/client.go new file mode 100644 index 0000000..4305d53 --- /dev/null +++ b/metrics/grpc/client.go @@ -0,0 +1,31 @@ +package grpc + +import ( + "git.frostfs.info/TrueCloudLab/frostfs-observability/metrics" + grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus" + "github.com/prometheus/client_golang/prometheus" + "google.golang.org/grpc" +) + +var clientMetrics *grpcprom.ClientMetrics = grpcprom.NewClientMetrics( + grpcprom.WithClientHandlingTimeHistogram( + grpcprom.WithHistogramBuckets(prometheus.DefBuckets), + ), + grpcprom.WithClientStreamRecvHistogram( + grpcprom.WithHistogramBuckets(prometheus.DefBuckets), + ), +) + +func init() { + metrics.Register(clientMetrics) +} + +// NewUnaryClientInterceptor returns client interceptor to collect metrics from unary RPCs. +func NewUnaryClientInterceptor() grpc.UnaryClientInterceptor { + return clientMetrics.UnaryClientInterceptor() +} + +// NewStreamClientInterceptor returns client interceptor to collect metrics from stream RPCs. +func NewStreamClientInterceptor() grpc.StreamClientInterceptor { + return clientMetrics.StreamClientInterceptor() +} diff --git a/metrics/grpc/server.go b/metrics/grpc/server.go new file mode 100644 index 0000000..b47c488 --- /dev/null +++ b/metrics/grpc/server.go @@ -0,0 +1,28 @@ +package grpc + +import ( + "git.frostfs.info/TrueCloudLab/frostfs-observability/metrics" + grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus" + "github.com/prometheus/client_golang/prometheus" + "google.golang.org/grpc" +) + +var serverMetrics *grpcprom.ServerMetrics = grpcprom.NewServerMetrics( + grpcprom.WithServerHandlingTimeHistogram( + grpcprom.WithHistogramBuckets(prometheus.DefBuckets), + ), +) + +func init() { + metrics.Register(serverMetrics) +} + +// NewUnaryServerInterceptor returns server interceptor to collect metrics from unary RPCs. +func NewUnaryServerInterceptor() grpc.UnaryServerInterceptor { + return serverMetrics.UnaryServerInterceptor() +} + +// NewStreamServerInterceptor returns server interceptor to collect metrics from stream RPCs. +func NewStreamServerInterceptor() grpc.StreamServerInterceptor { + return serverMetrics.StreamServerInterceptor() +}