mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-06 19:06:42 +01:00
Add Prometheus initial setup
This commit is contained in:
53
txselector/metrics.go
Normal file
53
txselector/metrics.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package txselector
|
||||
|
||||
import "github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
var (
|
||||
metricGetL2TxSelection = prometheus.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Name: "txsel_get_l2_txselecton_total",
|
||||
Help: "",
|
||||
},
|
||||
)
|
||||
metricGetL1L2TxSelection = prometheus.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Name: "txsel_get_l1_l2_txselecton_total",
|
||||
Help: "",
|
||||
},
|
||||
)
|
||||
|
||||
metricSelectedL1CoordinatorTxs = prometheus.NewGauge(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "txsel_selected_l1_coordinator_txs",
|
||||
Help: "",
|
||||
},
|
||||
)
|
||||
metricSelectedL1UserTxs = prometheus.NewGauge(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "txsel_selected_l1_user_txs",
|
||||
Help: "",
|
||||
},
|
||||
)
|
||||
metricSelectedL2Txs = prometheus.NewGauge(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "txsel_selected_l2_txs",
|
||||
Help: "",
|
||||
},
|
||||
)
|
||||
metricDiscardedL2Txs = prometheus.NewGauge(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "txsel_discarded_l2_txs",
|
||||
Help: "",
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
func init() {
|
||||
prometheus.MustRegister(metricGetL2TxSelection)
|
||||
prometheus.MustRegister(metricGetL1L2TxSelection)
|
||||
|
||||
prometheus.MustRegister(metricSelectedL1CoordinatorTxs)
|
||||
prometheus.MustRegister(metricSelectedL1UserTxs)
|
||||
prometheus.MustRegister(metricSelectedL2Txs)
|
||||
prometheus.MustRegister(metricDiscardedL2Txs)
|
||||
}
|
||||
@@ -133,9 +133,11 @@ func (txsel *TxSelector) coordAccountForTokenID(l1CoordinatorTxs []common.L1Tx,
|
||||
// included in the next batch.
|
||||
func (txsel *TxSelector) GetL2TxSelection(selectionConfig *SelectionConfig) ([]common.Idx,
|
||||
[][]byte, []common.L1Tx, []common.PoolL2Tx, []common.PoolL2Tx, error) {
|
||||
coordIdxs, accCreationAuths, _, l1CoordinatorTxs, l2Txs, discardedL2Txs, err :=
|
||||
txsel.GetL1L2TxSelection(selectionConfig, []common.L1Tx{})
|
||||
return coordIdxs, accCreationAuths, l1CoordinatorTxs, l2Txs, discardedL2Txs, tracerr.Wrap(err)
|
||||
metricGetL2TxSelection.Inc()
|
||||
coordIdxs, accCreationAuths, _, l1CoordinatorTxs, l2Txs,
|
||||
discardedL2Txs, err := txsel.getL1L2TxSelection(selectionConfig, []common.L1Tx{})
|
||||
return coordIdxs, accCreationAuths, l1CoordinatorTxs, l2Txs,
|
||||
discardedL2Txs, tracerr.Wrap(err)
|
||||
}
|
||||
|
||||
// GetL1L2TxSelection returns the selection of L1 + L2 txs.
|
||||
@@ -147,6 +149,16 @@ func (txsel *TxSelector) GetL2TxSelection(selectionConfig *SelectionConfig) ([]c
|
||||
// creation exists. The L1UserTxs, L1CoordinatorTxs, PoolL2Txs that will be
|
||||
// included in the next batch.
|
||||
func (txsel *TxSelector) GetL1L2TxSelection(selectionConfig *SelectionConfig,
|
||||
l1UserTxs []common.L1Tx) ([]common.Idx, [][]byte, []common.L1Tx,
|
||||
[]common.L1Tx, []common.PoolL2Tx, []common.PoolL2Tx, error) {
|
||||
metricGetL1L2TxSelection.Inc()
|
||||
coordIdxs, accCreationAuths, l1UserTxs, l1CoordinatorTxs, l2Txs,
|
||||
discardedL2Txs, err := txsel.getL1L2TxSelection(selectionConfig, l1UserTxs)
|
||||
return coordIdxs, accCreationAuths, l1UserTxs, l1CoordinatorTxs, l2Txs,
|
||||
discardedL2Txs, tracerr.Wrap(err)
|
||||
}
|
||||
|
||||
func (txsel *TxSelector) getL1L2TxSelection(selectionConfig *SelectionConfig,
|
||||
l1UserTxs []common.L1Tx) ([]common.Idx, [][]byte, []common.L1Tx,
|
||||
[]common.L1Tx, []common.PoolL2Tx, []common.PoolL2Tx, error) {
|
||||
// WIP.0: the TxSelector is not optimized and will need a redesign. The
|
||||
@@ -452,6 +464,11 @@ func (txsel *TxSelector) GetL1L2TxSelection(selectionConfig *SelectionConfig,
|
||||
return nil, nil, nil, nil, nil, nil, tracerr.Wrap(err)
|
||||
}
|
||||
|
||||
metricSelectedL1CoordinatorTxs.Set(float64(len(l1CoordinatorTxs)))
|
||||
metricSelectedL1UserTxs.Set(float64(len(l1UserTxs)))
|
||||
metricSelectedL2Txs.Set(float64(len(finalL2Txs)))
|
||||
metricDiscardedL2Txs.Set(float64(len(discardedL2Txs)))
|
||||
|
||||
return coordIdxs, accAuths, l1UserTxs, l1CoordinatorTxs, finalL2Txs, discardedL2Txs, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user