Skip to content

Commit

Permalink
network: introduce near_peer_message_sent_by_type_{bytes,total} metri…
Browse files Browse the repository at this point in the history
…cs (#7523)

* network: introduce near_peer_message_sent_by_type_{bytes,total} metrics

* fmt
  • Loading branch information
mina86 authored and nikurt committed Nov 9, 2022
1 parent 2961952 commit cb060f8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
deprecated. In fact it has never been used and only served to
confuse everyone [#7300](https://github.com/near/nearcore/pull/7300)
* Due to increasing state size, improved shard cache for Trie nodes to
put more nodes in memory. Requires 3 GB more RAM
put more nodes in memory. Requires 3 GB more RAM
[#7429](https://github.com/near/nearcore/pull/7429)
* Added `near_peer_message_sent_by_type_bytes` and
`near_peer_message_sent_by_type_total` Prometheus metrics measuring
size and number of messages sent to peers.

## 1.28.0 [2022-07-27]

Expand Down
8 changes: 6 additions & 2 deletions chain/network/src/peer/peer_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl PeerActor {
msg: &PeerMessage,
enc: Encoding,
) -> Result<(), IOError> {
let msg_type: &str = msg.into();
let msg_type: &str = msg.msg_variant();
let _span = tracing::trace_span!(
target: "network",
"send_message_with_encoding",
Expand All @@ -232,14 +232,18 @@ impl PeerActor {
self.tracker.lock().increment_sent(&self.clock, bytes.len() as u64);
let bytes_len = bytes.len();
tracing::trace!(target: "network", msg_len = bytes_len);
metrics::PEER_DATA_SENT_BYTES.inc_by(bytes_len as u64);
if !self.framed.write(bytes) {
#[cfg(feature = "performance_stats")]
let tid = near_rust_allocator_proxy::get_tid();
#[cfg(not(feature = "performance_stats"))]
let tid = 0;
return Err(IOError::Send { tid, message_type: msg_type.to_string(), size: bytes_len });
}
metrics::PEER_DATA_SENT_BYTES.inc_by(bytes_len as u64);
metrics::PEER_MESSAGE_SENT_BY_TYPE_TOTAL.with_label_values(&[msg_type]).inc();
metrics::PEER_MESSAGE_SENT_BY_TYPE_BYTES
.with_label_values(&[msg_type])
.inc_by(bytes_len as u64);
Ok(())
}

Expand Down
18 changes: 17 additions & 1 deletion chain/network/src/stats/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,23 @@ pub(crate) static PEER_MESSAGE_RECEIVED_TOTAL: Lazy<IntCounter> = Lazy::new(|| {
pub(crate) static PEER_MESSAGE_RECEIVED_BY_TYPE_TOTAL: Lazy<IntCounterVec> = Lazy::new(|| {
try_create_int_counter_vec(
"near_peer_message_received_by_type_total",
"Number of messages received from peers, by message types",
"Number of messages received from peers by message types",
&["type"],
)
.unwrap()
});
pub(crate) static PEER_MESSAGE_SENT_BY_TYPE_BYTES: Lazy<IntCounterVec> = Lazy::new(|| {
try_create_int_counter_vec(
"near_peer_message_sent_by_type_bytes",
"Total data sent to peers by message types",
&["type"],
)
.unwrap()
});
pub(crate) static PEER_MESSAGE_SENT_BY_TYPE_TOTAL: Lazy<IntCounterVec> = Lazy::new(|| {
try_create_int_counter_vec(
"near_peer_message_sent_by_type_total",
"Number of messages sent to peers by message types",
&["type"],
)
.unwrap()
Expand Down

0 comments on commit cb060f8

Please sign in to comment.