@ -31,6 +31,7 @@ import org.hyperledger.besu.ethereum.core.LogWithMetadata;
import org.hyperledger.besu.ethereum.core.Transaction ;
import org.hyperledger.besu.ethereum.core.Transaction ;
import org.hyperledger.besu.ethereum.core.TransactionReceipt ;
import org.hyperledger.besu.ethereum.core.TransactionReceipt ;
import org.hyperledger.besu.metrics.BesuMetricCategory ;
import org.hyperledger.besu.metrics.BesuMetricCategory ;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem ;
import org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem ;
import org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem ;
import org.hyperledger.besu.plugin.services.MetricsSystem ;
import org.hyperledger.besu.plugin.services.MetricsSystem ;
import org.hyperledger.besu.plugin.services.metrics.Counter ;
import org.hyperledger.besu.plugin.services.metrics.Counter ;
@ -84,8 +85,8 @@ public class DefaultBlockchain implements MutableBlockchain {
private final Optional < Cache < Hash , List < TransactionReceipt > > > transactionReceiptsCache ;
private final Optional < Cache < Hash , List < TransactionReceipt > > > transactionReceiptsCache ;
private final Optional < Cache < Hash , Difficulty > > totalDifficultyCache ;
private final Optional < Cache < Hash , Difficulty > > totalDifficultyCache ;
private final Counter gasUsedCounter ;
private Counter gasUsedCounter = NoOpMetricsSystem . NO_OP_COUNTER ;
private final Counter numberOfTransactionsCounter ;
private Counter numberOfTransactionsCounter = NoOpMetricsSystem . NO_OP_COUNTER ;
private DefaultBlockchain (
private DefaultBlockchain (
final Optional < Block > genesisBlock ,
final Optional < Block > genesisBlock ,
@ -147,6 +148,23 @@ public class DefaultBlockchain implements MutableBlockchain {
totalDifficultyCache = Optional . empty ( ) ;
totalDifficultyCache = Optional . empty ( ) ;
}
}
createCounters ( metricsSystem ) ;
createGauges ( metricsSystem ) ;
}
private void createCounters ( final MetricsSystem metricsSystem ) {
gasUsedCounter =
metricsSystem . createCounter (
BesuMetricCategory . BLOCKCHAIN , "chain_head_gas_used_counter" , "Counter for Gas used" ) ;
numberOfTransactionsCounter =
metricsSystem . createCounter (
BesuMetricCategory . BLOCKCHAIN ,
"chain_head_transaction_count_counter" ,
"Counter for the number of transactions" ) ;
}
private void createGauges ( final MetricsSystem metricsSystem ) {
metricsSystem . createLongGauge (
metricsSystem . createLongGauge (
BesuMetricCategory . ETHEREUM ,
BesuMetricCategory . ETHEREUM ,
"blockchain_height" ,
"blockchain_height" ,
@ -183,10 +201,6 @@ public class DefaultBlockchain implements MutableBlockchain {
"Gas used by the current chain head block" ,
"Gas used by the current chain head block" ,
( ) - > getChainHeadHeader ( ) . getGasUsed ( ) ) ;
( ) - > getChainHeadHeader ( ) . getGasUsed ( ) ) ;
gasUsedCounter =
metricsSystem . createCounter (
BesuMetricCategory . BLOCKCHAIN , "chain_head_gas_used_counter" , "Counter for Gas used" ) ;
metricsSystem . createLongGauge (
metricsSystem . createLongGauge (
BesuMetricCategory . BLOCKCHAIN ,
BesuMetricCategory . BLOCKCHAIN ,
"chain_head_gas_limit" ,
"chain_head_gas_limit" ,
@ -199,12 +213,6 @@ public class DefaultBlockchain implements MutableBlockchain {
"Number of transactions in the current chain head block" ,
"Number of transactions in the current chain head block" ,
( ) - > chainHeadTransactionCount ) ;
( ) - > chainHeadTransactionCount ) ;
numberOfTransactionsCounter =
metricsSystem . createCounter (
BesuMetricCategory . BLOCKCHAIN ,
"chain_head_transaction_count_counter" ,
"Counter for the number of transactions" ) ;
metricsSystem . createIntegerGauge (
metricsSystem . createIntegerGauge (
BesuMetricCategory . BLOCKCHAIN ,
BesuMetricCategory . BLOCKCHAIN ,
"chain_head_ommer_count" ,
"chain_head_ommer_count" ,