2021-09-08 18:04:56 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2021-11-11 22:18:32 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
2022-08-03 19:33:27 +00:00
|
|
|
"goauthentik.io/internal/config"
|
2022-06-10 20:19:48 +00:00
|
|
|
"goauthentik.io/internal/utils/sentry"
|
2021-11-11 22:18:32 +00:00
|
|
|
|
2021-09-08 18:04:56 +00:00
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
Requests = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
2023-07-27 16:51:08 +00:00
|
|
|
Name: "authentik_outpost_proxy_request_duration_seconds",
|
|
|
|
Help: "Proxy request latencies in seconds",
|
|
|
|
}, []string{"outpost_name", "method", "host", "type"})
|
|
|
|
UpstreamTiming = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
|
|
|
Name: "authentik_outpost_proxy_upstream_response_duration_seconds",
|
|
|
|
Help: "Proxy upstream response latencies in seconds",
|
|
|
|
}, []string{"outpost_name", "method", "scheme", "host", "upstream_host"})
|
|
|
|
|
|
|
|
// NOTE: the following metric is kept for compatibility purpose
|
|
|
|
RequestsLegacy = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
2021-09-08 18:04:56 +00:00
|
|
|
Name: "authentik_outpost_proxy_requests",
|
|
|
|
Help: "The total number of configured providers",
|
2022-06-03 08:32:52 +00:00
|
|
|
}, []string{"outpost_name", "method", "host", "type"})
|
2023-07-27 16:51:08 +00:00
|
|
|
UpstreamTimingLegacy = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
2021-09-08 18:04:56 +00:00
|
|
|
Name: "authentik_outpost_proxy_upstream_time",
|
|
|
|
Help: "A summary of the duration we wait for the upstream reply",
|
2022-05-29 19:45:25 +00:00
|
|
|
}, []string{"outpost_name", "method", "scheme", "host", "upstream_host"})
|
2021-09-08 18:04:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func RunServer() {
|
|
|
|
m := mux.NewRouter()
|
2021-11-19 09:37:13 +00:00
|
|
|
l := log.WithField("logger", "authentik.outpost.metrics")
|
2022-06-10 20:19:48 +00:00
|
|
|
m.Use(sentry.SentryNoSampleMiddleware)
|
2022-02-08 19:25:38 +00:00
|
|
|
m.HandleFunc("/outpost.goauthentik.io/ping", func(rw http.ResponseWriter, r *http.Request) {
|
2021-09-09 13:52:24 +00:00
|
|
|
rw.WriteHeader(204)
|
|
|
|
})
|
2021-09-08 18:04:56 +00:00
|
|
|
m.Path("/metrics").Handler(promhttp.Handler())
|
2022-08-03 19:33:27 +00:00
|
|
|
listen := config.Get().Listen.Metrics
|
2021-11-19 09:37:13 +00:00
|
|
|
l.WithField("listen", listen).Info("Starting Metrics server")
|
2021-11-11 22:18:32 +00:00
|
|
|
err := http.ListenAndServe(listen, m)
|
2021-09-08 18:04:56 +00:00
|
|
|
if err != nil {
|
2021-11-19 09:37:13 +00:00
|
|
|
l.WithError(err).Warning("Failed to start metrics listener")
|
2021-09-08 18:04:56 +00:00
|
|
|
}
|
|
|
|
}
|