diff --git a/jsonrpc/dynamic_gas_price_xlayer.go b/jsonrpc/dynamic_gas_price_xlayer.go index 837059af35..fc8aec9066 100644 --- a/jsonrpc/dynamic_gas_price_xlayer.go +++ b/jsonrpc/dynamic_gas_price_xlayer.go @@ -8,6 +8,7 @@ import ( "time" zktypes "github.com/0xPolygonHermez/zkevm-node/config/types" + "github.com/0xPolygonHermez/zkevm-node/jsonrpc/metrics" "github.com/0xPolygonHermez/zkevm-node/log" "github.com/ethereum/go-ethereum/core/types" ) @@ -168,6 +169,7 @@ func (e *EthEndpoints) calcDynamicGP(ctx context.Context) { e.dgpMan.cacheLock.Lock() e.dgpMan.lastPrice = getAvgPrice(rawGP, price) e.dgpMan.lastL2BatchNumber = l2BatchNumber + metrics.DynamicGasPrice(e.dgpMan.lastPrice.Int64()) e.dgpMan.cacheLock.Unlock() return } @@ -175,6 +177,7 @@ func (e *EthEndpoints) calcDynamicGP(ctx context.Context) { e.dgpMan.cacheLock.Lock() e.dgpMan.lastPrice = price e.dgpMan.lastL2BatchNumber = l2BatchNumber + metrics.DynamicGasPrice(e.dgpMan.lastPrice.Int64()) e.dgpMan.cacheLock.Unlock() } diff --git a/jsonrpc/metrics/metrics.go b/jsonrpc/metrics/metrics.go index f2304d136c..13df5098f6 100644 --- a/jsonrpc/metrics/metrics.go +++ b/jsonrpc/metrics/metrics.go @@ -75,6 +75,7 @@ func Register() { // XLayer handler metrics.RegisterCounterVecs(counterVecsXLayer...) metrics.RegisterHistogramVecs(histogramVecs...) + metrics.RegisterGaugeVecs(gaugeVecs...) } // CountConn increments the connection counter vector by one for the diff --git a/jsonrpc/metrics/metrics_xlayer.go b/jsonrpc/metrics/metrics_xlayer.go index bf87391ec4..9e910f2263 100644 --- a/jsonrpc/metrics/metrics_xlayer.go +++ b/jsonrpc/metrics/metrics_xlayer.go @@ -19,9 +19,23 @@ var ( requestWsMethodDurationName = wsRequestPrefix + "method_duration" requestMethodLabelName = "method" - start = 0.1 - width = 0.1 - count = 10 + start = 0.1 + width = 0.1 + count = 10 + + lastDynamicGasPriceName = prefix + "dynamic_gas_price" + lastBatchNumberLabelName = "batch_number" + + gaugeVecs = []metrics.GaugeVecOpts{ + { + GaugeOpts: prometheus.GaugeOpts{ + Name: lastDynamicGasPriceName, + Help: "[JSONRPC] dynamic gas price", + }, + Labels: []string{lastBatchNumberLabelName}, + }, + } + histogramVecs = []metrics.HistogramVecOpts{ { HistogramOpts: prometheus.HistogramOpts{ @@ -117,3 +131,8 @@ func RequestInnerTxCachedCount() { func RequestInnerTxAddErrorCount() { metrics.CounterVecInc(requestInnerTxAddErrorCount, "add_error") } + +// DynamicGasPrice sets the gauge vector to the given batch number and dynamic gas price. +func DynamicGasPrice(dgp int64) { + metrics.GaugeVecSet(lastDynamicGasPriceName, "inf", float64(dgp)) +}