Add metrics to DefaultBlockchain to get TPS and Mgas/s (#7105)

* Add gasUsedCounter and numberOfTransactionsCounter counters to DefaultBlockchain

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

* Make the attributes final

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

* Spotless

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

* Add a changelog entry

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

---------

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
pull/7172/head
ahamlat 6 months ago committed by GitHub
parent 64de9f2eda
commit b0823c41fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 19
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchain.java

@ -5,6 +5,7 @@
### Breaking Changes
### Additions and Improvements
- Add two counters to DefaultBlockchain in order to be able to calculate TPS and Mgas/s [#7105](https://github.com/hyperledger/besu/pull/7105)
### Bug fixes
- Make `eth_gasPrice` aware of the base fee market [#7102](https://github.com/hyperledger/besu/pull/7102)

@ -33,6 +33,7 @@ import org.hyperledger.besu.ethereum.core.TransactionReceipt;
import org.hyperledger.besu.metrics.BesuMetricCategory;
import org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.metrics.Counter;
import org.hyperledger.besu.util.InvalidConfigurationException;
import org.hyperledger.besu.util.Subscribers;
@ -83,6 +84,9 @@ public class DefaultBlockchain implements MutableBlockchain {
private final Optional<Cache<Hash, List<TransactionReceipt>>> transactionReceiptsCache;
private final Optional<Cache<Hash, Difficulty>> totalDifficultyCache;
private final Counter gasUsedCounter;
private final Counter numberOfTransactionsCounter;
private DefaultBlockchain(
final Optional<Block> genesisBlock,
final BlockchainStorage blockchainStorage,
@ -117,6 +121,7 @@ public class DefaultBlockchain implements MutableBlockchain {
"blockchain_height",
"The current height of the canonical chain",
this::getChainHeadBlockNumber);
metricsSystem.createGauge(
BesuMetricCategory.BLOCKCHAIN,
"difficulty_total",
@ -135,6 +140,10 @@ public class DefaultBlockchain implements MutableBlockchain {
"Gas used by the current chain head block",
() -> getChainHeadHeader().getGasUsed());
gasUsedCounter =
metricsSystem.createCounter(
BesuMetricCategory.BLOCKCHAIN, "chain_head_gas_used_counter", "Counter for Gas used");
metricsSystem.createLongGauge(
BesuMetricCategory.BLOCKCHAIN,
"chain_head_gas_limit",
@ -147,6 +156,12 @@ public class DefaultBlockchain implements MutableBlockchain {
"Number of transactions in the current chain head block",
() -> chainHeadTransactionCount);
numberOfTransactionsCounter =
metricsSystem.createCounter(
BesuMetricCategory.BLOCKCHAIN,
"chain_head_transaction_count_counter",
"Counter for the number of transactions");
metricsSystem.createIntegerGauge(
BesuMetricCategory.BLOCKCHAIN,
"chain_head_ommer_count",
@ -524,6 +539,10 @@ public class DefaultBlockchain implements MutableBlockchain {
updater.setChainHead(newBlockHash);
indexTransactionForBlock(
updater, newBlockHash, blockWithReceipts.getBlock().getBody().getTransactions());
gasUsedCounter.inc(blockWithReceipts.getHeader().getGasUsed());
numberOfTransactionsCounter.inc(
blockWithReceipts.getBlock().getBody().getTransactions().size());
return BlockAddedEvent.createForHeadAdvancement(
blockWithReceipts.getBlock(),
LogWithMetadata.generate(

Loading…
Cancel
Save