diff --git a/router/router.go b/router/router.go index aa25fa71..0041b74a 100644 --- a/router/router.go +++ b/router/router.go @@ -11,6 +11,7 @@ import ( "github.com/drone/drone/router/middleware/token" "github.com/drone/drone/server" "github.com/drone/drone/server/debug" + "github.com/drone/drone/server/metrics" "github.com/drone/drone/server/template" "github.com/drone/drone-ui/dist" @@ -171,6 +172,14 @@ func Load(middleware ...gin.HandlerFunc) http.Handler { debugger.GET("/pprof/trace", debug.TraceHandler()) } + monitor := e.Group("/api/metrics") + { + monitor.GET("/prometheus", + session.MustAdmin(), + metrics.PromHandler(), + ) + } + return e } diff --git a/server/metrics/prometheus.go b/server/metrics/prometheus.go new file mode 100644 index 00000000..1eea8961 --- /dev/null +++ b/server/metrics/prometheus.go @@ -0,0 +1,14 @@ +package metrics + +import ( + "github.com/gin-gonic/gin" + + "github.com/prometheus/client_golang/prometheus/promhttp" +) + +// PromHandler will pass the call from /api/metrics/prometheus to prometheus +func PromHandler() gin.HandlerFunc { + return func(c *gin.Context) { + promhttp.Handler().ServeHTTP(c.Writer, c.Request) + } +}