-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Test metric for the price - draft
- Loading branch information
Showing
9 changed files
with
75 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
scrape_configs: | ||
- job_name: 'RingBenchMonitor' | ||
metrics_path: '/actuator/prometheus' | ||
scrape_interval: 3s | ||
metrics_path: '/metrics' | ||
scrape_interval: 1s | ||
static_configs: | ||
- targets: ['host.docker.internal:8080'] | ||
- targets: ['host.docker.internal:3030'] | ||
labels: | ||
application: 'RingBenchMonitor Prometheus data' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod ws_client_trade; | ||
pub mod ws_client_trade; | ||
pub mod stats; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
mod stats_recorder; | ||
pub mod stats_recorder_service; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::collections::VecDeque; | ||
use prometheus::{Gauge, Encoder, TextEncoder, register_gauge, default_registry, Registry}; | ||
use std::sync::{Arc, Mutex}; | ||
use once_cell::sync::Lazy; | ||
use crate::config::CONFIG; | ||
use crate::domain::entities::trade::TradeData; | ||
|
||
// Static singleton for global price gauge storage | ||
pub static PRICE_GAUGE: Lazy<Arc<Mutex<Gauge>>> = Lazy::new(|| { | ||
let gauge = register_gauge!( | ||
"crypto_price", | ||
"Current price of the trading pair" | ||
).unwrap(); | ||
|
||
let registry = Registry::new(); | ||
|
||
registry.register(Box::new(gauge.clone())).expect("Failed to register gauge"); | ||
// Register gauge with the default registry manually | ||
//default_registry().register(Box::new(gauge.clone())).expect("Failed to register gauge"); | ||
log::info!("Prometheus Gauge was registered"); | ||
Arc::new(Mutex::new(gauge)) | ||
}); | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub struct StatsRecorderService; | ||
|
||
impl StatsRecorderService{ | ||
pub fn track_price(price: f64) { | ||
// Update the shared gauge | ||
let gauge = PRICE_GAUGE.lock().unwrap(); | ||
//log::info!("PRICE:: {}",price); | ||
gauge.set(price); | ||
} | ||
|
||
pub fn serve_metrics() -> String { | ||
// Serve the Prometheus metrics via HTTP | ||
let encoder = TextEncoder::new(); | ||
let mut buffer = Vec::new(); | ||
let metrics = prometheus::gather(); | ||
encoder.encode(&metrics, &mut buffer).unwrap(); | ||
String::from_utf8(buffer).unwrap() | ||
} | ||
} |