Skip to content

Commit

Permalink
add dynamic gas price metrics (#177)
Browse files Browse the repository at this point in the history
* add DGP metrics

* fix bug

* fix lint

* Update metrics_xlayer.go
  • Loading branch information
LeoGuo621 authored Apr 23, 2024
1 parent 3e9baae commit 9cc0766
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
3 changes: 3 additions & 0 deletions jsonrpc/dynamic_gas_price_xlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -168,13 +169,15 @@ 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
}

e.dgpMan.cacheLock.Lock()
e.dgpMan.lastPrice = price
e.dgpMan.lastL2BatchNumber = l2BatchNumber
metrics.DynamicGasPrice(e.dgpMan.lastPrice.Int64())
e.dgpMan.cacheLock.Unlock()
}

Expand Down
1 change: 1 addition & 0 deletions jsonrpc/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 22 additions & 3 deletions jsonrpc/metrics/metrics_xlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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))
}

0 comments on commit 9cc0766

Please sign in to comment.