From ed8d3ae3881367260e97c754652829f27a209233 Mon Sep 17 00:00:00 2001 From: Lars Gierth <larsg@systemli.org> Date: Sat, 20 Jun 2015 00:59:54 +0200 Subject: [PATCH] api: add /metrics endpoint for prometheus License: MIT Signed-off-by: Lars Gierth <larsg@systemli.org> --- cmd/ipfs/daemon.go | 1 + core/corehttp/prometheus.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 core/corehttp/prometheus.go diff --git a/cmd/ipfs/daemon.go b/cmd/ipfs/daemon.go index a49282949..90eed934e 100644 --- a/cmd/ipfs/daemon.go +++ b/cmd/ipfs/daemon.go @@ -300,6 +300,7 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) { defaultMux("/debug/vars"), defaultMux("/debug/pprof/"), corehttp.LogOption(), + corehttp.PrometheusOption("/debug/metrics/prometheus"), } if len(cfg.Gateway.RootRedirect) > 0 { diff --git a/core/corehttp/prometheus.go b/core/corehttp/prometheus.go new file mode 100644 index 000000000..d6e8ef4d0 --- /dev/null +++ b/core/corehttp/prometheus.go @@ -0,0 +1,16 @@ +package corehttp + +import ( + "net/http" + + prom "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/prometheus/client_golang/prometheus" + + "github.com/ipfs/go-ipfs/core" +) + +func PrometheusOption(path string) ServeOption { + return func(n *core.IpfsNode, mux *http.ServeMux) (*http.ServeMux, error) { + mux.Handle(path, prom.Handler()) + return mux, nil + } +} -- GitLab