Skip to content

Commit

Permalink
[impl] Override certain node metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
sadroeck committed Jun 18, 2021
1 parent 854894c commit 751eba3
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions rpc/src/rpc_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ use snarkvm_utilities::{

use chrono::Utc;

use std::{ops::Deref, sync::Arc};
use std::{
ops::Deref,
sync::{atomic::Ordering, Arc},
};

/// Implements JSON-RPC HTTP endpoint functions for a node.
/// The constructor is given Arc::clone() copies of all needed node components.
Expand Down Expand Up @@ -326,7 +329,20 @@ impl<S: Storage + Send + core::marker::Sync + 'static> RpcFunctions for RpcImpl<

/// Returns statistics related to the node.
fn get_node_stats(&self) -> Result<NodeStats, RpcError> {
Ok(NODE_STATS.snapshot())
let mut metrics = NODE_STATS.snapshot();

// Note: Temporarily overriding node metrics here, as they aren't all correctly updated
// @sadroeck - remove me
metrics.misc.block_height = self.storage.current_block_height.load(Ordering::Relaxed) as u64;
metrics.connections.connected_peers = self.node.peer_book.get_active_peer_count();
metrics.connections.disconnected_peers = self.node.peer_book.get_disconnected_peer_count();
metrics.misc.block_height = self
.node
.sync()
.map(|sync| sync.current_block_height() as u64)
.unwrap_or(0);

Ok(metrics)
}

/// Returns the current mempool and sync information known by this node.
Expand Down

0 comments on commit 751eba3

Please sign in to comment.