daemon: instrument the gateway and api HTTP handlers
License: MIT Signed-off-by: Lars Gierth <larsg@systemli.org>
Lars Gierth committed
Oct 5, 2015 at 03:53 UTC
dd20f4845477de3a38740135282986faff04173a
2 files changed
+11
-1
cmd/ipfs/daemon.go
+2
@@ -338,6 +338,7 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) {
338
},
339
})
340
var opts = []corehttp.ServeOption{
341
+ corehttp.PrometheusCollectorOption("api"),
342
corehttp.CommandsOption(*req.InvocContext()),
343
corehttp.WebUIOption,
344
apiGw.ServeOption(),
@@ -416,6 +417,7 @@ func serveHTTPGateway(req cmds.Request) (error, <-chan error) {
417
}
418
419
var opts = []corehttp.ServeOption{
420
+ corehttp.PrometheusCollectorOption("gateway"),
421
corehttp.CommandsROOption(*req.InvocContext()),
422
corehttp.VersionOption(),
423
corehttp.IPNSHostnameOption(),
core/corehttp/prometheus.go
+9
-1
@@ -11,7 +11,15 @@ import (
11
12
func PrometheusOption(path string) ServeOption {
13
return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
14
- mux.Handle(path, prom.Handler())
14
+ mux.Handle(path, prom.UninstrumentedHandler())
15
return mux, nil
16
}
17
}
18
+
19
+func PrometheusCollectorOption(handlerName string) ServeOption {
20
+ return func(_ *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
21
+ childMux := http.NewServeMux()
22
+ mux.HandleFunc("/", prom.InstrumentHandler(handlerName, childMux))
23
+ return childMux, nil
24
+ }
25
+}