From ad4ce178a990c3cb252ac48b9df1b84aa45c9c3a Mon Sep 17 00:00:00 2001 From: prplV Date: Thu, 27 Feb 2025 13:18:28 +0300 Subject: [PATCH] final fix --- crates/api-grub/src/main.rs | 31 ++++++++++++++++++++----------- crates/api-grub/src/monitoring.rs | 9 +++++++-- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/crates/api-grub/src/main.rs b/crates/api-grub/src/main.rs index ee9b2dd..cac81e3 100644 --- a/crates/api-grub/src/main.rs +++ b/crates/api-grub/src/main.rs @@ -14,13 +14,11 @@ use config::{pull_local_config, init_config_grub_mechanism}; use net::init_api_grub_mechanism; use tokio::sync::mpsc; use log::{error, info, warn}; +use monitoring::get_metrics_from_monitoring; #[tokio::main(flavor = "multi_thread")] async fn main() -> Result<()>{ - // 3 coroutines - // 1) unix-socket coroutine (for config updating) - // 2) api coroutine - // 3) ? + dotenv::dotenv().ok(); setup_logger().await?; let config = get_config().await; // config update channel @@ -41,13 +39,24 @@ async fn main() -> Result<()>{ } }); let event_grub = tokio::spawn(async move { - match init_api_grub_mechanism(config, &mut rx).await { - Ok(_) => { - info!("Grabing task deinitialized"); - }, - Err(er) => { - error!("Grabing task returned an error : {}", er); - }, + if std::env::var("ENODE_MONITORING_IP").is_ok() { + match get_metrics_from_monitoring(0, 5).await { + Ok(_) => { + info!("Grabing (eNODE.Monitoring) task deinitialized"); + }, + Err(er) => { + error!("Grabing task returned an error : {}", er); + }, + } + } else { + match init_api_grub_mechanism(config, &mut rx).await { + Ok(_) => { + info!("Grabing task deinitialized"); + }, + Err(er) => { + error!("Grabing task returned an error : {}", er); + }, + } } }); let events_handler = vec![event_config, event_grub]; diff --git a/crates/api-grub/src/monitoring.rs b/crates/api-grub/src/monitoring.rs index b77c141..dfcc5b8 100644 --- a/crates/api-grub/src/monitoring.rs +++ b/crates/api-grub/src/monitoring.rs @@ -13,6 +13,7 @@ use tokio::task::JoinHandle; use std::pin::Pin; use std::future::Future; use integr_structs::api::v3::{MetricOutput, PrometheusMetrics}; +use log::{error, info, warn}; // use chrono::{Local, DateTime}; pub async fn get_metrics_from_monitoring(duration: usize, delay: usize) -> anyhow::Result<()> { @@ -149,12 +150,16 @@ impl MonitoringImporter { }); jh_vec.push(jh); } - let mut vals = Vec::new(); + // let mut vals = Vec::new(); for event in jh_vec { match event.await { Ok(val) => { if let Ok(val) = val { - vals.push(val); + match crate::export::Exporter::export_metrics(val).await { + Ok(bytes) => info!("Successfully transmitted {} bytes to the Prometehus exporter", bytes), + Err(er) => error!("Cannot export data to the Prometehus exporter due to : `{}`", er), + } + // vals.push(val); } }, Err(er) => println!("Fatal error on async task: {}", er),