Skip to content

Commit

Permalink
feat: add and use Stats.{recv_success_count, recv_failure_count}
Browse files Browse the repository at this point in the history
Signed-off-by: ljedrz <[email protected]>
  • Loading branch information
ljedrz committed May 5, 2021
1 parent 9af5cf3 commit 86a749c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
3 changes: 3 additions & 0 deletions network/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ impl<S: Storage + Send + core::marker::Sync + 'static> Node<S> {
let incoming_task = task::spawn(async move {
loop {
if let Err(e) = node_clone.process_incoming_messages(&mut receiver).await {
node_clone.stats.recv_failure_count.fetch_add(1, Ordering::Relaxed);
error!("Node error: {}", e);
} else {
node_clone.stats.recv_success_count.fetch_add(1, Ordering::Relaxed);
}
}
});
Expand Down
4 changes: 4 additions & 0 deletions network/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ pub struct Stats {
pub send_success_count: AtomicU64,
/// The monotonic counter for the number of send requests that failed.
pub send_failure_count: AtomicU64,
/// The number of successfully processed inbound messages.
pub recv_success_count: AtomicU64,
/// The number of inbound messages that couldn't be processed.
pub recv_failure_count: AtomicU64,
/// The current number of items in the inbound channel.
pub inbound_channel_items: AtomicU64,
/// The number of all connection requests the node has received.
Expand Down
24 changes: 13 additions & 11 deletions rpc/documentation/public_endpoints/getnodestats.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ None

### Response

| Parameter | Type | Description |
|:------------------------------:|:----:|:-------------------------------------------------------:|
| `send_success_count` | u64 | The number of successfully sent messages |
| `send_failure_count` | u64 | The number of failures to send messages |
| `inbound_channel_items` | u64 | The number of inbound items queued to be processed |
| `inbound_connection_requests` | u64 | The number of connection requests the node has received |
| `outbound_connection_requests` | u64 | The number of connection requests the node has made |
| `number_of_connected_peers` | u16 | The number of currently connected peers |
| `number_of_connecting_peers` | u16 | The number of currently connecting peers |
| `blocks_mined` | u32 | The number of blocks the node has mined |
| `block_height` | u32 | The current block height of the node |
| Parameter | Type | Description |
|:------------------------------:|:----:|:---------------------------------------------------------:|
| `send_success_count` | u64 | The number of successfully sent messages |
| `send_failure_count` | u64 | The number of failures to send messages |
| `recv_success_count` | u64 | The number of successfully processed inbound messages |
| `recv_failure_count` | u64 | The number of inbound messages that couldn't be processed |
| `inbound_channel_items` | u64 | The number of inbound items queued to be processed |
| `inbound_connection_requests` | u64 | The number of connection requests the node has received |
| `outbound_connection_requests` | u64 | The number of connection requests the node has made |
| `number_of_connected_peers` | u16 | The number of currently connected peers |
| `number_of_connecting_peers` | u16 | The number of currently connecting peers |
| `blocks_mined` | u32 | The number of blocks the node has mined |
| `block_height` | u32 | The current block height of the node |

### Example
```ignore
Expand Down
2 changes: 2 additions & 0 deletions rpc/src/rpc_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ impl<S: Storage + Send + core::marker::Sync + 'static> RpcFunctions for RpcImpl<
Ok(NodeStats {
send_success_count: self.node.stats.send_success_count.load(Ordering::Relaxed),
send_failure_count: self.node.stats.send_failure_count.load(Ordering::Relaxed),
recv_success_count: self.node.stats.recv_success_count.load(Ordering::Relaxed),
recv_failure_count: self.node.stats.recv_failure_count.load(Ordering::Relaxed),
inbound_channel_items: self.node.stats.inbound_channel_items.load(Ordering::SeqCst),
inbound_connection_requests: self.node.stats.inbound_connection_requests.load(Ordering::Relaxed),
outbound_connection_requests: self.node.stats.outbound_connection_requests.load(Ordering::Relaxed),
Expand Down
6 changes: 6 additions & 0 deletions rpc/src/rpc_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ pub struct NodeStats {
/// The number of failures to send messages
pub send_failure_count: u64,

/// The number of successfully processed inbound messages.
pub recv_success_count: u64,

/// The number of inbound messages that couldn't be processed.
pub recv_failure_count: u64,

/// The number of inbound items queued to be processed
pub inbound_channel_items: u64,

Expand Down

0 comments on commit 86a749c

Please sign in to comment.