prometheus: add middleware function
Add middleware function to track request count and measure the latency of compose requests.
This commit is contained in:
parent
dfa6a48f5d
commit
f8199ec41d
3 changed files with 22 additions and 23 deletions
20
internal/prometheus/middleware.go
Normal file
20
internal/prometheus/middleware.go
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package prometheus
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
func MetricsMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(ctx echo.Context) error {
|
||||
TotalRequests.Inc()
|
||||
if strings.HasSuffix(ctx.Path(), "/compose") {
|
||||
ComposeRequests.Inc()
|
||||
}
|
||||
timer := prometheus.NewTimer(httpDuration.WithLabelValues(ctx.Path()))
|
||||
defer timer.ObserveDuration()
|
||||
return next(ctx)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue