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"
|
|
|
|
|
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{
|
|
|
|
Name: "authentik_outpost_proxy_requests",
|
|
|
|
Help: "The total number of configured providers",
|
2022-05-29 19:45:25 +00:00
|
|
|
}, []string{"outpost_name", "method", "scheme", "host", "type"})
|
2021-09-08 18:04:56 +00:00
|
|
|
UpstreamTiming = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
|
|
|
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-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())
|
2021-11-11 22:18:32 +00:00
|
|
|
listen := "0.0.0.0:9300"
|
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
|
|
|
}
|
|
|
|
}
|