Skip to content

Commit 28fc42c

Browse files
committed
update
1 parent 7ec53a6 commit 28fc42c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

middleware.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"strconv"
66

77
"github.com/prometheus/client_golang/prometheus"
8-
"github.com/prometheus/client_golang/prometheus/promauto"
98
"github.com/webx-top/echo"
109
)
1110

@@ -82,21 +81,24 @@ func MetricsMiddleware() echo.MiddlewareFuncd {
8281

8382
// MetricsMiddlewareWithConfig returns an echo middleware for instrumentation.
8483
func MetricsMiddlewareWithConfig(config Config) echo.MiddlewareFuncd {
85-
86-
httpRequests := promauto.NewCounterVec(prometheus.CounterOpts{
84+
httpRequests := prometheus.NewCounterVec(prometheus.CounterOpts{
8785
Namespace: config.Namespace,
8886
Subsystem: config.Subsystem,
8987
Name: httpRequestsCount,
9088
Help: "Number of HTTP operations",
9189
}, []string{"status", "method", "handler"})
90+
prometheus.DefaultRegisterer.Unregister(httpRequests)
91+
prometheus.DefaultRegisterer.MustRegister(httpRequests)
9292

93-
httpDuration := promauto.NewHistogramVec(prometheus.HistogramOpts{
93+
httpDuration := prometheus.NewHistogramVec(prometheus.HistogramOpts{
9494
Namespace: config.Namespace,
9595
Subsystem: config.Subsystem,
9696
Name: httpRequestsDuration,
9797
Help: "Spend time by processing a route",
9898
Buckets: config.Buckets,
9999
}, []string{"method", "handler"})
100+
prometheus.DefaultRegisterer.Unregister(httpDuration)
101+
prometheus.DefaultRegisterer.MustRegister(httpDuration)
100102

101103
skipper := config.Skipper
102104
if skipper == nil {

0 commit comments

Comments
 (0)