wip: mixnet metrics

This commit is contained in:
Youngjoon Lee 2024-03-26 13:50:25 +09:00
parent a9bdab28d3
commit d2c6520a7b
No known key found for this signature in database
GPG Key ID: 7E8EE3EC8D5CEBA2
3 changed files with 28 additions and 0 deletions

View File

@ -22,6 +22,7 @@ futures = "0.3"
parking_lot = "0.12"
nomos-core = { path = "../../nomos-core" }
nomos-libp2p = { path = "../../nomos-libp2p", optional = true }
nomos-metrics = { path = "../metrics", optional = true }
mixnet = { path = "../../mixnet", optional = true }
utoipa = { version = "4.0", optional = true }
@ -36,3 +37,4 @@ libp2p = ["nomos-libp2p", "rand", "humantime-serde"]
mixnet = ["dep:mixnet"]
mock = ["rand", "chrono"]
openapi = ["dep:utoipa", "serde_json"]
metrics = ["nomos-metrics"]

View File

@ -1,4 +1,6 @@
pub mod backends;
#[cfg(feature = "metrics")]
pub mod metrics;
// std
use std::fmt::{self, Debug};

View File

@ -0,0 +1,24 @@
use nomos_metrics::{metrics::gauge::Gauge, NomosRegistry};
use overwatch_rs::services::ServiceId;
pub(crate) struct Metrics {
mixing_packets: Gauge,
}
impl Metrics {
pub(crate) fn new(registry: NomosRegistry, discriminant: ServiceId) -> Self {
let mut registry = registry
.lock()
.expect("should've acquired the lock for registry");
let sub_registry = registry.sub_registry_with_prefix(discriminant);
let mixing_packets = Gauge::default();
sub_registry.register(
"mixing_packets",
"Number of packets being mixed in the mixnode",
mixing_packets.clone(),
);
Self { mixing_packets }
}
}