Skip to content

Commit 64d5c61

Browse files
Merge pull request #335 from OffchainLabs/metrics
[NIT-1168] Metrics for total gas used for eth_call and total gas used for eth_estimateGas
2 parents e52de0a + c186780 commit 64d5c61

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

internal/ethapi/api.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
"github.com/ethereum/go-ethereum/eth/gasestimator"
4343
"github.com/ethereum/go-ethereum/eth/tracers/logger"
4444
"github.com/ethereum/go-ethereum/log"
45+
"github.com/ethereum/go-ethereum/metrics"
4546
"github.com/ethereum/go-ethereum/p2p"
4647
"github.com/ethereum/go-ethereum/params"
4748
"github.com/ethereum/go-ethereum/rlp"
@@ -52,6 +53,10 @@ import (
5253
)
5354

5455
var errBlobTxNotSupported = errors.New("signing blob transactions not supported")
56+
var (
57+
gasUsedEthEstimateGasGauge = metrics.NewRegisteredCounter("rpc/gas_used/eth_estimategas", nil)
58+
gasUsedEthCallGauge = metrics.NewRegisteredCounter("rpc/gas_used/eth_call", nil)
59+
)
5560

5661
func fallbackClientFor(b Backend, err error) types.FallbackClient {
5762
if !errors.Is(err, types.ErrUseFallback) {
@@ -1242,6 +1247,7 @@ func (s *BlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrO
12421247
if len(result.Revert()) > 0 {
12431248
return nil, newRevertError(result.Revert())
12441249
}
1250+
gasUsedEthCallGauge.Inc(int64(result.UsedGas))
12451251
return result.Return(), result.Err
12461252
}
12471253

@@ -1312,6 +1318,9 @@ func (s *BlockChainAPI) EstimateGas(ctx context.Context, args TransactionArgs, b
13121318
err := client.CallContext(ctx, &res, "eth_estimateGas", args, blockNrOrHash, overrides)
13131319
return res, err
13141320
}
1321+
if err != nil {
1322+
gasUsedEthEstimateGasGauge.Inc(int64(res))
1323+
}
13151324
return res, err
13161325
}
13171326

0 commit comments

Comments
 (0)