From 27878eb2d2bcc8d71ed490271c04b4ed8ec306a9 Mon Sep 17 00:00:00 2001 From: Alexey Velikiy Date: Thu, 14 Oct 2021 01:34:53 +0300 Subject: [PATCH] extract metrics begin --- src/grafana_service.rs | 14 ++++++++++++++ src/main.rs | 1 + 2 files changed, 15 insertions(+) diff --git a/src/grafana_service.rs b/src/grafana_service.rs index fd3c81e..f0cb6a7 100644 --- a/src/grafana_service.rs +++ b/src/grafana_service.rs @@ -24,7 +24,21 @@ impl GrafanaService { let client = Client::new(); let resp = client.request(req).await?; println!("Response: {}", resp.status()); + Ok(()) + } + pub async fn extract_metrics(&self) -> types::Result<()> { + let req = Request::builder() + .method(Method::POST) + .uri(self.url.clone() + "/api/datasources/proxy/1/api/v1/query_range") + .header("content-type", "application/json") + .header("Authorization", format!("Bearer {}", self.api_key)) + .body(Body::from(r#"{"query":"go_memstats_alloc_bytes_total", "start": "1634163645", "end": "1634163945", "step": "15"}"#)) + .unwrap(); + + let client = Client::new(); + let resp = client.request(req).await?; + println!("Response: {}", resp.status()); Ok(()) } } diff --git a/src/main.rs b/src/main.rs index 91319a9..5b43804 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,6 +28,7 @@ async fn main() -> types::Result<()> { let gs = grafana_service::GrafanaService::new(url.to_string(), key.to_string()); gs.test_connection().await?; + gs.extract_metrics().await?; Ok(()) }