From dd20f4845477de3a38740135282986faff04173a Mon Sep 17 00:00:00 2001 From: Lars Gierth Date: Mon, 5 Oct 2015 03:53:49 +0200 Subject: [PATCH] daemon: instrument the gateway and api HTTP handlers License: MIT Signed-off-by: Lars Gierth --- cmd/ipfs/daemon.go | 2 ++ core/corehttp/prometheus.go | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/ipfs/daemon.go b/cmd/ipfs/daemon.go index ad0f227f3..b916391a4 100644 --- a/cmd/ipfs/daemon.go +++ b/cmd/ipfs/daemon.go @@ -338,6 +338,7 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) { }, }) var opts = []corehttp.ServeOption{ + corehttp.PrometheusCollectorOption("api"), corehttp.CommandsOption(*req.InvocContext()), corehttp.WebUIOption, apiGw.ServeOption(), @@ -416,6 +417,7 @@ func serveHTTPGateway(req cmds.Request) (error, <-chan error) { } var opts = []corehttp.ServeOption{ + corehttp.PrometheusCollectorOption("gateway"), corehttp.CommandsROOption(*req.InvocContext()), corehttp.VersionOption(), corehttp.IPNSHostnameOption(), diff --git a/core/corehttp/prometheus.go b/core/corehttp/prometheus.go index 0642c04b5..2605e6cbe 100644 --- a/core/corehttp/prometheus.go +++ b/core/corehttp/prometheus.go @@ -11,7 +11,15 @@ import ( func PrometheusOption(path string) ServeOption { return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) { - mux.Handle(path, prom.Handler()) + mux.Handle(path, prom.UninstrumentedHandler()) return mux, nil } } + +func PrometheusCollectorOption(handlerName string) ServeOption { + return func(_ *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) { + childMux := http.NewServeMux() + mux.HandleFunc("/", prom.InstrumentHandler(handlerName, childMux)) + return childMux, nil + } +}