-
Notifications
You must be signed in to change notification settings - Fork 12
/
metrics_slots.go
151 lines (143 loc) · 7 KB
/
metrics_slots.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package prometheus
import (
"strconv"
"time"
"github.com/iotaledger/hive.go/runtime/event"
"github.com/iotaledger/iota-core/components/prometheus/collector"
"github.com/iotaledger/iota-core/pkg/protocol/engine/blocks"
"github.com/iotaledger/iota-core/pkg/protocol/engine/mempool"
iotago "github.com/iotaledger/iota.go/v4"
)
const (
slotNamespace = "slots"
slotLabelName = "slot"
totalBlocks = "total_blocks"
acceptedBlocksInSlot = "accepted_blocks"
invalidBlocks = "invalid_blocks"
acceptedAttachments = "accepted_attachments"
createdConflicts = "created_conflicts"
acceptedConflicts = "accepted_conflicts"
rejectedConflicts = "rejected_conflicts"
)
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() {
// Hook to BlockBooked to initialize metric for the slot for improved readability in the Dashboard.
// Update for a counter doesn't override the value with 0, but rather adds 0 to the value.
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() {
// Hook to BlockBooked to initialize metric for the slot for improved readability in the Dashboard.
// Update for a counter doesn't override the value with 0, but rather adds 0 to the value.
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() {
// Hook to BlockBooked to initialize metric for the slot for improved readability in the Dashboard.
// Update for a counter doesn't override the value with 0, but rather adds 0 to the value.
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))
}),
)),
)