From da83b7e3921f8094fe61e62248dcf14b36c47b3c Mon Sep 17 00:00:00 2001 From: TanayK07 Date: Mon, 2 Mar 2026 21:28:34 +0530 Subject: [PATCH] internal/ethapi: add gas usage metric for eth_call Add a Prometheus histogram metric (rpc/gas_used/eth_call) that tracks the gas consumed by eth_call requests. This helps RPC providers monitor node capacity and correlate CPU usage with actual EVM computation load. The metric is recorded after successful execution, including reverted calls, since they still consume gas. Fixes #32774 --- internal/ethapi/api.go | 1 + internal/ethapi/metrics.go | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 internal/ethapi/metrics.go diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 41d165a423..075abcd83f 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -822,6 +822,7 @@ func (api *BlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockN if err != nil { return nil, err } + ethCallGasUsedHist.Update(int64(result.UsedGas)) if errors.Is(result.Err, vm.ErrExecutionReverted) { return nil, newRevertError(result.Revert()) } diff --git a/internal/ethapi/metrics.go b/internal/ethapi/metrics.go new file mode 100644 index 0000000000..ae57a17b3a --- /dev/null +++ b/internal/ethapi/metrics.go @@ -0,0 +1,7 @@ +package ethapi + +import "github.com/ethereum/go-ethereum/metrics" + +var ( + ethCallGasUsedHist = metrics.NewRegisteredHistogram("rpc/gas_used/eth_call", nil, metrics.NewExpDecaySample(1028, 0.015)) +)