Add middleware function to track request count and measure the latency of compose requests.
20 lines
458 B
Go
20 lines
458 B
Go
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)
|
|
}
|
|
}
|