Skip to content

Commit

Permalink
refactoring prometheus interface for message memo: made register_gaug…
Browse files Browse the repository at this point in the history
…e_with_label does not imply "other_node" as label name, register_gauge_with_other_node_label does.
  • Loading branch information
SurfingNerd committed Nov 7, 2023
1 parent ecd8582 commit c145cd2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 39 deletions.
74 changes: 37 additions & 37 deletions crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ impl PrometheusMetrics for NodeStakingEpochHistory {

let node_id = self.get_node_id().0 .0;

let label = std::format!(
let other_node = std::format!(
"{:x}{:x}{:x}{:x}{:x}{:x}{:x}{:x}",
node_id[0],
node_id[1],
Expand All @@ -1001,56 +1001,56 @@ impl PrometheusMetrics for NodeStakingEpochHistory {
);

//r.register_gauge_with_label(name, help, label, value)
r.register_gauge_with_label(
format!("cumulative_lateness").as_str(),
format!("cumulative lateness").as_str(),
label.as_str(),
r.register_gauge_with_other_node_label(
"cumulative_lateness",
"cumulative lateness",
other_node.as_str(),
self.cumulative_lateness as i64,
);

r.register_gauge_with_label(
format!("sealing_blocks_good").as_str(),
format!("good sealed block messages").as_str(),
label.as_str(),
r.register_gauge_with_other_node_label(
"sealing_blocks_good",
"good sealed block messages",
other_node.as_str(),
self.sealing_blocks_good.len() as i64,
);

r.register_gauge_with_label(
format!("sealing_blocks_late").as_str(),
format!("late sealed blocks").as_str(),
label.as_str(),
r.register_gauge_with_other_node_label(
"sealing_blocks_late",
"late sealed blocks",
other_node.as_str(),
self.sealing_blocks_late.len() as i64,
);

r.register_gauge_with_label(
format!("sealing_blocks_bad").as_str(),
format!("bad block seals").as_str(),
label.as_str(),
r.register_gauge_with_other_node_label(
"sealing_blocks_bad",
"bad block seals",
other_node.as_str(),
self.sealing_blocks_bad.len() as i64,
);

// last_good_sealing_message: u64,
// last_late_sealing_message: u64,
// last_error_sealing_message: u64,

r.register_gauge_with_label(
format!("last_good_sealing_message").as_str(),
format!("block number").as_str(),
label.as_str(),
r.register_gauge_with_other_node_label(
"last_good_sealing_message",
"block number",
other_node.as_str(),
self.last_good_sealing_message as i64,
);

r.register_gauge_with_label(
format!("last_late_sealing_message").as_str(),
format!("block number").as_str(),
label.as_str(),
r.register_gauge_with_other_node_label(
"last_late_sealing_message",
"block number",
other_node.as_str(),
self.last_late_sealing_message as i64,
);

r.register_gauge_with_label(
format!("last_error_sealing_message").as_str(),
format!("block number").as_str(),
label.as_str(),
r.register_gauge_with_other_node_label(
"last_error_sealing_message",
"block number",
other_node.as_str(),
self.last_error_sealing_message as i64,
);

Expand All @@ -1060,17 +1060,17 @@ impl PrometheusMetrics for NodeStakingEpochHistory {
// num_faulty_messages: u64,
// num_good_messages: u64,

r.register_gauge_with_label(
format!("last_message_good").as_str(),
format!("block number").as_str(),
label.as_str(),
r.register_gauge_with_other_node_label(
"last_message_good",
"block number",
other_node.as_str(),
self.last_message_good as i64,
);

r.register_gauge_with_label(
format!("last_message_faulty").as_str(),
format!("block number").as_str(),
label.as_str(),
r.register_gauge_with_other_node_label(
"last_message_faulty",
"block number",
other_node.as_str(),
self.last_message_faulty as i64,
);
}
Expand Down
10 changes: 8 additions & 2 deletions crates/util/stats/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,15 @@ impl PrometheusRegistry {
.expect("prometheus identifiers must be are unique");
}

/// Adds a new prometheus gauge with a "other_node" label.
/// Designed for tracking communication partner values.
pub fn register_gauge_with_other_node_label(&mut self, name: &str, help: &str, other_node: &str, value: i64) {
self.register_gauge_with_label(name, help, "other_node", other_node, value);
}

/// Adds a new prometheus gauge with a label
pub fn register_gauge_with_label(&mut self, name: &str, help: &str, label: &str, value: i64) {
let opts = prometheus::Opts::new(name, help).const_label("other_node", label);
pub fn register_gauge_with_label(&mut self, name: &str, help: &str, label: &str, label_value: &str, value: i64) {
let opts = prometheus::Opts::new(name, help).const_label(label, label_value);
// add labels here .
//opts.variable_labels.push(label.to_string());

Expand Down

0 comments on commit c145cd2

Please sign in to comment.