-
Notifications
You must be signed in to change notification settings - Fork 659
/
tx_heap_metrics.go
51 lines (41 loc) · 1.04 KB
/
tx_heap_metrics.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
// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package platformvm
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/ava-labs/avalanchego/ids"
)
var _ TxHeap = &txHeapWithMetrics{}
type txHeapWithMetrics struct {
TxHeap
numTxs prometheus.Gauge
}
func NewTxHeapWithMetrics(
txHeap TxHeap,
namespace string,
registerer prometheus.Registerer,
) (TxHeap, error) {
h := &txHeapWithMetrics{
TxHeap: txHeap,
numTxs: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "count",
Help: "Number of transactions in the heap",
}),
}
return h, registerer.Register(h.numTxs)
}
func (h *txHeapWithMetrics) Add(tx *Tx) {
h.TxHeap.Add(tx)
h.numTxs.Set(float64(h.TxHeap.Len()))
}
func (h *txHeapWithMetrics) Remove(txID ids.ID) *Tx {
tx := h.TxHeap.Remove(txID)
h.numTxs.Set(float64(h.TxHeap.Len()))
return tx
}
func (h *txHeapWithMetrics) RemoveTop() *Tx {
tx := h.TxHeap.RemoveTop()
h.numTxs.Set(float64(h.TxHeap.Len()))
return tx
}