Browse Source

prom continue

main
Alexey Velikiy 3 years ago
parent
commit
5aff24e1f7
  1. 20
      src/datasources.rs
  2. 12
      src/datasources/grafana.rs
  3. 4
      src/datasources/prometheus.rs
  4. 1
      src/types.rs

20
src/datasources.rs

@ -1,2 +1,22 @@
use crate::{
metric::Metric,
types::{DatasourceType, QueryConfig},
};
pub mod grafana;
pub mod prometheus;
pub fn resolve(query_config: &QueryConfig) -> Box<dyn Metric> {
if query_config.datasource_type == DatasourceType::Grafana {
let gs = grafana::Grafana::new(
query_config.url.to_string(),
query_config.key.to_string(),
query_config.datasource_url.to_string(),
query_config.query.to_string(),
);
return Box::new(gs);
} else {
let pm = prometheus::Prometheus::new(&query_config.url, &query_config.query);
return Box::new(pm);
}
}

12
src/datasources/grafana.rs

@ -40,18 +40,6 @@ impl Grafana {
Ok(())
}
// pub async fn extract_metrics(
// &self,
// from: u64,
// to: u64,
// step: u64,
// ) -> types::Result<MetricResult> {
// let pm = prometheus::Prometheus::new(self, &self.datasource_url, &self.query);
// // TODO: split big query to chunks
// let r = pm.query(from, to, step).await?;
// Ok(r)
// }
async fn get(&self, suburl: &str) -> types::Result<(StatusCode, serde_json::Value)> {
let req = Request::builder()
.method(Method::GET)

4
src/datasources/prometheus.rs

@ -8,7 +8,7 @@ use crate::{
use bytes::Buf as _;
struct Prometheus {
pub struct Prometheus {
url: String,
query: String,
}
@ -44,6 +44,8 @@ impl Prometheus {
#[async_trait]
impl Metric for Prometheus {
async fn query_chunk(&self, from: u64, to: u64, step: u64) -> types::Result<MetricResult> {
// TODO: query
// TODO: parse
return Ok(Default::default());
}
}

1
src/types.rs

@ -4,6 +4,7 @@ use anyhow;
pub type Result<T> = anyhow::Result<T>;
#[derive(PartialEq)]
pub enum DatasourceType {
Grafana,
Prometheus,

Loading…
Cancel
Save