Skip to content

Commit 7305195

Browse files
authored
Load metrics from stats on startup (#287)
1 parent 31ba7a4 commit 7305195

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

server/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ async fn main() -> anyhow::Result<()> {
8282
// track all parquet files already in the data directory
8383
storage::CACHED_FILES.track_parquet();
8484

85+
// load data from stats back to prometheus metrics
86+
metrics::load_from_global_stats();
87+
8588
let (localsync_handler, mut localsync_outbox, localsync_inbox) = run_local_sync();
8689
let (mut remote_sync_handler, mut remote_sync_outbox, mut remote_sync_inbox) =
8790
object_store_sync();

server/src/metrics/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ use actix_web_prometheus::{PrometheusMetrics, PrometheusMetricsBuilder};
2222
use lazy_static::lazy_static;
2323
use prometheus::{HistogramOpts, HistogramVec, IntCounterVec, IntGaugeVec, Opts, Registry};
2424

25+
use crate::metadata::STREAM_INFO;
26+
2527
pub const METRICS_NAMESPACE: &str = env!("CARGO_PKG_NAME");
2628

2729
lazy_static! {
@@ -101,5 +103,21 @@ fn prom_process_metrics(metrics: &PrometheusMetrics) {
101103
.register(Box::new(ProcessCollector::for_self()))
102104
.expect("metric can be registered");
103105
}
106+
104107
#[cfg(not(target_os = "linux"))]
105108
fn prom_process_metrics(_metrics: &PrometheusMetrics) {}
109+
110+
pub fn load_from_global_stats() {
111+
for stream_name in STREAM_INFO.list_streams() {
112+
let stats = STREAM_INFO.get_stats(&stream_name).expect("stream exists");
113+
EVENTS_INGESTED
114+
.with_label_values(&[&stream_name, "json"])
115+
.inc_by(stats.events);
116+
EVENTS_INGESTED_SIZE
117+
.with_label_values(&[&stream_name, "json"])
118+
.set(stats.ingestion as i64);
119+
STORAGE_SIZE
120+
.with_label_values(&[&stream_name, "parquet"])
121+
.set(stats.storage as i64)
122+
}
123+
}

0 commit comments

Comments
 (0)