package middleware import ( "strconv" "time" "a301_server/pkg/metrics" "github.com/gofiber/fiber/v2" ) // Metrics records HTTP request count and duration as Prometheus metrics. func Metrics(c *fiber.Ctx) error { start := time.Now() err := c.Next() duration := time.Since(start).Seconds() status := strconv.Itoa(c.Response().StatusCode()) path := c.Route().Path // use route pattern to avoid cardinality explosion method := c.Method() metrics.HTTPRequestsTotal.WithLabelValues(method, path, status).Inc() metrics.HTTPRequestDuration.WithLabelValues(method, path).Observe(duration) return err }