From 83102e097edf1fea127061c8ebec7ef8e6f545cc Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Wed, 29 May 2019 14:24:04 +1000 Subject: [PATCH] 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 --- .../ethereum/chain/DefaultMutableBlockchain.java | 14 ++++++++++---- .../ethereum/eth/sync/DefaultSynchronizer.java | 12 ++++++++++++ .../ethereum/p2p/network/DefaultP2PNetwork.java | 6 ++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/DefaultMutableBlockchain.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/DefaultMutableBlockchain.java index 102e5802ea..521a999dea 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/DefaultMutableBlockchain.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/DefaultMutableBlockchain.java @@ -63,18 +63,24 @@ public class DefaultMutableBlockchain implements MutableBlockchain { chainHeader = blockchainStorage.getBlockHeader(chainHead).get(); totalDifficulty = blockchainStorage.getTotalDifficulty(chainHead).get(); - metricsSystem.createGauge( + metricsSystem.createLongGauge( MetricCategory.BLOCKCHAIN, "height", "Height of the chainhead", - () -> (double) this.getChainHeadBlockNumber()); - metricsSystem.createGauge( + this::getChainHeadBlockNumber); + metricsSystem.createLongGauge( MetricCategory.BLOCKCHAIN, "difficulty_total", "Total difficulty of the chainhead", () -> BytesValues.asUnsignedBigInteger(this.getChainHead().getTotalDifficulty().getBytes()) - .doubleValue()); + .longValue()); + + metricsSystem.createLongGauge( + MetricCategory.BLOCKCHAIN, + "chain_head_timestamp", + "Timestamp from the current chain head", + () -> getChainHeadHeader().getTimestamp()); } @Override diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java index 404781ebc5..d340e93e19 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java @@ -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.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage; +import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.util.ExceptionUtils; import tech.pegasys.pantheon.util.Subscribers; @@ -95,6 +96,17 @@ public class DefaultSynchronizer implements Synchronizer { worldStateStorage, syncState, 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() { diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java index 1dc52eb246..6e8af0ab73 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java @@ -237,6 +237,12 @@ public class DefaultP2PNetwork implements P2PNetwork { "netty_boss_pending_tasks", "The number of pending tasks in the Netty boss event loop", pendingTaskCounter(boss)); + + metricsSystem.createIntegerGauge( + MetricCategory.NETWORK, + "peers_limit", + "Maximum P2P peer connections that can be established", + () -> maxPeers); } public static Builder builder() {