|
|
@ -6,6 +6,7 @@ import (
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/tal-tech/go-zero/core/metric"
|
|
|
|
"github.com/tal-tech/go-zero/core/metric"
|
|
|
|
|
|
|
|
"github.com/tal-tech/go-zero/core/prometheus"
|
|
|
|
"github.com/tal-tech/go-zero/core/timex"
|
|
|
|
"github.com/tal-tech/go-zero/core/timex"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
@ -35,6 +36,10 @@ var (
|
|
|
|
// PrometheusInterceptor is an interceptor that reports to prometheus server.
|
|
|
|
// PrometheusInterceptor is an interceptor that reports to prometheus server.
|
|
|
|
func PrometheusInterceptor(ctx context.Context, method string, req, reply interface{},
|
|
|
|
func PrometheusInterceptor(ctx context.Context, method string, req, reply interface{},
|
|
|
|
cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
|
|
|
|
cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
|
|
|
|
|
|
|
|
if !prometheus.Enabled() {
|
|
|
|
|
|
|
|
return invoker(ctx, method, req, reply, cc, opts...)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
startTime := timex.Now()
|
|
|
|
startTime := timex.Now()
|
|
|
|
err := invoker(ctx, method, req, reply, cc, opts...)
|
|
|
|
err := invoker(ctx, method, req, reply, cc, opts...)
|
|
|
|
metricClientReqDur.Observe(int64(timex.Since(startTime)/time.Millisecond), method)
|
|
|
|
metricClientReqDur.Observe(int64(timex.Since(startTime)/time.Millisecond), method)
|
|
|
|