Add metrics to assist monitoring and alerting (#1506)

Adds metrics to expose:
 * height of best known block
 * synchronizer in sync flag
 * max peers
 * Timestamp of current chain head
Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Adrian Sutton 6 years ago committed by GitHub
parent 945f979357
commit 83102e097e
  1. 14
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/DefaultMutableBlockchain.java
  2. 12
      ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java
  3. 6
      ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java

@ -63,18 +63,24 @@ public class DefaultMutableBlockchain implements MutableBlockchain {
chainHeader = blockchainStorage.getBlockHeader(chainHead).get(); chainHeader = blockchainStorage.getBlockHeader(chainHead).get();
totalDifficulty = blockchainStorage.getTotalDifficulty(chainHead).get(); totalDifficulty = blockchainStorage.getTotalDifficulty(chainHead).get();
metricsSystem.createGauge( metricsSystem.createLongGauge(
MetricCategory.BLOCKCHAIN, MetricCategory.BLOCKCHAIN,
"height", "height",
"Height of the chainhead", "Height of the chainhead",
() -> (double) this.getChainHeadBlockNumber()); this::getChainHeadBlockNumber);
metricsSystem.createGauge( metricsSystem.createLongGauge(
MetricCategory.BLOCKCHAIN, MetricCategory.BLOCKCHAIN,
"difficulty_total", "difficulty_total",
"Total difficulty of the chainhead", "Total difficulty of the chainhead",
() -> () ->
BytesValues.asUnsignedBigInteger(this.getChainHead().getTotalDifficulty().getBytes()) BytesValues.asUnsignedBigInteger(this.getChainHead().getTotalDifficulty().getBytes())
.doubleValue()); .longValue());
metricsSystem.createLongGauge(
MetricCategory.BLOCKCHAIN,
"chain_head_timestamp",
"Timestamp from the current chain head",
() -> getChainHeadHeader().getTimestamp());
} }
@Override @Override

@ -27,6 +27,7 @@ import tech.pegasys.pantheon.ethereum.eth.sync.state.PendingBlocks;
import tech.pegasys.pantheon.ethereum.eth.sync.state.SyncState; import tech.pegasys.pantheon.ethereum.eth.sync.state.SyncState;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage;
import tech.pegasys.pantheon.metrics.MetricCategory;
import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.metrics.MetricsSystem;
import tech.pegasys.pantheon.util.ExceptionUtils; import tech.pegasys.pantheon.util.ExceptionUtils;
import tech.pegasys.pantheon.util.Subscribers; import tech.pegasys.pantheon.util.Subscribers;
@ -95,6 +96,17 @@ public class DefaultSynchronizer<C> implements Synchronizer {
worldStateStorage, worldStateStorage,
syncState, syncState,
clock); clock);
metricsSystem.createLongGauge(
MetricCategory.SYNCHRONIZER,
"best_known_block",
"Height of best known block from any connected peer",
() -> syncState.syncStatus().getHighestBlock());
metricsSystem.createIntegerGauge(
MetricCategory.SYNCHRONIZER,
"in_sync",
"Whether or not the local node has caught up to the best known peer",
() -> getSyncStatus().isPresent() ? 0 : 1);
} }
private TrailingPeerRequirements calculateTrailingPeerRequirements() { private TrailingPeerRequirements calculateTrailingPeerRequirements() {

@ -237,6 +237,12 @@ public class DefaultP2PNetwork implements P2PNetwork {
"netty_boss_pending_tasks", "netty_boss_pending_tasks",
"The number of pending tasks in the Netty boss event loop", "The number of pending tasks in the Netty boss event loop",
pendingTaskCounter(boss)); pendingTaskCounter(boss));
metricsSystem.createIntegerGauge(
MetricCategory.NETWORK,
"peers_limit",
"Maximum P2P peer connections that can be established",
() -> maxPeers);
} }
public static Builder builder() { public static Builder builder() {

Loading…
Cancel
Save