Skip to content

Commit

Permalink
Metrics for total gas used for eth_call and total gas used for eth_es…
Browse files Browse the repository at this point in the history
…timateGas
  • Loading branch information
amsanghi committed Jul 9, 2024
1 parent 71b0d6b commit 757508b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/ethereum/go-ethereum/eth/gasestimator"
"github.com/ethereum/go-ethereum/eth/tracers/logger"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
Expand All @@ -52,6 +53,10 @@ import (
)

var errBlobTxNotSupported = errors.New("signing blob transactions not supported")
var (
gasUsedEthEstimateGasGauge = metrics.NewRegisteredGauge("api/eth_call/gas", nil)
gasUsedEthCallGauge = metrics.NewRegisteredGauge("api/eth_estimateGas/gas", nil)
)

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

Expand Down Expand Up @@ -1316,6 +1322,9 @@ func (s *BlockChainAPI) EstimateGas(ctx context.Context, args TransactionArgs, b
err := client.CallContext(ctx, &res, "eth_estimateGas", args, blockNrOrHash, overrides)
return res, err
}
if err != nil {
gasUsedEthEstimateGasGauge.Inc(int64(res))
}
return res, err
}

Expand Down

0 comments on commit 757508b

Please sign in to comment.