metrics

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: Apache-2.0, BSD-2-Clause Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const PluginName = "Metrics"

PluginName is the name of the metrics collector plugin.

Variables

View Source
var AutopeeringMetrics = collector.NewCollection(autopeeringNamespace,
	collector.WithMetric(collector.NewMetric(neighborDropCount,
		collector.WithType(collector.Counter),
		collector.WithHelp("Number of dropped neighbors so far"),
		collector.WithInitFunc(func() {
			deps.P2Pmgr.NeighborGroupEvents(p2p.NeighborsGroupAuto).NeighborRemoved.Hook(func(event *p2p.NeighborRemovedEvent) {
				deps.Collector.Increment(autopeeringNamespace, neighborDropCount)
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(connectionsCount,
		collector.WithType(collector.Counter),
		collector.WithHelp("Number of established neighbor connections so far"),
		collector.WithInitFunc(func() {
			deps.P2Pmgr.NeighborGroupEvents(p2p.NeighborsGroupAuto).NeighborAdded.Hook(func(event *p2p.NeighborAddedEvent) {
				deps.Collector.Increment(autopeeringNamespace, connectionsCount)
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(neighborConnectionLifetimeSec,
		collector.WithType(collector.Counter),
		collector.WithHelp("Time since a neighbor connection establishment"),
		collector.WithInitFunc(func() {
			deps.P2Pmgr.NeighborGroupEvents(p2p.NeighborsGroupAuto).NeighborRemoved.Hook(func(event *p2p.NeighborRemovedEvent) {
				neighborConnectionsLifeTime := time.Since(event.Neighbor.ConnectionEstablished())
				deps.Collector.Update(autopeeringNamespace, neighborConnectionLifetimeSec, collector.SingleValue(neighborConnectionsLifeTime.Seconds()))
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(distance,
		collector.WithType(collector.Gauge),
		collector.WithHelp("A relative distance between the node and the neighbor"),
		collector.WithInitFunc(func() {
			var onAutopeeringSelection = func(event *selection.PeeringEvent) {
				deps.Collector.Update(autopeeringNamespace, distance, collector.SingleValue(float64(event.Distance)))
			}
			if deps.Selection != nil {
				deps.Selection.Events().IncomingPeering.Hook(onAutopeeringSelection, event.WithWorkerPool(Plugin.WorkerPool))
				deps.Selection.Events().OutgoingPeering.Hook(onAutopeeringSelection, event.WithWorkerPool(Plugin.WorkerPool))
			}
		}),
	)),
	collector.WithMetric(collector.NewMetric(trafficInboundBytes,
		collector.WithType(collector.Counter),
		collector.WithHelp("Inbound network autopeering traffic in bytes"),
		collector.WithCollectFunc(func() map[string]float64 {
			return collector.SingleValue(deps.AutopeeringConnMetric.RXBytes())
		}),
	)),
	collector.WithMetric(collector.NewMetric(trafficOutboundBytes,
		collector.WithType(collector.Counter),
		collector.WithHelp("Outbound network autopeering traffic in bytes"),
		collector.WithCollectFunc(func() map[string]float64 {
			return collector.SingleValue(deps.AutopeeringConnMetric.TXBytes())
		}),
	)),
)

AutopeeringMetrics is the collection of metrics for autopeering component.

View Source
var CommitmentsMetrics = collector.NewCollection(commitmentsNamespace,
	collector.WithMetric(collector.NewMetric(lastCommitment,
		collector.WithType(collector.GaugeVec),
		collector.WithHelp("Last commitment of the node."),
		collector.WithLabels("slot", "commitment"),
		collector.WithLabelValuesCollection(),
		collector.WithInitFunc(func() {
			deps.Collector.ResetMetric(commitmentsNamespace, lastCommitment)
			deps.Protocol.Events.Engine.Notarization.SlotCommitted.Hook(func(details *notarization.SlotCommittedDetails) {
				deps.Collector.Update(commitmentsNamespace, lastCommitment, collector.MultiLabels(strconv.Itoa(int(details.Commitment.Index())), details.Commitment.ID().Base58()))
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(seenTotal,
		collector.WithType(collector.Counter),
		collector.WithHelp("Number of commitments seen by the node."),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.ChainManager.ForkDetected.Hook(func(_ *chainmanager.Fork) {
				deps.Collector.Increment(commitmentsNamespace, seenTotal)
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(missingRequested,
		collector.WithType(collector.Counter),
		collector.WithHelp("Number of missing commitments requested by the node."),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.ChainManager.CommitmentMissing.Hook(func(commitment commitment.ID) {
				deps.Collector.Increment(commitmentsNamespace, missingRequested)
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(missingReceived,
		collector.WithType(collector.Counter),
		collector.WithHelp("Number of missing commitments received by the node."),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.ChainManager.MissingCommitmentReceived.Hook(func(commitment commitment.ID) {
				deps.Collector.Increment(commitmentsNamespace, missingReceived)
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(acceptedBlocks,
		collector.WithType(collector.GaugeVec),
		collector.WithHelp("Number of accepted blocks by the node per slot."),
		collector.WithLabels("slot"),
		collector.WithResetBeforeCollecting(true),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Notarization.SlotCommitted.Hook(func(details *notarization.SlotCommittedDetails) {
				deps.Collector.Update(commitmentsNamespace, acceptedBlocks, collector.MultiLabelsValues([]string{strconv.Itoa(int(details.Commitment.Index()))}, details.AcceptedBlocks.Size()))
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(transactions,
		collector.WithType(collector.GaugeVec),
		collector.WithHelp("Number of transactions by the node per slot."),
		collector.WithLabels("slot"),
		collector.WithResetBeforeCollecting(true),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Notarization.SlotCommitted.Hook(func(details *notarization.SlotCommittedDetails) {
				deps.Collector.Update(commitmentsNamespace, transactions, collector.MultiLabelsValues([]string{strconv.Itoa(int(details.Commitment.Index()))}, details.AcceptedTransactions.Size()))
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(validators,
		collector.WithType(collector.GaugeVec),
		collector.WithHelp("Number of active validators per slot."),
		collector.WithLabels("slot"),
		collector.WithResetBeforeCollecting(true),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Notarization.SlotCommitted.Hook(func(details *notarization.SlotCommittedDetails) {
				deps.Collector.Update(commitmentsNamespace, validators, collector.MultiLabelsValues([]string{strconv.Itoa(int(details.Commitment.Index()))}, details.ActiveValidatorsCount))
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
)
View Source
var ConflictMetrics = collector.NewCollection(conflictNamespace,
	collector.WithMetric(collector.NewMetric(resolutionTime,
		collector.WithType(collector.Counter),
		collector.WithHelp("Time since transaction issuance to the conflict acceptance"),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Ledger.MemPool.ConflictDAG.ConflictAccepted.Hook(func(conflict *conflictdag.Conflict[utxo.TransactionID, utxo.OutputID]) {
				firstAttachment := deps.Protocol.Engine().Mesh.Booker().GetEarliestAttachment(conflict.ID())
				timeSinceIssuance := time.Since(firstAttachment.IssuingTime()).Milliseconds()
				timeIssuanceSeconds := float64(timeSinceIssuance) / 1000
				deps.Collector.Update(conflictNamespace, resolutionTime, collector.SingleValue(timeIssuanceSeconds))
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(resolvedConflictCount,
		collector.WithType(collector.Counter),
		collector.WithHelp("Number of resolved (accepted) conflicts"),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Ledger.MemPool.ConflictDAG.ConflictAccepted.Hook(func(conflict *conflictdag.Conflict[utxo.TransactionID, utxo.OutputID]) {
				deps.Collector.Increment(conflictNamespace, resolvedConflictCount)
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(allConflictCounts,
		collector.WithType(collector.Counter),
		collector.WithHelp("Number of created conflicts"),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Ledger.MemPool.ConflictDAG.ConflictCreated.Hook(func(event *conflictdag.Conflict[utxo.TransactionID, utxo.OutputID]) {
				deps.Collector.Increment(conflictNamespace, allConflictCounts)
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
)
View Source
var DBMetrics = collector.NewCollection(dbNamespace,
	collector.WithMetric(collector.NewMetric(sizeBytes,
		collector.WithType(collector.GaugeVec),
		collector.WithHelp("DB size in bytes for permanent, prunable storage and retainer plugin"),
		collector.WithLabels("type"),
		collector.WithCollectFunc(func() map[string]float64 {
			mainEngine := deps.Protocol.MainEngineInstance()
			return collector.MultiLabelsValues(
				[]string{storagePermanentSizeLabel, storagePrunableSizeLabel, retainerSizeLabel},
				mainEngine.Storage.PermanentDatabaseSize(),
				mainEngine.Storage.PrunableDatabaseSize(),
				deps.Retainer.DatabaseSize(),
			)
		}),
	)),
)
View Source
var InfoMetrics = collector.NewCollection(infoNamespace,
	collector.WithMetric(collector.NewMetric(appName,
		collector.WithType(collector.GaugeVec),
		collector.WithHelp("Node software name and version."),
		collector.WithLabels("nodeID", "name", "version"),
		collector.WithLabelValuesCollection(),
		collector.WithInitValue(func() map[string]float64 {
			var nodeID string
			if deps.Local != nil {
				nodeID = deps.Local.ID().String()
			}
			return collector.MultiLabels(nodeID, banner.AppName, banner.AppVersion)
		}),
	)),
	collector.WithMetric(collector.NewMetric(nodeOS,
		collector.WithType(collector.GaugeVec),
		collector.WithHelp("Node OS."),
		collector.WithLabels("nodeID", "OS", "ARCH", "NUM_CPU"),
		collector.WithLabelValuesCollection(),
		collector.WithInitValue(func() map[string]float64 {
			var nodeID string
			if deps.Local != nil {
				nodeID = deps.Local.ID().String()
			}
			return collector.MultiLabels(nodeID, runtime.GOOS, runtime.GOARCH, strconv.Itoa(runtime.GOMAXPROCS(0)))
		}),
	)),
	collector.WithMetric(collector.NewMetric(syncStatus,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Node sync status based on MeshTime."),
		collector.WithCollectFunc(func() map[string]float64 {
			if deps.Protocol.Engine().IsSynced() {
				return collector.SingleValue(1)
			}
			return collector.SingleValue(0)
		}),
	)),
	collector.WithMetric(collector.NewMetric(cpuUsage,
		collector.WithType(collector.Gauge),
		collector.WithHelp("The percentage of cpu used either per CPU or combined. Calculated over the data scrap interval."),
		collector.WithCollectFunc(func() map[string]float64 {
			if percent, err := cpu.Percent(time.Second, false); err == nil {
				return collector.SingleValue(percent[0])
			}
			return collector.SingleValue(0)
		}),
	)),
	collector.WithMetric(collector.NewMetric(memUsage,
		collector.WithType(collector.Gauge),
		collector.WithHelp("The memory usage in bytes of allocated heap objects"),
		collector.WithCollectFunc(func() map[string]float64 {
			var m runtime.MemStats
			runtime.ReadMemStats(&m)
			return collector.SingleValue(float64(m.Alloc))
		}),
	)),
)
View Source
var ManaMetrics = collector.NewCollection(manaNamespace,
	collector.WithMetric(collector.NewMetric(manaPerNode,
		collector.WithType(collector.GaugeVec),
		collector.WithLabels("nodeID"),
		collector.WithResetBeforeCollecting(true),
		collector.WithHelp("Current amount of aMana of each node in the network."),
		collector.WithCollectFunc(func() map[string]float64 {
			access := deps.Protocol.Engine().ThroughputQuota.BalanceByIDs()
			res := make(map[string]float64)
			for id, val := range access {
				res[id.String()] = float64(val)
			}
			return res
		}),
	)),
	collector.WithMetric(collector.NewMetric(weightPerNode,
		collector.WithType(collector.GaugeVec),
		collector.WithLabels("nodeID"),
		collector.WithResetBeforeCollecting(true),
		collector.WithHelp("Current amount of cMana of each node in the network."),
		collector.WithCollectFunc(func() map[string]float64 {
			consensus := lo.PanicOnErr(deps.Protocol.Engine().SybilProtection.Weights().Map())
			res := make(map[string]float64)
			for id, val := range consensus {
				res[id.String()] = float64(val)
			}
			return res
		}),
	)),
	collector.WithMetric(collector.NewMetric(nodeManaPercentile,
		collector.WithType(collector.GaugeVec),
		collector.WithLabels("type"),
		collector.WithHelp("Current percentile of the local node in terms of aMana."),
		collector.WithCollectFunc(func() map[string]float64 {
			access := deps.Protocol.Engine().ThroughputQuota.BalanceByIDs()
			accPerc := manamodels.Percentile(deps.Local.ID(), access)
			consensus := lo.PanicOnErr(deps.Protocol.Engine().SybilProtection.Weights().Map())
			conPerc := manamodels.Percentile(deps.Local.ID(), consensus)

			return collector.MultiLabelsValues([]string{"access", "consensus"}, accPerc, conPerc)
		}),
	)),
	collector.WithMetric(collector.NewMetric(neighborsMana,
		collector.WithType(collector.GaugeVec),
		collector.WithLabels("type"),
		collector.WithHelp(""),
		collector.WithCollectFunc(func() map[string]float64 {
			neighbors := deps.P2Pmgr.AllNeighbors()
			access := deps.Protocol.Engine().ThroughputQuota.BalanceByIDs()
			consensus := lo.PanicOnErr(deps.Protocol.Engine().SybilProtection.Weights().Map())

			accAvg := manamodels.NeighborsAverageMana(access, neighbors)
			conAvg := manamodels.NeighborsAverageMana(consensus, neighbors)
			return collector.MultiLabelsValues([]string{"access", "consensus"}, accAvg, conAvg)
		}),
	)),
)
View Source
var MeshMetrics = collector.NewCollection(meshNamespace,
	collector.WithMetric(collector.NewMetric(tipsCount,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Number of tips in the mesh"),
		collector.WithCollectFunc(func() map[string]float64 {
			count := deps.Protocol.TipManager.TipCount()
			return collector.SingleValue(count)
		}),
	)),
	collector.WithMetric(collector.NewMetric(blockPerTypeCount,
		collector.WithType(collector.GaugeVec),
		collector.WithHelp("Number of blocks per type in the mesh"),
		collector.WithLabels("type"),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Consensus.BlockGadget.BlockAccepted.Hook(func(block *blockgadget.Block) {
				blockType := collector.NewBlockType(block.Payload().Type()).String()
				deps.Collector.Increment(meshNamespace, blockPerTypeCount, blockType)
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(missingBlocksCount,
		collector.WithType(collector.Counter),
		collector.WithHelp("Number of blocks missing during the solidification in the mesh"),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Mesh.BlockDAG.BlockMissing.Hook(func(_ *blockdag.Block) {
				deps.Collector.Increment(meshNamespace, missingBlocksCount)
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(parentPerTypeCount,
		collector.WithType(collector.CounterVec),
		collector.WithHelp("Number of parents of the block per its type"),
		collector.WithLabels("type"),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Consensus.BlockGadget.BlockAccepted.Hook(func(block *blockgadget.Block) {
				blockType := collector.NewBlockType(block.Payload().Type()).String()
				block.ForEachParent(func(parent models.Parent) {
					deps.Collector.Increment(meshNamespace, parentPerTypeCount, blockType)
				})
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(blocksPerComponentCount,
		collector.WithType(collector.CounterVec),
		collector.WithHelp("Number of blocks per component"),
		collector.WithLabels("component"),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Network.BlockReceived.Hook(func(_ *network.BlockReceivedEvent) {
				deps.Collector.Increment(meshNamespace, blocksPerComponentCount, collector.Received.String())
			}, event.WithWorkerPool(Plugin.WorkerPool))
			deps.Protocol.Events.Engine.Filter.BlockAllowed.Hook(func(_ *models.Block) {
				deps.Collector.Increment(meshNamespace, blocksPerComponentCount, collector.Allowed.String())
			}, event.WithWorkerPool(Plugin.WorkerPool))
			deps.BlockIssuer.Events.BlockIssued.Hook(func(_ *models.Block) {
				deps.Collector.Increment(meshNamespace, blocksPerComponentCount, collector.Issued.String())
			}, event.WithWorkerPool(Plugin.WorkerPool))
			deps.Protocol.Events.Engine.Mesh.BlockDAG.BlockAttached.Hook(func(block *blockdag.Block) {
				deps.Collector.Increment(meshNamespace, blocksPerComponentCount, collector.Attached.String())
			}, event.WithWorkerPool(Plugin.WorkerPool))
			deps.Protocol.Events.Engine.Mesh.BlockDAG.BlockSolid.Hook(func(block *blockdag.Block) {
				deps.Collector.Increment(meshNamespace, blocksPerComponentCount, collector.Solidified.String())
			}, event.WithWorkerPool(Plugin.WorkerPool))
			deps.Protocol.Events.CongestionControl.Scheduler.BlockScheduled.Hook(func(block *scheduler.Block) {
				deps.Collector.Increment(meshNamespace, blocksPerComponentCount, collector.Scheduled.String())
			}, event.WithWorkerPool(Plugin.WorkerPool))
			deps.Protocol.Events.Engine.Mesh.Booker.BlockBooked.Hook(func(_ *booker.BlockBookedEvent) {
				deps.Collector.Increment(meshNamespace, blocksPerComponentCount, collector.Booked.String())
			}, event.WithWorkerPool(Plugin.WorkerPool))
			deps.Protocol.Events.CongestionControl.Scheduler.BlockDropped.Hook(func(block *scheduler.Block) {
				deps.Collector.Increment(meshNamespace, blocksPerComponentCount, collector.SchedulerDropped.String())
			}, event.WithWorkerPool(Plugin.WorkerPool))
			deps.Protocol.Events.CongestionControl.Scheduler.BlockSkipped.Hook(func(block *scheduler.Block) {
				deps.Collector.Increment(meshNamespace, blocksPerComponentCount, collector.SchedulerSkipped.String())
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(blocksOrphanedCount,
		collector.WithType(collector.Counter),
		collector.WithHelp("Number of orphaned blocks"),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Mesh.BlockDAG.BlockOrphaned.Hook(func(block *blockdag.Block) {
				deps.Collector.Increment(meshNamespace, blocksOrphanedCount)
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(acceptedBlocksCount,
		collector.WithType(collector.Counter),
		collector.WithHelp("Number of accepted blocks"),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Consensus.BlockGadget.BlockAccepted.Hook(func(block *blockgadget.Block) {
				deps.Collector.Increment(meshNamespace, acceptedBlocksCount)
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(timeSinceReceivedPerComponent,
		collector.WithType(collector.CounterVec),
		collector.WithHelp("Time since the block was received per component"),
		collector.WithLabels("component"),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Consensus.BlockGadget.BlockAccepted.Hook(func(block *blockgadget.Block) {
				blockType := collector.NewBlockType(block.Payload().Type()).String()
				timeSince := float64(time.Since(block.IssuingTime()).Milliseconds())
				deps.Collector.Update(meshNamespace, timeSinceReceivedPerComponent, collector.MultiLabelsValues([]string{blockType}, timeSince))
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(requestQueueSize,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Number of blocks in the request queue"),
		collector.WithCollectFunc(func() map[string]float64 {
			return collector.SingleValue(float64(deps.Protocol.Engine().BlockRequester.QueueSize()))
		}),
	)),
)
View Source
var Parameters = &ParametersDefinition{}

Parameters contains the configuration used by the metrics collector plugin.

View Source
var (
	// Plugin is the plugin instance of the metrics collector plugin.
	Plugin *node.Plugin
)
View Source
var RateSetterMetrics = collector.NewCollection(rateSetterNamespace,
	collector.WithMetric(collector.NewMetric(estimate,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Current rate estimate for the node."),
		collector.WithCollectFunc(func() map[string]float64 {
			return collector.SingleValue(deps.BlockIssuer.RateSetter.Estimate())
		}),
	)),
	collector.WithMetric(collector.NewMetric(ownRate,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Current rate of the node."),
		collector.WithCollectFunc(func() map[string]float64 {
			return collector.SingleValue(deps.BlockIssuer.RateSetter.Rate())
		}),
	)),
)
View Source
var SchedulerMetrics = collector.NewCollection(schedulerNamespace,
	collector.WithMetric(collector.NewMetric(queueSizePerNode,
		collector.WithType(collector.GaugeVec),
		collector.WithLabels("node_id"),
		collector.WithResetBeforeCollecting(true),
		collector.WithHelp("Current size of each node's queue (in bytes)."),
		collector.WithCollectFunc(func() map[string]float64 {
			res := make(map[string]float64)
			for issuer, s := range deps.Protocol.CongestionControl.Scheduler().IssuerQueueSizes() {
				res[issuer.String()] = float64(s)
			}
			return res
		}),
	)),
	collector.WithMetric(collector.NewMetric(manaAmountPerNode,
		collector.WithType(collector.GaugeVec),
		collector.WithLabels("node_id"),
		collector.WithResetBeforeCollecting(true),
		collector.WithHelp("Current amount of aMana of each node in the queue (in bytes)."),
		collector.WithCollectFunc(func() map[string]float64 {
			res := make(map[string]float64)
			for issuer, val := range deps.Protocol.CongestionControl.Scheduler().GetAccessManaMap() {
				res[issuer.String()] = float64(val)
			}
			return res
		}),
	)),
	collector.WithMetric(collector.NewMetric(bufferMaxSize,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Maximum number of bytes that can be stored in the buffer."),
		collector.WithCollectFunc(func() map[string]float64 {
			return collector.SingleValue(deps.Protocol.CongestionControl.Scheduler().MaxBufferSize())
		}),
	)),
	collector.WithMetric(collector.NewMetric(bufferReadyBlockCount,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Number of ready blocks in the scheduler buffer."),
		collector.WithCollectFunc(func() map[string]float64 {
			return collector.SingleValue(deps.Protocol.CongestionControl.Scheduler().ReadyBlocksCount())
		}),
	)),
	collector.WithMetric(collector.NewMetric(bufferTotalSize,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Current size of the scheduler buffer (in bytes)."),
		collector.WithCollectFunc(func() map[string]float64 {
			return collector.SingleValue(deps.Protocol.CongestionControl.Scheduler().BufferSize())
		}),
	)),
	collector.WithMetric(collector.NewMetric(deficit,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Current deficit of the scheduler."),
		collector.WithCollectFunc(func() map[string]float64 {
			deficit, _ := deps.Protocol.CongestionControl.Scheduler().Deficit(deps.Local.ID()).Float64()
			return collector.SingleValue(deficit)
		}),
	)),
	collector.WithMetric(collector.NewMetric(rate,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Current rate of the scheduler."),
		collector.WithCollectFunc(func() map[string]float64 {
			return collector.SingleValue(deps.Protocol.CongestionControl.Scheduler().Rate())
		}),
	)),
)
View Source
var SlotMetrics = collector.NewCollection(slotNamespace,
	collector.WithMetric(collector.NewMetric(totalBlocks,
		collector.WithType(collector.CounterVec),
		collector.WithLabels(labelName),
		collector.WithHelp("Number of blocks seen by the node in a slot."),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Mesh.BlockDAG.BlockAttached.Hook(func(block *blockdag.Block) {
				eventSlot := int(block.ID().Index())
				deps.Collector.Increment(slotNamespace, totalBlocks, strconv.Itoa(eventSlot))

				for _, metricName := range []string{acceptedBlocksInSlot, orphanedBlocks, invalidBlocks, subjectivelyInvalidBlocks, totalAttachments, orphanedAttachments, rejectedAttachments, acceptedAttachments, createdConflicts, acceptedConflicts, rejectedConflicts, notConflictingConflicts} {
					deps.Collector.Update(slotNamespace, metricName, map[string]float64{
						strconv.Itoa(eventSlot): 0,
					})
				}
			}, event.WithWorkerPool(Plugin.WorkerPool))

			deps.Protocol.Events.Engine.Notarization.SlotCommitted.Hook(func(details *notarization.SlotCommittedDetails) {
				slotToEvict := int(details.Commitment.Index()) - metricEvictionOffset

				for _, metricName := range []string{totalBlocks, acceptedBlocksInSlot, orphanedBlocks, invalidBlocks, subjectivelyInvalidBlocks, totalAttachments, orphanedAttachments, rejectedAttachments, acceptedAttachments, createdConflicts, acceptedConflicts, rejectedConflicts, notConflictingConflicts} {
					deps.Collector.ResetMetricLabels(slotNamespace, metricName, map[string]string{
						labelName: strconv.Itoa(slotToEvict),
					})
				}
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),

	collector.WithMetric(collector.NewMetric(acceptedBlocksInSlot,
		collector.WithType(collector.CounterVec),
		collector.WithHelp("Number of accepted blocks in a slot."),
		collector.WithLabels(labelName),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Consensus.BlockGadget.BlockAccepted.Hook(func(block *blockgadget.Block) {
				eventSlot := int(block.ID().Index())
				deps.Collector.Increment(slotNamespace, acceptedBlocksInSlot, strconv.Itoa(eventSlot))
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(orphanedBlocks,
		collector.WithType(collector.CounterVec),
		collector.WithLabels(labelName),
		collector.WithHelp("Number of orphaned blocks in a slot."),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Mesh.BlockDAG.BlockOrphaned.Hook(func(block *blockdag.Block) {
				eventSlot := int(block.ID().Index())
				deps.Collector.Increment(slotNamespace, orphanedBlocks, strconv.Itoa(eventSlot))
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(invalidBlocks,
		collector.WithType(collector.CounterVec),
		collector.WithLabels(labelName),
		collector.WithHelp("Number of invalid blocks in a slot slot."),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Mesh.BlockDAG.BlockInvalid.Hook(func(blockInvalidEvent *blockdag.BlockInvalidEvent) {
				fmt.Println("block invalid", blockInvalidEvent.Block.ID(), blockInvalidEvent.Reason)
				eventSlot := int(blockInvalidEvent.Block.ID().Index())
				deps.Collector.Increment(slotNamespace, invalidBlocks, strconv.Itoa(eventSlot))
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(subjectivelyInvalidBlocks,
		collector.WithType(collector.CounterVec),
		collector.WithLabels(labelName),
		collector.WithHelp("Number of invalid blocks in a slot slot."),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Mesh.Booker.BlockTracked.Hook(func(block *booker.Block) {
				if block.IsSubjectivelyInvalid() {
					eventSlot := int(block.ID().Index())
					deps.Collector.Increment(slotNamespace, subjectivelyInvalidBlocks, strconv.Itoa(eventSlot))
				}
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),

	collector.WithMetric(collector.NewMetric(totalAttachments,
		collector.WithType(collector.CounterVec),
		collector.WithLabels(labelName),
		collector.WithHelp("Number of transaction attachments by the node per slot."),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Mesh.Booker.AttachmentCreated.Hook(func(block *booker.Block) {
				eventSlot := int(block.ID().Index())
				deps.Collector.Increment(slotNamespace, totalAttachments, strconv.Itoa(eventSlot))
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(orphanedAttachments,
		collector.WithType(collector.CounterVec),
		collector.WithLabels(labelName),
		collector.WithHelp("Number of orphaned attachments by the node per slot."),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Mesh.Booker.AttachmentOrphaned.Hook(func(block *booker.Block) {
				eventSlot := int(block.ID().Index())
				deps.Collector.Increment(slotNamespace, orphanedAttachments, strconv.Itoa(eventSlot))
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(rejectedAttachments,
		collector.WithType(collector.CounterVec),
		collector.WithLabels(labelName),
		collector.WithHelp("Number of rejected attachments by the node per slot."),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Ledger.MemPool.TransactionRejected.Hook(func(transactionMetadata *mempool.TransactionMetadata) {
				for it := deps.Protocol.Engine().Mesh.Booker().GetAllAttachments(transactionMetadata.ID()).Iterator(); it.HasNext(); {
					attachmentBlock := it.Next()
					if !attachmentBlock.IsOrphaned() {
						deps.Collector.Increment(slotNamespace, rejectedAttachments, strconv.Itoa(int(attachmentBlock.ID().Index())))
					}
				}
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(acceptedAttachments,
		collector.WithType(collector.CounterVec),
		collector.WithLabels(labelName),
		collector.WithHelp("Number of accepted attachments by the node per slot."),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Ledger.MemPool.TransactionAccepted.Hook(func(transactionEvent *mempool.TransactionEvent) {
				for it := deps.Protocol.Engine().Mesh.Booker().GetAllAttachments(transactionEvent.Metadata.ID()).Iterator(); it.HasNext(); {
					attachmentBlock := it.Next()
					if !attachmentBlock.IsOrphaned() {
						deps.Collector.Increment(slotNamespace, acceptedAttachments, strconv.Itoa(int(attachmentBlock.ID().Index())))
					}
				}
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(createdConflicts,
		collector.WithType(collector.CounterVec),
		collector.WithLabels(labelName),
		collector.WithHelp("Number of conflicts created per slot."),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Ledger.MemPool.ConflictDAG.ConflictCreated.Hook(func(conflictCreated *conflictdag.Conflict[utxo.TransactionID, utxo.OutputID]) {
				for it := deps.Protocol.Engine().Mesh.Booker().GetAllAttachments(conflictCreated.ID()).Iterator(); it.HasNext(); {
					deps.Collector.Increment(slotNamespace, createdConflicts, strconv.Itoa(int(it.Next().ID().Index())))
				}
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(acceptedConflicts,
		collector.WithType(collector.CounterVec),
		collector.WithLabels(labelName),
		collector.WithHelp("Number of conflicts accepted per slot."),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Ledger.MemPool.ConflictDAG.ConflictAccepted.Hook(func(conflict *conflictdag.Conflict[utxo.TransactionID, utxo.OutputID]) {
				for it := deps.Protocol.Engine().Mesh.Booker().GetAllAttachments(conflict.ID()).Iterator(); it.HasNext(); {
					deps.Collector.Increment(slotNamespace, acceptedConflicts, strconv.Itoa(int(it.Next().ID().Index())))
				}
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(rejectedConflicts,
		collector.WithType(collector.CounterVec),
		collector.WithLabels(labelName),
		collector.WithHelp("Number of conflicts rejected per slot."),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Ledger.MemPool.ConflictDAG.ConflictRejected.Hook(func(conflict *conflictdag.Conflict[utxo.TransactionID, utxo.OutputID]) {
				for it := deps.Protocol.Engine().Mesh.Booker().GetAllAttachments(conflict.ID()).Iterator(); it.HasNext(); {
					deps.Collector.Increment(slotNamespace, rejectedConflicts, strconv.Itoa(int(it.Next().ID().Index())))
				}
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(notConflictingConflicts,
		collector.WithType(collector.CounterVec),
		collector.WithLabels(labelName),
		collector.WithHelp("Number of conflicts rejected per slot."),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Ledger.MemPool.ConflictDAG.ConflictNotConflicting.Hook(func(conflict *conflictdag.Conflict[utxo.TransactionID, utxo.OutputID]) {
				for it := deps.Protocol.Engine().Mesh.Booker().GetAllAttachments(conflict.ID()).Iterator(); it.HasNext(); {
					deps.Collector.Increment(slotNamespace, notConflictingConflicts, strconv.Itoa(int(it.Next().ID().Index())))
				}
			}, event.WithWorkerPool(Plugin.WorkerPool))
		}),
	)),
)
View Source
var WorkerPoolMetrics = collector.NewCollection(workerPoolNamespace,
	collector.WithMetric(collector.NewMetric(workers,
		collector.WithType(collector.GaugeVec),
		collector.WithHelp("Number of workers in the worker pool."),
		collector.WithLabels("type"),
		collector.WithCollectFunc(func() map[string]float64 {
			collected := make(map[string]float64)

			for _, p := range Plugin.Node.LoadedPlugins() {
				collected[p.Name] = float64(p.WorkerPool.WorkerCount())
			}

			if deps.Protocol != nil {
				for name, wp := range deps.Protocol.Workers.Pools() {
					collected[name] = float64(wp.WorkerCount())
				}
			}

			if deps.Retainer != nil {
				for name, wp := range deps.Retainer.Workers.Pools() {
					collected[name] = float64(wp.WorkerCount())
				}
			}

			return collected
		}),
	)),
	collector.WithMetric(collector.NewMetric(tasks,
		collector.WithType(collector.GaugeVec),
		collector.WithHelp("Number of pending tasks in the worker pool."),
		collector.WithLabels("type"),
		collector.WithCollectFunc(func() map[string]float64 {
			collected := make(map[string]float64)

			for _, p := range Plugin.Node.LoadedPlugins() {
				collected[p.Name] = float64(p.WorkerPool.PendingTasksCounter.Get())
			}

			if deps.Protocol != nil {
				for name, wp := range deps.Protocol.Workers.Pools() {
					collected[name] = float64(wp.PendingTasksCounter.Get())
				}
			}

			if deps.Retainer != nil {
				for name, wp := range deps.Retainer.Workers.Pools() {
					collected[name] = float64(wp.PendingTasksCounter.Get())
				}
			}

			return collected
		}),
	)),
)

Functions

This section is empty.

Types

type ParametersDefinition

type ParametersDefinition struct {
	// BindAddress defines the bind address for the Prometheus exporter server.
	BindAddress string `default:"0.0.0.0:9311" usage:"bind address on which the Prometheus exporter server"`
	// GoMetrics defines whether to include Go metrics.
	GoMetrics bool `default:"false" usage:"include go metrics"`
	// ProcessMetrics defines whether to include process metrics.
	ProcessMetrics bool `default:"false" usage:"include process metrics"`
	// PromhttpMetrics defines whether to include promhttp metrics.
	PromhttpMetrics bool `default:"false" usage:"include promhttp metrics"`
}

ParametersDefinition contains the definition of the parameters used by the metrics plugin.

Jump to

Keyboard shortcuts

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