Adds prometheus registry

This commit is contained in:
Daniel Svitan
2025-05-01 21:43:53 +02:00
parent 1a94965b2a
commit 590fb13c86
3 changed files with 67 additions and 20 deletions
+16
View File
@@ -6,9 +6,11 @@ import (
"net/http"
"time"
"github.com/labstack/echo-contrib/echoprometheus"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/labstack/gommon/log"
"github.com/prometheus/client_golang/prometheus"
)
const TimeFormat = "2006-01-02 15:04:05"
@@ -58,8 +60,22 @@ func main() {
}
}
registry := prometheus.NewRegistry()
counter := prometheus.NewCounter(
prometheus.CounterOpts{
Name: "custom_requests_total",
Help: "How many HTTP requests processed, partitioned by status code and HTTP method.",
},
)
if err := registry.Register(counter); err != nil {
log.Fatal(err)
}
app.GET("/", func(c echo.Context) error {
return c.JSON(http.StatusOK, "Hello, World!")
})
app.GET("/metrics", echoprometheus.NewHandlerWithConfig(echoprometheus.HandlerConfig{Gatherer: registry}))
log.Fatal(app.Start(":1323"))
}