mirror of
https://github.com/thomiceli/opengist.git
synced 2025-07-12 10:51:49 +02:00
feat: add Prometheus metrics (#439)
* feat: add Prometheus metrics * setup metrics using Prometheus client under /metrics endpoint * add configuration value for metrics * configure Prometheus middleware for generic metrics * provide metrics for totals of users, gists and SSH keys * modify test request to optionally return the response * provide integration test for Prometheus metrics * update documentation * chore: make fmt
This commit is contained in:
@ -3,6 +3,7 @@ package server
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/labstack/echo-contrib/echoprometheus"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
"github.com/rs/zerolog/log"
|
||||
@ -34,6 +35,10 @@ func (s *Server) useCustomContext() {
|
||||
func (s *Server) registerMiddlewares() {
|
||||
s.echo.Use(Middleware(dataInit).toEcho())
|
||||
s.echo.Use(Middleware(locale).toEcho())
|
||||
if config.C.MetricsEnabled {
|
||||
p := echoprometheus.NewMiddleware("opengist")
|
||||
s.echo.Use(p)
|
||||
}
|
||||
|
||||
s.echo.Pre(middleware.MethodOverrideWithConfig(middleware.MethodOverrideConfig{
|
||||
Getter: middleware.MethodFromForm("_method"),
|
||||
|
@ -1,6 +1,13 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/thomiceli/opengist/internal/config"
|
||||
"github.com/thomiceli/opengist/internal/index"
|
||||
@ -10,14 +17,9 @@ import (
|
||||
"github.com/thomiceli/opengist/internal/web/handlers/gist"
|
||||
"github.com/thomiceli/opengist/internal/web/handlers/git"
|
||||
"github.com/thomiceli/opengist/internal/web/handlers/health"
|
||||
"github.com/thomiceli/opengist/internal/web/handlers/metrics"
|
||||
"github.com/thomiceli/opengist/internal/web/handlers/settings"
|
||||
"github.com/thomiceli/opengist/public"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (s *Server) registerRoutes() {
|
||||
@ -29,7 +31,10 @@ func (s *Server) registerRoutes() {
|
||||
r.POST("/preview", gist.Preview, logged)
|
||||
|
||||
r.GET("/healthcheck", health.Healthcheck)
|
||||
r.GET("/metrics", health.Metrics)
|
||||
|
||||
if config.C.MetricsEnabled {
|
||||
r.GET("/metrics", metrics.Metrics)
|
||||
}
|
||||
|
||||
r.GET("/register", auth.Register)
|
||||
r.POST("/register", auth.ProcessRegister)
|
||||
|
Reference in New Issue
Block a user