From 3a255230ec56911ce9404f240ece4acd0f1cd6eb Mon Sep 17 00:00:00 2001 From: Jason Riddle Date: Thu, 27 Apr 2017 16:49:28 -0400 Subject: [PATCH] Add /api/metrics/prometheus endpoint --- router/router.go | 9 +++++++++ server/metrics/prometheus.go | 14 ++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 server/metrics/prometheus.go 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) + } +}