Skip to content

Commit

Permalink
feat(metrics): add solidification counter metric (#170)
Browse files Browse the repository at this point in the history
* Add solidification counter metric

* Fix solid count metric name
  • Loading branch information
Alexandcoats committed May 18, 2022
1 parent a3a2020 commit 46f5bcb
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
24 changes: 22 additions & 2 deletions bin/inx-chronicle/src/collector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,31 @@ impl Actor for Collector {
type Error = CollectorError;

async fn init(&mut self, cx: &mut ActorContext<Self>) -> Result<Self::State, Self::Error> {
#[cfg(feature = "metrics")]
let solid_counter = {
let solid_counter = bee_metrics::metrics::counter::Counter::default();
cx.addr::<crate::metrics::MetricsWorker>()
.await
.send(crate::metrics::RegisterMetric {
name: "solid_count".to_string(),
help: "Count of solidified milestones".to_string(),
metric: solid_counter.clone(),
})?;
solid_counter
};
let mut solidifiers = Vec::with_capacity(self.config.solidifier_count);
for i in 0..self.config.solidifier_count {
solidifiers.push(
cx.spawn_child(Solidifier::new(i, self.db.clone()).with_registration(false))
.await,
cx.spawn_child(
Solidifier::new(
i,
self.db.clone(),
#[cfg(feature = "metrics")]
solid_counter.clone(),
)
.with_registration(false),
)
.await,
);
}
#[cfg(all(feature = "stardust", feature = "inx"))]
Expand Down
25 changes: 22 additions & 3 deletions bin/inx-chronicle/src/collector/solidifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,34 @@ pub enum SolidifierError {
ValueAccess(#[from] ValueAccessError),
}

#[derive(Debug)]
pub struct Solidifier {
pub id: usize,
pub(crate) db: MongoDb,
#[cfg(feature = "metrics")]
pub(crate) counter: bee_metrics::metrics::counter::Counter,
}

impl Solidifier {
pub fn new(id: usize, db: MongoDb) -> Self {
Self { id, db }
pub fn new(
id: usize,
db: MongoDb,
#[cfg(feature = "metrics")] counter: bee_metrics::metrics::counter::Counter,
) -> Self {
Self {
id,
db,
#[cfg(feature = "metrics")]
counter,
}
}
}

impl std::fmt::Debug for Solidifier {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Solidifier")
.field("id", &self.id)
.field("db", &self.db)
.finish()
}
}

Expand Down
3 changes: 3 additions & 0 deletions bin/inx-chronicle/src/collector/stardust_inx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ impl HandleEvent<MilestoneState> for Solidifier {
synced: true,
})
.await?;
#[cfg(feature = "metrics")]
self.counter.inc();

Ok(())
}
}

0 comments on commit 46f5bcb

Please sign in to comment.