Skip to content

Commit

Permalink
feat: initial structure
Browse files Browse the repository at this point in the history
  • Loading branch information
apskhem committed Jan 16, 2025
1 parent 56454b6 commit 11e4144
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 3 deletions.
44 changes: 44 additions & 0 deletions catalyst-gateway/bin/src/metrics/chain_follower.rs
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
//! Metrics related to Chain Follower analytics.
use std::{
sync::atomic::{AtomicBool, Ordering},
thread,
};

use crate::settings::Settings;

/// This is to prevent the init function from accidentally being called multiple times.
static IS_INITIALIZED: AtomicBool = AtomicBool::new(false);

/// Starts a background thread to periodically update memory metrics.
///
/// This function spawns a thread that updates the memory metrics
/// at regular intervals defined by the `METRICS_MEMORY_INTERVAL` envar.
pub(crate) fn init_metrics_updater() {
if IS_INITIALIZED.swap(true, Ordering::SeqCst) {
return;
}

let api_host_names = Settings::api_host_names().join(",");
let service_id = Settings::service_id();

thread::spawn(move || {
loop {
{

}

thread::sleep(Settings::metrics_memory_interval());
}
});
}

/// All the related memory reporting metrics to the Prometheus service are inside this
/// module.
mod reporter {
use std::sync::LazyLock;

use prometheus::{register_int_gauge_vec, IntGaugeVec};

/// Labels for the chain follower metrics
const MEMORY_METRIC_LABELS: [&str; 2] = ["api_host_names", "service_id"];
}
44 changes: 44 additions & 0 deletions catalyst-gateway/bin/src/metrics/chain_indexer.rs
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
//! Metrics related to Chain Indexer analytics.
use std::{
sync::atomic::{AtomicBool, Ordering},
thread,
};

use crate::settings::Settings;

/// This is to prevent the init function from accidentally being called multiple times.
static IS_INITIALIZED: AtomicBool = AtomicBool::new(false);

/// Starts a background thread to periodically update memory metrics.
///
/// This function spawns a thread that updates the memory metrics
/// at regular intervals defined by the `METRICS_MEMORY_INTERVAL` envar.
pub(crate) fn init_metrics_updater() {
if IS_INITIALIZED.swap(true, Ordering::SeqCst) {
return;
}

let api_host_names = Settings::api_host_names().join(",");
let service_id = Settings::service_id();

thread::spawn(move || {
loop {
{

}

thread::sleep(Settings::metrics_memory_interval());
}
});
}

/// All the related memory reporting metrics to the Prometheus service are inside this
/// module.
mod reporter {
use std::sync::LazyLock;

use prometheus::{register_int_gauge_vec, IntGaugeVec};

/// Labels for the chain follower metrics
const MEMORY_METRIC_LABELS: [&str; 2] = ["api_host_names", "service_id"];
}
6 changes: 3 additions & 3 deletions catalyst-gateway/bin/src/metrics/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ static IS_INITIALIZED: AtomicBool = AtomicBool::new(false);

/// Starts a background thread to periodically update memory metrics.
///
/// This function spawns a thread that updates the global `MemoryMetrics`
/// structure at regular intervals defined by `UPDATE_INTERVAL_MILLI`.
/// This function spawns a thread that updates the memory metrics
/// at regular intervals defined by the `METRICS_MEMORY_INTERVAL` envar.
pub(crate) fn init_metrics_updater() {
if IS_INITIALIZED.swap(true, Ordering::SeqCst) {
return;
Expand Down Expand Up @@ -82,7 +82,7 @@ mod reporter {

use prometheus::{register_int_gauge_vec, IntGaugeVec};

/// Labels for the client metrics
/// Labels for the memory metrics
const MEMORY_METRIC_LABELS: [&str; 2] = ["api_host_names", "service_id"];

/// The "physical" memory used by this process, in bytes.
Expand Down
2 changes: 2 additions & 0 deletions catalyst-gateway/bin/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub(crate) mod memory;
/// Returns the default prometheus registry.
#[must_use]
pub(crate) fn init_prometheus() -> Registry {
chain_follower::init_metrics_updater();
chain_indexer::init_metrics_updater();
memory::init_metrics_updater();

default_registry().clone()
Expand Down

0 comments on commit 11e4144

Please sign in to comment.