1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-10-26 02:45:48 +08:00

Merge pull request #1799 from ipfs/prometheus-http

daemon: instrument the gateway and api HTTP handlers
This commit is contained in:
Juan Benet
2015-10-05 01:35:45 -04:00
2 changed files with 11 additions and 1 deletions

View File

@ -338,6 +338,7 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) {
}, },
}) })
var opts = []corehttp.ServeOption{ var opts = []corehttp.ServeOption{
corehttp.PrometheusCollectorOption("api"),
corehttp.CommandsOption(*req.InvocContext()), corehttp.CommandsOption(*req.InvocContext()),
corehttp.WebUIOption, corehttp.WebUIOption,
apiGw.ServeOption(), apiGw.ServeOption(),
@ -416,6 +417,7 @@ func serveHTTPGateway(req cmds.Request) (error, <-chan error) {
} }
var opts = []corehttp.ServeOption{ var opts = []corehttp.ServeOption{
corehttp.PrometheusCollectorOption("gateway"),
corehttp.CommandsROOption(*req.InvocContext()), corehttp.CommandsROOption(*req.InvocContext()),
corehttp.VersionOption(), corehttp.VersionOption(),
corehttp.IPNSHostnameOption(), corehttp.IPNSHostnameOption(),

View File

@ -11,7 +11,15 @@ import (
func PrometheusOption(path string) ServeOption { func PrometheusOption(path string) ServeOption {
return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) { 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 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
}
}