feature/1117
prplV 2025-03-04 15:43:04 +03:00
parent 45305d4c35
commit 58dedc1adf
1 changed files with 6 additions and 14 deletions

View File

@ -3,7 +3,7 @@ use integr_structs::api::v3::{PrometheusMetrics, PrometheusMetricsExtended};
use reqwest::Client;
use tokio_postgres::NoTls;
use std::env;
use anyhow::{Result};
use anyhow::Result;
use log::{info, error};
pub struct Exporter {
@ -34,51 +34,43 @@ impl Exporter {
},
}
}
#[allow(unused)]
pub fn is_no_connection(&self) -> bool { self.pool.is_none() }
pub fn init() -> Self {
Self {
pool : Self::pool_construct(),
}
}
#[allow(unused)]
pub async fn get_connection_from_pool(&self) -> Option<PgClient> {
if let Some(pool) = &self.pool {
return Some(pool.get().await.ok()?);
}
None
}
#[allow(unused)]
pub async fn export_data(client: PgClient, metrics: &str) -> Result<()> {
// client.
let query = client.prepare_cached("INSERT INTO metrics (body) VALUES ($1);").await?;
let _ = client.query(&query, &[&metrics]).await?;
Ok(())
}
pub async fn export_metrics(metrics: PrometheusMetrics) -> Result<usize> {
let url = env::var("EXPORTER_URL")?;
// let req = Request::new(Method::PUT,
// Url::parse(metrics)?);
// dbg!(&metrics);
let req = Client::new()
.post(url)
.json(&metrics)
.send().await;
// dbg!(&req);
// dbg!(&req.unwrap().text().await);
// todo : rewrite with status code wrapping
req?;
Ok(metrics.get_bytes_len())
}
pub async fn export_extended_metrics(metrics: PrometheusMetricsExtended) -> Result<usize> {
let url = env::var("EXPORTER_URL")?;
// let req = Request::new(Method::PUT,
// Url::parse(metrics)?);
// dbg!(&metrics);
let req = Client::new()
.post(url)
.json(&metrics)
.send().await;
// dbg!(&req);
// dbg!(&req.unwrap().text().await);
// todo : rewrite with status code wrapping
req?;
Ok(metrics.get_bytes_len())
}