⚡ Adds prometheus registry
This commit is contained in:
@@ -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"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user