metrics

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package metrics provides Prometheus metrics specific to awl-bootstrap-node.

Most of the useful telemetry for a bootstrap node (relay service, autonat, swarm, resource manager, identify, holepunch, ...) comes from libp2p's own built-in Prometheus metrics, enabled via libp2p.PrometheusRegisterer. This package only adds what libp2p does not expose: DHT routing table size, node bandwidth by protocol, node info/uptime, peerstore size, connected peers and DHT requests by client, and relayed connection durations with buckets that fit the relay limits.

Index

Constants

This section is empty.

Variables

View Source
var (
	NodeInfo = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Namespace: namespace,
		Subsystem: subsystemNode,
		Name:      "info",
		Help:      "Static node information.",
	}, []string{"version", "peer_id", "go_version", "os", "arch"})

	NodeUptimeSeconds = promauto.NewGauge(prometheus.GaugeOpts{
		Namespace: namespace,
		Subsystem: subsystemNode,
		Name:      "uptime_seconds",
		Help:      "Node uptime in seconds.",
	})

	NodeStartTimestamp = promauto.NewGauge(prometheus.GaugeOpts{
		Namespace: namespace,
		Subsystem: subsystemNode,
		Name:      "start_timestamp",
		Help:      "Unix timestamp of node start.",
	})
)
View Source
var (
	// P2PDHTRoutingTableSize is not provided by libp2p Prometheus metrics
	// (go-libp2p-kad-dht is instrumented via OpenTelemetry and does not export
	// routing table size), so we expose it ourselves.
	P2PDHTRoutingTableSize = promauto.NewGauge(prometheus.GaugeOpts{
		Namespace: namespace,
		Subsystem: subsystemP2P,
		Name:      "dht_routing_table_size",
		Help:      "DHT routing table size.",
	})

	P2PBootstrapPeersConnected = promauto.NewGauge(prometheus.GaugeOpts{
		Namespace: namespace,
		Subsystem: subsystemP2P,
		Name:      "bootstrap_peers_connected",
		Help:      "Number of connected bootstrap peers.",
	})
)
View Source
var P2PDHTRequestsTotal = promauto.NewCounterVec(prometheus.CounterOpts{
	Namespace: namespace,
	Subsystem: subsystemP2P,
	Name:      "dht_requests_total",
	Help:      "DHT requests received, by message type and by the client of the peer that sent them.",
}, []string{"message_type", labelNameApp, labelNameVersion})

P2PDHTRequestsTotal adds the client of the sender to what libp2p_kad_dht_rpc_inbound_messages_total counts: the version shows how much of the DHT load comes from old clients.

View Source
var P2PRelayCircuitDurationSeconds = promauto.NewHistogram(prometheus.HistogramOpts{
	Namespace: namespace,
	Subsystem: subsystemP2P,
	Name:      "relay_circuit_duration_seconds",
	Help:      "How long relayed connections lasted. Attempts that failed to reach the destination are counted too, with a duration under 1 s.",
	Buckets:   []float64{1, 10, 30, 60, 110, 125, 300, 590, 610, 1200, 3600},
})

P2PRelayCircuitDurationSeconds repeats libp2p_relaysvc_connection_duration_seconds with buckets that fit relayed connections: the libp2p one has the default buckets, the largest is 10 s, so it can't show circuits cut by the relay limit. The buckets are around 2 and 10 minutes, the current limit and the next one.

libp2p reports a circuit as closed also when the relay could not reach the destination, so failed attempts land in the first bucket. To get shares of established circuits, divide by libp2p_relaysvc_connection_request_response_status_total{status="ok"}.

Functions

func CountDHTRequests

func CountDHTRequests(ps peerstore.Peerstore) dht.Option

CountDHTRequests returns a DHT option that counts the received requests in P2PDHTRequestsTotal. The user agent of the sender is taken from ps.

func RelayMetricsTracer

func RelayMetricsTracer(reg prometheus.Registerer) relay.MetricsTracer

RelayMetricsTracer returns the relay metrics tracer of libp2p registered with reg, which also observes P2PRelayCircuitDurationSeconds. Pass it with relay.WithMetricsTracer: it replaces the tracer libp2p sets up itself.

func SetBandwidthStats

func SetBandwidthStats(s BandwidthStats)

SetBandwidthStats sets the source of the traffic metric. The metric is absent until it is set.

func SetHost

func SetHost(h host.Host)

SetHost sets the host for the metrics computed on scrape: connected peers and peerstore size. They are absent until it is set.

func SetNodeInfo

func SetNodeInfo(version, peerID string)

SetNodeInfo sets the static node info gauge and the start timestamp.

func StartBackgroundUpdater

func StartBackgroundUpdater(ctx context.Context, p2pMetrics P2pMetrics)

StartBackgroundUpdater periodically updates gauge-type metrics from their data sources.

Types

type BandwidthStats

type BandwidthStats interface {
	NetworkStatsByProtocol() map[protocol.ID]metrics.Stats
}

BandwidthStats is the source of the traffic metric. It is satisfied by *github.com/anywherelan/awl/p2p.P2p.

type P2pMetrics

type P2pMetrics interface {
	RoutingTableSize() int
	BootstrapPeersStats() (total int, connected int)
}

P2pMetrics is an interface for getting p2p stats used by the background updater. It is satisfied by *github.com/anywherelan/awl/p2p.P2p.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL