diff --git a/src/grafana_service.rs b/src/grafana_service.rs index d404152..07bdf6b 100644 --- a/src/grafana_service.rs +++ b/src/grafana_service.rs @@ -35,10 +35,14 @@ impl GrafanaService { } pub async fn extract_metrics(&self, panel_url: &str) -> types::Result<()> { - let pm = prometheus::Prometheus::new(self, "rate(go_memstats_alloc_bytes_total[5m])", 15); - let r = pm.query(1634672070, 1634672970).await; + let pm = prometheus::Prometheus::new( + self, + "/api/datasources/proxy/1/api/v1/query_range", + "rate(go_memstats_alloc_bytes_total[5m])", + 15, + ); + let r = pm.query(1634672070, 1634672970).await?; - // println!("{}", p.to_string()); Ok(()) } diff --git a/src/grafana_service/prometheus.rs b/src/grafana_service/prometheus.rs index e52a3d2..76dd494 100644 --- a/src/grafana_service/prometheus.rs +++ b/src/grafana_service/prometheus.rs @@ -1,5 +1,3 @@ -use std::{collections::HashMap, result}; - use async_trait::async_trait; use serde_json::Value; @@ -15,6 +13,7 @@ use serde_qs as qs; use super::GrafanaService; pub struct Prometheus<'a> { + url: String, query: String, step: u32, grafana_service: &'a GrafanaService, @@ -29,8 +28,14 @@ struct Query { } impl<'a> Prometheus<'a> { - pub fn new(grafana_service: &'a GrafanaService, query: &str, step: u32) -> Prometheus<'a> { + pub fn new( + grafana_service: &'a GrafanaService, + url: &str, + query: &str, + step: u32, + ) -> Prometheus<'a> { Prometheus { + url: url.to_owned(), grafana_service, query: query.to_string(), step, @@ -80,11 +85,11 @@ impl Metric for Prometheus<'_> { start: from, end: to, }; - let url = "/api/datasources/proxy/1/api/v1/query_range"; + // TODO: use serialisatoin from serde let rq = qs::to_string(&q)?; - let (status_code, value) = self.grafana_service.post_form(&url, &rq).await?; + let (status_code, value) = self.grafana_service.post_form(&self.url, &rq).await?; // TODO: return error // if status_code != StatusCode::OK { // return std::error::("Bad status code");