|
|
|
@ -1,11 +1,15 @@
|
|
|
|
|
use async_trait::async_trait; |
|
|
|
|
use hyper::{Body, Client, Method, Request, StatusCode}; |
|
|
|
|
|
|
|
|
|
use serde_derive::{Deserialize, Serialize}; |
|
|
|
|
|
|
|
|
|
use crate::{ |
|
|
|
|
metric::{Metric, MetricResult}, |
|
|
|
|
types, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
use serde_qs as qs; |
|
|
|
|
|
|
|
|
|
use bytes::Buf as _; |
|
|
|
|
|
|
|
|
|
pub struct Prometheus { |
|
|
|
@ -13,6 +17,14 @@ pub struct Prometheus {
|
|
|
|
|
query: String, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize)] |
|
|
|
|
struct Query { |
|
|
|
|
query: String, |
|
|
|
|
start: u64, |
|
|
|
|
end: u64, |
|
|
|
|
step: u64, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Prometheus { |
|
|
|
|
pub fn new(url: &String, query: &String) -> Prometheus { |
|
|
|
|
Prometheus { |
|
|
|
@ -44,6 +56,15 @@ impl Prometheus {
|
|
|
|
|
#[async_trait] |
|
|
|
|
impl Metric for Prometheus { |
|
|
|
|
async fn query_chunk(&self, from: u64, to: u64, step: u64) -> types::Result<MetricResult> { |
|
|
|
|
let q = Query { |
|
|
|
|
query: self.query.to_owned(), |
|
|
|
|
start: from, |
|
|
|
|
end: to, |
|
|
|
|
step, |
|
|
|
|
}; |
|
|
|
|
let qs = qs::to_string(&q)?; |
|
|
|
|
|
|
|
|
|
println!("prom str: {}", qs); |
|
|
|
|
// TODO: query
|
|
|
|
|
// TODO: parse
|
|
|
|
|
return Ok(Default::default()); |
|
|
|
|