Skip to content

Commit

Permalink
Merge pull request #2056 from RolandSherwin/metrics_unit
Browse files Browse the repository at this point in the history
chore(metrics): add unit to certain metrics
  • Loading branch information
RolandSherwin authored Aug 21, 2024
2 parents f7b8da9 + 0bc6074 commit a0f85d1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
14 changes: 9 additions & 5 deletions sn_networking/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use libp2p::metrics::{Metrics as Libp2pMetrics, Recorder};
use prometheus_client::metrics::family::Family;
use prometheus_client::{
metrics::{counter::Counter, gauge::Gauge},
registry::Registry,
registry::{Registry, Unit},
};
use sysinfo::{Pid, ProcessRefreshKind, System};
use tokio::time::Duration;
Expand Down Expand Up @@ -118,25 +118,28 @@ impl NetworkMetricsRecorder {
);

let process_memory_used_mb = Gauge::default();
sub_registry.register(
sub_registry.register_with_unit(
"process_memory_used_mb",
"Memory used by the process in MegaBytes",
Unit::Other("MegaByte".to_string()),
process_memory_used_mb.clone(),
);

let process_cpu_usage_percentage = Gauge::default();
sub_registry.register(
sub_registry.register_with_unit(
"process_cpu_usage_percentage",
"The percentage of CPU used by the process. Value is from 0-100",
Unit::Other("Percentage".to_string()),
process_cpu_usage_percentage.clone(),
);

// store cost
let store_cost_sub_registry = sub_registry.sub_registry_with_prefix("store_cost");
let store_cost = Gauge::default();
store_cost_sub_registry.register(
store_cost_sub_registry.register_with_unit(
"store_cost",
"The store cost of the node",
Unit::Other("Nano".to_string()),
store_cost.clone(),
);
let relevant_records = Gauge::default();
Expand All @@ -158,9 +161,10 @@ impl NetworkMetricsRecorder {
received_payment_count.clone(),
);
let live_time = Gauge::default();
store_cost_sub_registry.register(
store_cost_sub_registry.register_with_unit(
"live_time",
"The time for which the node has been alive",
Unit::Seconds,
live_time.clone(),
);

Expand Down
11 changes: 7 additions & 4 deletions sn_node/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use prometheus_client::{
gauge::Gauge,
histogram::{exponential_buckets, Histogram},
},
registry::Registry,
registry::{Registry, Unit},
};
use sn_networking::Instant;

Expand Down Expand Up @@ -102,23 +102,26 @@ impl NodeMetricsRecorder {
);

let current_reward_wallet_balance = Gauge::default();
sub_registry.register(
sub_registry.register_with_unit(
"current_reward_wallet_balance",
"The number of Nanos in the node reward wallet",
Unit::Other("Nano".to_string()),
current_reward_wallet_balance.clone(),
);

let total_forwarded_rewards = Gauge::default();
sub_registry.register(
sub_registry.register_with_unit(
"total_forwarded_rewards",
"The cumulative number of Nanos forwarded by the node",
Unit::Other("Nano".to_string()),
total_forwarded_rewards.clone(),
);

let uptime = Gauge::default();
sub_registry.register(
sub_registry.register_with_unit(
"uptime",
"The uptime of the node in seconds",
Unit::Seconds,
uptime.clone(),
);

Expand Down

0 comments on commit a0f85d1

Please sign in to comment.