diff --git a/.env.example b/.env.example index a8a5abb..78b0f00 100644 --- a/.env.example +++ b/.env.example @@ -2,7 +2,11 @@ CONFIG_SERVER_CREDS = "ws://ip.ip.ip.ip:port" API_GRUBBER_SOCKET = "api-grubber.sock" PREPROC_SOCKET = "preproc.sock" +# PostgreSQL connection [DEPRECATED] DB_HOST = "ip.addr.postgresql.server" DB_USER = "db_user" DB_PASSWORD = "db_user_password" -DB_DBNAME = "db_name"1 \ No newline at end of file +DB_DBNAME = "db_name"1 + +# Prometheus-Exporter info +EXPORTER_URL = "ip.ip.ip.ip:port" \ No newline at end of file diff --git a/crates/api-grub/src/export.rs b/crates/api-grub/src/export.rs index ee73421..06e94d2 100644 --- a/crates/api-grub/src/export.rs +++ b/crates/api-grub/src/export.rs @@ -1,7 +1,8 @@ use deadpool_postgres::{Config, Pool, Runtime, Client as PgClient}; +use reqwest::Client; use tokio_postgres::NoTls; use std::env; -use anyhow::{Error, Result}; +use anyhow::{Result}; use log::{info, error}; pub struct Exporter { @@ -35,7 +36,7 @@ impl Exporter { pub fn is_no_connection(&self) -> bool { self.pool.is_none() } pub fn init() -> Self { Self { - pool : Self::pool_construct() + pool : Self::pool_construct(), } } pub async fn get_connection_from_pool(&self) -> Option { @@ -50,5 +51,16 @@ impl Exporter { let _ = client.query(&query, &[&metrics]).await?; Ok(()) } + pub async fn export_metrics(metrics: &str) -> Result<()> { + let url = env::var("EXPORTER_URL")?; + // let req = Request::new(Method::PUT, + // Url::parse(metrics)?); + let req = Client::new() + .put(url) + .json(metrics) + .send().await; + req?; + Ok(()) + } } \ No newline at end of file