-
Notifications
You must be signed in to change notification settings - Fork 0
/
prometheus.go
32 lines (26 loc) · 1 KB
/
prometheus.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package metrics
import (
"github.com/leokuzmanovic/go-echo-example/internal/configuration"
utils "github.com/leokuzmanovic/go-echo-example/internal/utils"
"github.com/labstack/echo-contrib/prometheus"
"github.com/labstack/echo/v4"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var endpointsConfigService configuration.EndpointsConfigService
func SetupPrometheusServer(e *echo.Echo, username, password string, ecs configuration.EndpointsConfigService) *echo.Echo {
endpointsConfigService = ecs
eProm := echo.New()
eProm.HideBanner = true
p := prometheus.NewPrometheus("echo", func(c echo.Context) bool {
return !endpointsConfigService.AreMetricsEnabled(utils.SanitizeUri(c.Request().RequestURI))
})
e.Use(p.HandlerFunc)
p.SetMetricsPath(eProm)
middlewareFunc := utils.PrepareBasicAuthenticationMiddleware(username, password)
h := promhttp.Handler()
e.GET(p.MetricsPath, func(c echo.Context) error {
h.ServeHTTP(c.Response(), c.Request())
return nil
}, middlewareFunc)
return eProm
}