diff --git a/core/corehttp/metrics.go b/core/corehttp/metrics.go index 3f8c68ccd84..12a514a7a14 100644 --- a/core/corehttp/metrics.go +++ b/core/corehttp/metrics.go @@ -6,14 +6,27 @@ import ( core "github.com/ipfs/go-ipfs/core" + dhtMetrics "github.com/libp2p/go-libp2p-kad-dht/metrics" prometheus "github.com/prometheus/client_golang/prometheus" promhttp "github.com/prometheus/client_golang/prometheus/promhttp" + ocProm "go.opencensus.io/exporter/prometheus" + "go.opencensus.io/stats/view" ) // This adds the scraping endpoint which Prometheus uses to fetch metrics. func MetricsScrapingOption(path string) ServeOption { return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) { - mux.Handle(path, promhttp.HandlerFor(prometheus.DefaultGatherer, promhttp.HandlerOpts{})) + pe, err := ocProm.NewExporter(ocProm.Options{ + Registry: prometheus.DefaultGatherer.(*prometheus.Registry), + }) + if err != nil { + return mux, err + } + view.RegisterExporter(pe) + if err := view.Register(dhtMetrics.Views...); err != nil { + return mux, err + } + mux.Handle(path, pe) return mux, nil } } diff --git a/go.mod b/go.mod index d426df67eef..a08da43f23a 100644 --- a/go.mod +++ b/go.mod @@ -70,7 +70,7 @@ require ( github.com/libp2p/go-libp2p-crypto v0.0.1 github.com/libp2p/go-libp2p-host v0.0.1 github.com/libp2p/go-libp2p-interface-connmgr v0.0.1 - github.com/libp2p/go-libp2p-kad-dht v0.0.9 + github.com/libp2p/go-libp2p-kad-dht v0.0.10-0.20190423053654-33dc9eda5233 github.com/libp2p/go-libp2p-kbucket v0.1.1 github.com/libp2p/go-libp2p-loggables v0.0.1 github.com/libp2p/go-libp2p-metrics v0.0.1 @@ -110,6 +110,7 @@ require ( github.com/whyrusleeping/go-sysinfo v0.0.0-20190219211824-4a357d4b90b1 github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 github.com/whyrusleeping/tar-utils v0.0.0-20180509141711-8c6c8ba81d5c + go.opencensus.io v0.20.2 go.uber.org/atomic v1.3.2 // indirect go.uber.org/dig v1.7.0 // indirect go.uber.org/fx v1.9.0 diff --git a/go.sum b/go.sum index a4a8df69cfb..5260e0aa644 100644 --- a/go.sum +++ b/go.sum @@ -343,8 +343,8 @@ github.com/libp2p/go-libp2p-interface-connmgr v0.0.1/go.mod h1:GarlRLH0LdeWcLnYM github.com/libp2p/go-libp2p-interface-pnet v0.0.1 h1:7GnzRrBTJHEsofi1ahFdPN9Si6skwXQE9UqR2S+Pkh8= github.com/libp2p/go-libp2p-interface-pnet v0.0.1/go.mod h1:el9jHpQAXK5dnTpKA4yfCNBZXvrzdOU75zz+C6ryp3k= github.com/libp2p/go-libp2p-kad-dht v0.0.4/go.mod h1:oaBflOQcuC8H+SVV0YN26H6AS+wcUEJyjUGV66vXuSY= -github.com/libp2p/go-libp2p-kad-dht v0.0.9 h1:lgt0TuhnZieDg7jd6e4+aZIL11+Z9MLz7h66duB04Hw= -github.com/libp2p/go-libp2p-kad-dht v0.0.9/go.mod h1:RVllrB76xoaayqqBkLmXT8iIkMRNfLWSBuqAggP7W00= +github.com/libp2p/go-libp2p-kad-dht v0.0.10-0.20190423053654-33dc9eda5233 h1:XFz2azHEr07wTbCuDxgdOUVAIfEV17zqfLe+uN+yU8M= +github.com/libp2p/go-libp2p-kad-dht v0.0.10-0.20190423053654-33dc9eda5233/go.mod h1:RVllrB76xoaayqqBkLmXT8iIkMRNfLWSBuqAggP7W00= github.com/libp2p/go-libp2p-kbucket v0.0.1 h1:7H5hM851hkEpLOFjrVNSrrxo6J4bWrUQxxv+z1JW9xk= github.com/libp2p/go-libp2p-kbucket v0.0.1/go.mod h1:Y0iQDHRTk/ZgM8PC4jExoF+E4j+yXWwRkdldkMa5Xm4= github.com/libp2p/go-libp2p-kbucket v0.1.1 h1:ZrvW3qCM+lAuv7nrNts/zfEiClq+GZe8OIzX4Vb3Dwo=