frostfs-observability/metrics/grpc/server.go
Dmitrii Stepanov c97d21411e [#3] metrics: Add gRPC middleware
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-05-31 11:27:42 +03:00

28 lines
884 B
Go

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()
}