Files
nym/nym-node/nym-node-http-api/src/state/mod.rs
T
Simon Wicky 435f236812 [Product Data] First step in gateway usage data collection (#4963)
* add stats model

* add stats collection

* add stats route

* propagate stuff and run stuff

* cargo stuff

* sqlx unused what?

* add sessions started stat

* session durations in miliseconds

* apply Jon's comments

* [Product Data] Second step in gateway usage data collection  (#4964)

* turn stats collection into event based

* move events into a common crate for future use elsewhere

* apply Jon's comments
2024-10-15 09:18:02 +02:00

55 lines
1.4 KiB
Rust

// Copyright 2023-2024 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: GPL-3.0-only
use crate::state::metrics::{
MetricsAppState, SharedMixingStats, SharedSessionStats, SharedVerlocStats,
};
use tokio::time::Instant;
pub mod metrics;
#[derive(Debug, Clone)]
pub struct AppState {
pub(crate) startup_time: Instant,
pub(crate) metrics: MetricsAppState,
}
impl AppState {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
AppState {
// is it 100% accurate?
// no.
// does it have to be?
// also no.
startup_time: Instant::now(),
metrics: Default::default(),
}
}
#[must_use]
pub fn with_mixing_stats(mut self, mixing_stats: SharedMixingStats) -> Self {
self.metrics.mixing_stats = mixing_stats;
self
}
#[must_use]
pub fn with_sessions_stats(mut self, session_stats: SharedSessionStats) -> Self {
self.metrics.session_stats = session_stats;
self
}
#[must_use]
pub fn with_verloc_stats(mut self, verloc_stats: SharedVerlocStats) -> Self {
self.metrics.verloc = verloc_stats;
self
}
#[must_use]
pub fn with_metrics_key(mut self, bearer_token: impl Into<Option<String>>) -> Self {
self.metrics.prometheus_access_token = bearer_token.into();
self
}
}