prometheus

package
v1.0.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AccountMetrics = collector.NewCollection(accountNamespace,
	collector.WithMetric(collector.NewMetric(activeSeats,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Seats seen as active by the node."),
		collector.WithCollectFunc(func() (metricValue float64, labelValues []string) {
			return float64(deps.Protocol.Engines.Main.Get().SybilProtection.SeatManager().OnlineCommittee().Size()), nil
		}),
	)),
)
View Source
var CommitmentsMetrics = collector.NewCollection(commitmentsNamespace,
	collector.WithMetric(collector.NewMetric(latestCommitment,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Last commitment of the node."),
		collector.WithLabels("commitment"),
		collector.WithPruningDelay(10*time.Minute),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Notarization.SlotCommitted.Hook(func(details *notarization.SlotCommittedDetails) {
				deps.Collector.Update(commitmentsNamespace, latestCommitment, float64(details.Commitment.ID().Slot()), "C "+details.Commitment.ID().ToHex())
			}, event.WithWorkerPool(Component.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(finalizedCommitment,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Last commitment finalized by the node."),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.SlotGadget.SlotFinalized.Hook(func(slot iotago.SlotIndex) {
				deps.Collector.Update(commitmentsNamespace, finalizedCommitment, float64(slot))
			}, event.WithWorkerPool(Component.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(forksCount,
		collector.WithType(collector.Counter),
		collector.WithHelp("Number of forks seen by the node."),
		collector.WithInitFunc(func() {
			deps.Protocol.Chains.HeaviestVerifiedCandidate.OnUpdate(func(prevHeaviestVerifiedCandidate *protocol.Chain, _ *protocol.Chain) {
				if prevHeaviestVerifiedCandidate != nil {
					Component.WorkerPool.Submit(func() { deps.Collector.Increment(commitmentsNamespace, forksCount) })
				}
			})
		}),
	)),
	collector.WithMetric(collector.NewMetric(spawnedEnginesCount,
		collector.WithType(collector.Counter),
		collector.WithHelp("Number spawned engines since the node started."),
		collector.WithInitFunc(func() {
			deps.Protocol.Chains.WithInitializedEngines(func(_ *protocol.Chain, _ *engine.Engine) (shutdown func()) {
				Component.WorkerPool.Submit(func() { deps.Collector.Increment(commitmentsNamespace, spawnedEnginesCount) })

				return nil
			})
		}),
	)),
	collector.WithMetric(collector.NewMetric(seenChainsCount,
		collector.WithType(collector.Counter),
		collector.WithHelp("Number chains seen since the node started."),
		collector.WithInitFunc(func() {
			deps.Protocol.Chains.WithElements(func(_ *protocol.Chain) (teardown func()) {
				Component.WorkerPool.Submit(func() { deps.Collector.Increment(commitmentsNamespace, seenChainsCount) })

				return nil
			})
		}),
	)),
	collector.WithMetric(collector.NewMetric(activeChainsCount,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Number currently active chains."),
		collector.WithCollectFunc(func() (metricValue float64, labelValues []string) {
			return float64(deps.Protocol.Chains.Size()), nil
		}),
	)),
	collector.WithMetric(collector.NewMetric(acceptedBlocks,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Number of accepted blocks by the node per slot."),
		collector.WithLabels("slot"),
		collector.WithPruningDelay(10*time.Minute),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Notarization.SlotCommitted.Hook(func(details *notarization.SlotCommittedDetails) {
				deps.Collector.Update(commitmentsNamespace, acceptedBlocks, float64(details.AcceptedBlocks.Size()), strconv.Itoa(int(details.Commitment.Slot())))
			}, event.WithWorkerPool(Component.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(transactions,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Number of accepted transactions by the node per slot."),
		collector.WithLabels("slot"),
		collector.WithPruningDelay(10*time.Minute),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Notarization.SlotCommitted.Hook(func(details *notarization.SlotCommittedDetails) {
				deps.Collector.Update(commitmentsNamespace, transactions, float64(len(details.Mutations)), strconv.Itoa(int(details.Commitment.Slot())))
			}, event.WithWorkerPool(Component.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(validators,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Number of active validators per slot."),
		collector.WithLabels("slot"),
		collector.WithPruningDelay(10*time.Minute),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Notarization.SlotCommitted.Hook(func(details *notarization.SlotCommittedDetails) {
				deps.Collector.Update(commitmentsNamespace, validators, float64(details.ActiveValidatorsCount), strconv.Itoa(int(details.Commitment.Slot())))
			}, event.WithWorkerPool(Component.WorkerPool))
		}),
	)),
)
View Source
var (
	Component *app.Component
)

PluginName is the name of the metrics collector plugin.

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.SpendDAG.SpenderAccepted.Hook(func(spendID iotago.TransactionID) {
				if txMetadata, exists := deps.Protocol.Engines.Main.Get().Ledger.MemPool().TransactionMetadata(spendID); exists {
					firstAttachmentID := txMetadata.EarliestIncludedAttachment()
					if block, blockExists := deps.Protocol.Engines.Main.Get().BlockFromCache(firstAttachmentID); blockExists {
						timeSinceIssuance := time.Since(block.IssuingTime()).Milliseconds()
						timeIssuanceSeconds := float64(timeSinceIssuance) / 1000
						deps.Collector.Update(conflictNamespace, resolutionTime, timeIssuanceSeconds)
					}
				}
			}, event.WithWorkerPool(Component.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(resolvedConflictCount,
		collector.WithType(collector.Counter),
		collector.WithHelp("Number of resolved (accepted) conflicts"),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.SpendDAG.SpenderAccepted.Hook(func(_ iotago.TransactionID) {
				deps.Collector.Increment(conflictNamespace, resolvedConflictCount)
			}, event.WithWorkerPool(Component.WorkerPool))

			deps.Protocol.Events.Engine.SpendDAG.SpenderRejected.Hook(func(_ iotago.TransactionID) {
				deps.Collector.Increment(conflictNamespace, resolvedConflictCount)
			}, event.WithWorkerPool(Component.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(allConflictCounts,
		collector.WithType(collector.Counter),
		collector.WithHelp("Number of created conflicts"),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.SpendDAG.SpenderCreated.Hook(func(_ iotago.TransactionID) {
				deps.Collector.Increment(conflictNamespace, allConflictCounts)
			}, event.WithWorkerPool(Component.WorkerPool))
		}),
	)),
)
View Source
var DBMetrics = collector.NewCollection(dbNamespace,
	collector.WithMetric(collector.NewMetric(sizeBytesPermanent,
		collector.WithType(collector.Gauge),
		collector.WithHelp("DB size in bytes for permanent storage."),
		collector.WithCollectFunc(func() (metricValue float64, labelValues []string) {
			return float64(deps.Protocol.Engines.Main.Get().Storage.PermanentDatabaseSize()), nil
		}),
	)),
	collector.WithMetric(collector.NewMetric(sizeBytesPrunable,
		collector.WithType(collector.Gauge),
		collector.WithHelp("DB size in bytes for prunable storage."),
		collector.WithCollectFunc(func() (metricValue float64, labelValues []string) {
			return float64(deps.Protocol.Engines.Main.Get().Storage.PrunableDatabaseSize()), nil
		}),
	)),
	collector.WithMetric(collector.NewMetric(sizeBytesTxRetainerDatabase,
		collector.WithType(collector.Gauge),
		collector.WithHelp("DB size in bytes for transaction retainer SQL database."),
		collector.WithCollectFunc(func() (metricValue float64, labelValues []string) {
			return float64(deps.Protocol.Engines.Main.Get().Storage.TransactionRetainerDatabaseSize()), nil
		}),
	)),
)
View Source
var InfoMetrics = collector.NewCollection(infoNamespace,
	collector.WithMetric(collector.NewMetric(nodeOS,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Node OS data."),
		collector.WithLabels("nodeID", "OS", "ARCH", "NUM_CPU"),
		collector.WithPruningDelay(10*time.Minute),
		collector.WithInitValueFunc(func() (metricValue float64, labelValues []string) {
			var nodeID string
			if deps.Host != nil {
				nodeID = deps.Host.ID().String()
			}

			return 0, []string{nodeID, runtime.GOOS, runtime.GOARCH, strconv.Itoa(runtime.NumCPU())}
		}),
	)),
	collector.WithMetric(collector.NewMetric(syncStatus,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Node sync status based on ATT."),
		collector.WithCollectFunc(func() (metricValue float64, labelValues []string) {
			if deps.Protocol.Engines.Main.Get().SyncManager.IsNodeSynced() {
				return 1, nil
			}

			return 0, nil
		}),
	)),
	collector.WithMetric(collector.NewMetric(memUsage,
		collector.WithType(collector.Gauge),
		collector.WithHelp("The memory usage in bytes of allocated heap objects"),
		collector.WithCollectFunc(func() (metricValue float64, labelValues []string) {
			var m runtime.MemStats
			runtime.ReadMemStats(&m)

			return float64(m.Alloc), nil
		}),
	)),
)
View Source
var ParamsMetrics = &ParametersMetrics{}

ParamsMetrics contains the configuration used by the metrics collector plugin.

View Source
var SchedulerMetrics = collector.NewCollection(schedulerNamespace,
	collector.WithMetric(collector.NewMetric(queueSizePerNodeWork,
		collector.WithType(collector.Gauge),
		collector.WithLabels("issuer_id"),
		collector.WithPruningDelay(10*time.Minute),
		collector.WithHelp("Current size of each node's queue (in work units)."),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Scheduler.BlockEnqueued.Hook(func(block *blocks.Block) {
				deps.Collector.Update(schedulerNamespace, queueSizePerNodeWork, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueWork(block.IssuerID())), block.IssuerID().String())

			}, event.WithWorkerPool(Component.WorkerPool))

			deps.Protocol.Events.Engine.Scheduler.BlockSkipped.Hook(func(block *blocks.Block) {
				deps.Collector.Update(schedulerNamespace, queueSizePerNodeWork, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueWork(block.IssuerID())), block.IssuerID().String())
			}, event.WithWorkerPool(Component.WorkerPool))

			deps.Protocol.Events.Engine.Scheduler.BlockDropped.Hook(func(block *blocks.Block, _ error) {
				deps.Collector.Update(schedulerNamespace, queueSizePerNodeWork, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueWork(block.IssuerID())), block.IssuerID().String())
			}, event.WithWorkerPool(Component.WorkerPool))

			deps.Protocol.Events.Engine.Scheduler.BlockScheduled.Hook(func(block *blocks.Block) {
				deps.Collector.Update(schedulerNamespace, queueSizePerNodeWork, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueWork(block.IssuerID())), block.IssuerID().String())
			}, event.WithWorkerPool(Component.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(queueSizePerNodeCount,
		collector.WithType(collector.Gauge),
		collector.WithLabels("issuer_id"),
		collector.WithPruningDelay(10*time.Minute),
		collector.WithHelp("Current size of each node's queue (as block count)."),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Scheduler.BlockEnqueued.Hook(func(block *blocks.Block) {
				if block.IsBasicBlock() {
					deps.Collector.Update(schedulerNamespace, queueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueBlockCount(block.IssuerID())), block.IssuerID().String())
				}
			}, event.WithWorkerPool(Component.WorkerPool))

			deps.Protocol.Events.Engine.Scheduler.BlockSkipped.Hook(func(block *blocks.Block) {
				if block.IsBasicBlock() {
					deps.Collector.Update(schedulerNamespace, queueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueBlockCount(block.IssuerID())), block.IssuerID().String())
				}
			}, event.WithWorkerPool(Component.WorkerPool))

			deps.Protocol.Events.Engine.Scheduler.BlockDropped.Hook(func(block *blocks.Block, _ error) {
				if block.IsBasicBlock() {
					deps.Collector.Update(schedulerNamespace, queueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueBlockCount(block.IssuerID())), block.IssuerID().String())
				}
			}, event.WithWorkerPool(Component.WorkerPool))

			deps.Protocol.Events.Engine.Scheduler.BlockScheduled.Hook(func(block *blocks.Block) {
				if block.IsBasicBlock() {
					deps.Collector.Update(schedulerNamespace, queueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueBlockCount(block.IssuerID())), block.IssuerID().String())
				}
			}, event.WithWorkerPool(Component.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(validatorQueueSizePerNodeCount,
		collector.WithType(collector.Gauge),
		collector.WithLabels("issuer_id"),
		collector.WithPruningDelay(10*time.Minute),
		collector.WithHelp("Current number of validation blocks in each validator's queue."),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Scheduler.BlockEnqueued.Hook(func(block *blocks.Block) {
				if block.IsValidationBlock() {
					deps.Collector.Update(schedulerNamespace, validatorQueueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.ValidatorQueueBlockCount(block.IssuerID())), block.IssuerID().String())
				}
			}, event.WithWorkerPool(Component.WorkerPool))

			deps.Protocol.Events.Engine.Scheduler.BlockSkipped.Hook(func(block *blocks.Block) {
				if block.IsValidationBlock() {
					deps.Collector.Update(schedulerNamespace, validatorQueueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.ValidatorQueueBlockCount(block.IssuerID())), block.IssuerID().String())
				}
			}, event.WithWorkerPool(Component.WorkerPool))

			deps.Protocol.Events.Engine.Scheduler.BlockDropped.Hook(func(block *blocks.Block, _ error) {
				if block.IsValidationBlock() {
					deps.Collector.Update(schedulerNamespace, validatorQueueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.ValidatorQueueBlockCount(block.IssuerID())), block.IssuerID().String())
				}
			}, event.WithWorkerPool(Component.WorkerPool))

			deps.Protocol.Events.Engine.Scheduler.BlockScheduled.Hook(func(block *blocks.Block) {
				if block.IsValidationBlock() {
					deps.Collector.Update(schedulerNamespace, validatorQueueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.ValidatorQueueBlockCount(block.IssuerID())), block.IssuerID().String())
				}
			}, event.WithWorkerPool(Component.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(schedulerProcessedBlocks,
		collector.WithType(collector.Counter),
		collector.WithLabels("state"),
		collector.WithHelp("Number of blocks processed by the scheduler."),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Scheduler.BlockEnqueued.Hook(func(_ *blocks.Block) {
				deps.Collector.Increment(schedulerNamespace, schedulerProcessedBlocks, enqueuedBlockLabel)
			}, event.WithWorkerPool(Component.WorkerPool))

			deps.Protocol.Events.Engine.Scheduler.BlockDropped.Hook(func(_ *blocks.Block, _ error) {
				deps.Collector.Increment(schedulerNamespace, schedulerProcessedBlocks, droppedBlockLabel)
			}, event.WithWorkerPool(Component.WorkerPool))

			deps.Protocol.Events.Engine.Scheduler.BlockSkipped.Hook(func(_ *blocks.Block) {
				deps.Collector.Increment(schedulerNamespace, schedulerProcessedBlocks, skippedBlockLabel)
			}, event.WithWorkerPool(Component.WorkerPool))

			deps.Protocol.Events.Engine.Scheduler.BlockScheduled.Hook(func(_ *blocks.Block) {
				deps.Collector.Increment(schedulerNamespace, schedulerProcessedBlocks, scheduledBlockLabel)
			}, event.WithWorkerPool(Component.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(basicBufferMaxSize,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Maximum number of basic blocks that can be stored in the buffer."),
		collector.WithCollectFunc(func() (float64, []string) {
			return float64(deps.Protocol.Engines.Main.Get().CommittedAPI().ProtocolParameters().CongestionControlParameters().MaxBufferSize), []string{}
		}),
	)),
	collector.WithMetric(collector.NewMetric(basicBufferReadyBlockCount,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Number of ready blocks in the scheduler buffer."),
		collector.WithCollectFunc(func() (float64, []string) {
			return float64(deps.Protocol.Engines.Main.Get().Scheduler.ReadyBlocksCount()), []string{}
		}),
	)),
	collector.WithMetric(collector.NewMetric(basicBufferTotalSize,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Current number of basic blocks in the scheduler buffer."),
		collector.WithCollectFunc(func() (float64, []string) {
			return float64(deps.Protocol.Engines.Main.Get().Scheduler.BasicBufferSize()), []string{}
		}),
	)),
	collector.WithMetric(collector.NewMetric(rate,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Current scheduling rate of basic blocks."),
		collector.WithCollectFunc(func() (float64, []string) {
			return float64(deps.Protocol.Engines.Main.Get().CommittedAPI().ProtocolParameters().CongestionControlParameters().SchedulerRate), []string{}
		}),
	)),
	collector.WithMetric(collector.NewMetric(validatorBufferTotalSize,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Current number of validation blocks in the scheduling buffer."),
		collector.WithCollectFunc(func() (float64, []string) {
			return float64(deps.Protocol.Engines.Main.Get().Scheduler.ValidatorBufferSize()), []string{}
		}),
	)),
	collector.WithMetric(collector.NewMetric(validatorQueueMaxSize,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Maximum number of validation blocks that can be stored in each validator queue."),
		collector.WithCollectFunc(func() (float64, []string) {
			return float64(deps.Protocol.Engines.Main.Get().CommittedAPI().ProtocolParameters().CongestionControlParameters().MaxValidationBufferSize), []string{}
		}),
	)),
)
View Source
var SlotMetrics = collector.NewCollection(slotNamespace,
	collector.WithMetric(collector.NewMetric(totalBlocks,
		collector.WithType(collector.Counter),
		collector.WithLabels(slotLabelName),
		collector.WithPruningDelay(10*time.Minute),
		collector.WithHelp("Number of blocks seen by the node in a slot."),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.PostSolidFilter.BlockAllowed.Hook(func(block *blocks.Block) {
				eventSlot := int(block.ID().Slot())
				deps.Collector.Increment(slotNamespace, totalBlocks, strconv.Itoa(eventSlot))
			}, event.WithWorkerPool(Component.WorkerPool))
		}),
	)),

	collector.WithMetric(collector.NewMetric(acceptedBlocksInSlot,
		collector.WithType(collector.Counter),
		collector.WithHelp("Number of accepted blocks in a slot."),
		collector.WithLabels(slotLabelName),
		collector.WithPruningDelay(10*time.Minute),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.BlockGadget.BlockAccepted.Hook(func(block *blocks.Block) {
				eventSlot := int(block.ID().Slot())
				deps.Collector.Increment(slotNamespace, acceptedBlocksInSlot, strconv.Itoa(eventSlot))
			}, event.WithWorkerPool(Component.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(invalidBlocks,
		collector.WithType(collector.Counter),
		collector.WithLabels(slotLabelName),
		collector.WithPruningDelay(10*time.Minute),
		collector.WithHelp("Number of invalid blocks in a slot."),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.BlockDAG.BlockInvalid.Hook(func(block *blocks.Block, _ error) {
				eventSlot := int(block.ID().Slot())
				deps.Collector.Increment(slotNamespace, invalidBlocks, strconv.Itoa(eventSlot))
			}, event.WithWorkerPool(Component.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(acceptedAttachments,
		collector.WithType(collector.Counter),
		collector.WithLabels(slotLabelName),
		collector.WithPruningDelay(10*time.Minute),
		collector.WithHelp("Number of accepted attachments by the node per slot."),
		collector.WithInitFunc(func() {
			deps.Protocol.Engines.Main.Get().Ledger.OnTransactionAttached(func(transactionMetadata mempool.TransactionMetadata) {
				transactionMetadata.OnAccepted(func() {
					for _, attachmentBlockID := range transactionMetadata.ValidAttachments() {
						if block, exists := deps.Protocol.Engines.Main.Get().BlockCache.Block(attachmentBlockID); exists && block.IsAccepted() {
							deps.Collector.Increment(slotNamespace, acceptedAttachments, strconv.Itoa(int(attachmentBlockID.Slot())))
						}
					}
				})
			})
		}),
	)),
	collector.WithMetric(collector.NewMetric(createdConflicts,
		collector.WithType(collector.Counter),
		collector.WithLabels(slotLabelName),
		collector.WithPruningDelay(10*time.Minute),
		collector.WithHelp("Number of conflicts created per slot."),
		collector.WithInitFunc(func() {

			deps.Protocol.Events.Engine.Booker.BlockBooked.Hook(func(block *blocks.Block) {
				eventSlot := int(block.ID().Slot())
				deps.Collector.Update(slotNamespace, createdConflicts, 0, strconv.Itoa(eventSlot))
			}, event.WithWorkerPool(Component.WorkerPool))

			deps.Protocol.Events.Engine.SpendDAG.SpenderCreated.Hook(func(spendID iotago.TransactionID) {
				if txMetadata, exists := deps.Protocol.Engines.Main.Get().Ledger.TransactionMetadata(spendID); exists {
					for _, attachment := range txMetadata.ValidAttachments() {
						deps.Collector.Increment(slotNamespace, createdConflicts, strconv.Itoa(int(attachment.Slot())))
					}
				}
			}, event.WithWorkerPool(Component.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(acceptedConflicts,
		collector.WithType(collector.Counter),
		collector.WithLabels(slotLabelName),
		collector.WithPruningDelay(10*time.Minute),
		collector.WithHelp("Number of conflicts accepted per slot."),
		collector.WithInitFunc(func() {

			deps.Protocol.Events.Engine.Booker.BlockBooked.Hook(func(block *blocks.Block) {
				eventSlot := int(block.ID().Slot())
				deps.Collector.Update(slotNamespace, acceptedConflicts, 0, strconv.Itoa(eventSlot))
			}, event.WithWorkerPool(Component.WorkerPool))

			deps.Protocol.Events.Engine.SpendDAG.SpenderAccepted.Hook(func(spendID iotago.TransactionID) {
				if txMetadata, exists := deps.Protocol.Engines.Main.Get().Ledger.TransactionMetadata(spendID); exists {
					for _, attachmentBlockID := range txMetadata.ValidAttachments() {
						if attachment, exists := deps.Protocol.Engines.Main.Get().BlockCache.Block(attachmentBlockID); exists && attachment.IsAccepted() {
							deps.Collector.Increment(slotNamespace, acceptedConflicts, strconv.Itoa(int(attachment.ID().Slot())))
						}
					}
				}
			}, event.WithWorkerPool(Component.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(rejectedConflicts,
		collector.WithType(collector.Counter),
		collector.WithLabels(slotLabelName),
		collector.WithPruningDelay(10*time.Minute),
		collector.WithHelp("Number of conflicts rejected per slot."),
		collector.WithInitFunc(func() {

			deps.Protocol.Events.Engine.Booker.BlockBooked.Hook(func(block *blocks.Block) {
				eventSlot := int(block.ID().Slot())
				deps.Collector.Update(slotNamespace, rejectedConflicts, 0, strconv.Itoa(eventSlot))
			}, event.WithWorkerPool(Component.WorkerPool))

			deps.Protocol.Events.Engine.SpendDAG.SpenderRejected.Hook(func(spendID iotago.TransactionID) {
				if txMetadata, exists := deps.Protocol.Engines.Main.Get().Ledger.TransactionMetadata(spendID); exists {
					for _, attachmentBlockID := range txMetadata.ValidAttachments() {
						if attachment, exists := deps.Protocol.Engines.Main.Get().BlockCache.Block(attachmentBlockID); exists && attachment.IsAccepted() {
							deps.Collector.Increment(slotNamespace, rejectedConflicts, strconv.Itoa(int(attachment.ID().Slot())))
						}
					}
				}
			}, event.WithWorkerPool(Component.WorkerPool))
		}),
	)),
)
View Source
var TangleMetrics = collector.NewCollection(tangleNamespace,
	collector.WithMetric(collector.NewMetric(strongTipsCount,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Number of strong tips in the tangle"),
		collector.WithCollectFunc(func() (metricValue float64, labelValues []string) {
			count := len(deps.Protocol.Engines.Main.Get().TipManager.StrongTips())

			return float64(count), nil
		}),
	)),
	collector.WithMetric(collector.NewMetric(weakTipsCount,
		collector.WithType(collector.Gauge),
		collector.WithHelp("Number of weak tips in the tangle"),
		collector.WithCollectFunc(func() (metricValue float64, labelValues []string) {
			count := len(deps.Protocol.Engines.Main.Get().TipManager.WeakTips())

			return float64(count), nil
		}),
	)),
	collector.WithMetric(collector.NewMetric(bookedBlocksTotal,
		collector.WithType(collector.Counter),
		collector.WithHelp("Total number of blocks booked."),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.Booker.BlockBooked.Hook(func(_ *blocks.Block) {
				deps.Collector.Increment(tangleNamespace, bookedBlocksTotal)
			}, event.WithWorkerPool(Component.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(missingBlocksCount,
		collector.WithType(collector.Counter),
		collector.WithHelp("Number of blocks missing during the solidification in the tangle"),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.BlockDAG.BlockMissing.Hook(func(_ *blocks.Block) {
				deps.Collector.Increment(tangleNamespace, missingBlocksCount)
			}, event.WithWorkerPool(Component.WorkerPool))
		}),
	)),
	collector.WithMetric(collector.NewMetric(acceptedBlocksCount,
		collector.WithType(collector.Counter),
		collector.WithHelp("Number of accepted blocks"),
		collector.WithInitFunc(func() {
			deps.Protocol.Events.Engine.BlockGadget.BlockAccepted.Hook(func(_ *blocks.Block) {
				deps.Collector.Increment(tangleNamespace, acceptedBlocksCount)
			}, event.WithWorkerPool(Component.WorkerPool))
		}),
	)),
)

Functions

This section is empty.

Types

type ParametersMetrics

type ParametersMetrics struct {
	// Enabled defines whether the Metrics component is enabled.
	Enabled bool `default:"true" usage:"whether the Metrics component is enabled"`
	// 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"`
}

ParametersMetrics contains the definition of the parameters used by the metrics component.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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