feat: mysql and redis metric support (#2355)
* feat: mysql and redis metric support * feat: mysql and redis metric support * feat: mysql and redis metric support Co-authored-by: dawn.zhou <dawn.zhou@yijinin.com>
This commit is contained in:
@@ -6,8 +6,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/metric"
|
||||
"github.com/zeromicro/go-zero/core/prometheus"
|
||||
"github.com/zeromicro/go-zero/core/timex"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
@@ -36,10 +36,6 @@ var (
|
||||
// PrometheusInterceptor is an interceptor that reports to prometheus server.
|
||||
func PrometheusInterceptor(ctx context.Context, method string, req, reply interface{},
|
||||
cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
|
||||
if !prometheus.Enabled() {
|
||||
return invoker(ctx, method, req, reply, cc, opts...)
|
||||
}
|
||||
|
||||
startTime := timex.Now()
|
||||
err := invoker(ctx, method, req, reply, cc, opts...)
|
||||
metricClientReqDur.Observe(int64(timex.Since(startTime)/time.Millisecond), method)
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/metric"
|
||||
"github.com/zeromicro/go-zero/core/prometheus"
|
||||
"github.com/zeromicro/go-zero/core/timex"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
@@ -36,10 +36,6 @@ var (
|
||||
// UnaryPrometheusInterceptor reports the statistics to the prometheus server.
|
||||
func UnaryPrometheusInterceptor(ctx context.Context, req interface{},
|
||||
info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
|
||||
if !prometheus.Enabled() {
|
||||
return handler(ctx, req)
|
||||
}
|
||||
|
||||
startTime := timex.Now()
|
||||
resp, err := handler(ctx, req)
|
||||
metricServerReqDur.Observe(int64(timex.Since(startTime)/time.Millisecond), info.FullMethod)
|
||||
|
||||
Reference in New Issue
Block a user