Replies: 1 comment 2 replies
-
Here is example that creates new prometheus counter and adds it to registry. In your use-case you do not need that func TestMiddlewareConfig_AfterNextFuncs(t *testing.T) {
e := echo.New()
customRegistry := prometheus.NewRegistry()
customCounter := prometheus.NewCounter(
prometheus.CounterOpts{
Name: "custom_requests_total",
Help: "How many HTTP requests processed, partitioned by status code and HTTP method.",
},
)
if err := customRegistry.Register(customCounter); err != nil {
t.Fatal(err)
}
e.Use(NewMiddlewareWithConfig(MiddlewareConfig{
AfterNext: func(c echo.Context, err error) {
customCounter.Inc() // use our custom metric in middleware
},
Registerer: customRegistry,
}))
e.GET("/metrics", NewHandlerWithConfig(HandlerConfig{Gatherer: customRegistry}))
e.GET("/ok", func(c echo.Context) error {
return c.JSON(http.StatusOK, "OK")
})
assert.Equal(t, http.StatusOK, request(e, "/ok"))
body, code := requestBody(e, "/metrics")
assert.Equal(t, http.StatusOK, code)
assert.Contains(t, body, `custom_requests_total 1`)
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
is it possible to add custom gauge metric for some function/endpoint? If so, how to make it? For example I would like to run goroutine which would make some action and set value for that metric.
Unfortunately, the documentation doesn't have any examples.
Beta Was this translation helpful? Give feedback.
All reactions