api: add /metrics endpoint for prometheus
License: MIT Signed-off-by: Lars Gierth <larsg@systemli.org>
Lars Gierth committed
Jun 20, 2015 at 00:59 UTC
ed8d3ae3881367260e97c754652829f27a209233
2 files changed
+17
cmd/ipfs/daemon.go
+1
@@ -300,6 +300,7 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) {
300
defaultMux("/debug/vars"),
301
defaultMux("/debug/pprof/"),
302
corehttp.LogOption(),
303
+ corehttp.PrometheusOption("/debug/metrics/prometheus"),
304
}
305
306
if len(cfg.Gateway.RootRedirect) > 0 {
core/corehttp/prometheus.go
new
+16
@@ -0,0 +1,16 @@
1
+package corehttp
2
+
3
+import (
4
+ "net/http"
5
+
6
+ prom "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/prometheus/client_golang/prometheus"
7
+
8
+ "github.com/ipfs/go-ipfs/core"
9
+)
10
+
11
+func PrometheusOption(path string) ServeOption {
12
+ return func(n *core.IpfsNode, mux *http.ServeMux) (*http.ServeMux, error) {
13
+ mux.Handle(path, prom.Handler())
14
+ return mux, nil
15
+ }
16
+}