mirror of
https://github.com/ipfs/kubo.git
synced 2025-08-06 19:44:01 +08:00
Move register exporter to metrics file
This commit is contained in:
@ -649,6 +649,7 @@ func serveHTTPApi(req *cmds.Request, cctx *oldcmds.Context) (<-chan error, error
|
||||
var opts = []corehttp.ServeOption{
|
||||
corehttp.MetricsCollectionOption("api"),
|
||||
corehttp.MetricsOpenCensusCollectionOption(),
|
||||
corehttp.MetricsOpenCensusDefaultPrometheusRegistry(),
|
||||
corehttp.CheckVersionOption(),
|
||||
corehttp.CommandsOption(*cctx),
|
||||
corehttp.WebUIOption,
|
||||
|
@ -51,6 +51,30 @@ func MetricsOpenCensusCollectionOption() ServeOption {
|
||||
}
|
||||
}
|
||||
|
||||
// MetricsOpenCensusDefaultPrometheusRegistry registers the default prometheus
|
||||
// registry as an exporter to OpenCensus metrics. This means that OpenCensus
|
||||
// metrics will show up in the prometheus metrics endpoint
|
||||
func MetricsOpenCensusDefaultPrometheusRegistry() ServeOption {
|
||||
return func(_ *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
|
||||
log.Info("Init OpenCensus with default prometheus registry")
|
||||
|
||||
pe, err := ocprom.NewExporter(ocprom.Options{
|
||||
Registry: prometheus.DefaultRegisterer.(*prometheus.Registry),
|
||||
OnError: func(err error) {
|
||||
log.Errorw("OC default registry ERROR", "error", err)
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// register prometheus with opencensus
|
||||
view.RegisterExporter(pe)
|
||||
|
||||
return mux, nil
|
||||
}
|
||||
}
|
||||
|
||||
// MetricsCollectionOption adds collection of net/http-related metrics.
|
||||
func MetricsCollectionOption(handlerName string) ServeOption {
|
||||
return func(_ *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
ocprom "contrib.go.opencensus.io/exporter/prometheus"
|
||||
"github.com/benbjohnson/clock"
|
||||
logging "github.com/ipfs/go-log/v2"
|
||||
config "github.com/ipfs/kubo/config"
|
||||
@ -21,7 +20,6 @@ import (
|
||||
rcmgr "github.com/libp2p/go-libp2p-resource-manager"
|
||||
rcmgrObs "github.com/libp2p/go-libp2p-resource-manager/obs"
|
||||
"github.com/multiformats/go-multiaddr"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"go.opencensus.io/stats/view"
|
||||
|
||||
"go.uber.org/fx"
|
||||
@ -86,18 +84,10 @@ func ResourceManager(cfg config.SwarmConfig) interface{} {
|
||||
log.Infof("Setting allowlist to: %v", mas)
|
||||
}
|
||||
|
||||
// Hook up the trace reporter metrics
|
||||
err = view.Register(rcmgrObs.DefaultViews...)
|
||||
view.Register(rcmgrObs.DefaultViews...)
|
||||
if err != nil {
|
||||
return nil, opts, fmt.Errorf("registering rcmgr obs views: %w", err)
|
||||
}
|
||||
_, err = ocprom.NewExporter(ocprom.Options{
|
||||
Registry: prometheus.DefaultRegisterer.(*prometheus.Registry),
|
||||
Namespace: "rcmgr_trace_metrics",
|
||||
})
|
||||
if err != nil {
|
||||
return nil, opts, fmt.Errorf("creating new prom exporter: %w", err)
|
||||
}
|
||||
|
||||
if os.Getenv("LIBP2P_DEBUG_RCMGR") != "" {
|
||||
traceFilePath := filepath.Join(repoPath, NetLimitTraceFilename)
|
||||
|
Reference in New Issue
Block a user