Alexey Velikiy
3 years ago
5 changed files with 21 additions and 20 deletions
@ -1,21 +1,26 @@
|
||||
use subbeat::datasources::prometheus::Prometheus; |
||||
use subbeat::{datasources::prometheus::Prometheus, metric::{Metric, MetricResult}}; |
||||
|
||||
// TODO: use resolve function as in subbeat itself
|
||||
#[derive(Clone)] |
||||
pub struct MetricService { |
||||
url: String, |
||||
query: String, |
||||
// url: String,
|
||||
// query: String,
|
||||
|
||||
prom: Prometheus |
||||
} |
||||
|
||||
impl MetricService { |
||||
pub fn new(url: &str, query: &str) -> MetricService { |
||||
MetricService { |
||||
url: url.to_string(), |
||||
query: query.to_string(), |
||||
// url: url.to_string(),
|
||||
// query: query.to_string(),
|
||||
prom: Prometheus::new(&url.to_string(), &query.to_string()) |
||||
} |
||||
} |
||||
|
||||
// TODO: make prom as field, but Prometheus should be clonable first
|
||||
pub fn get_prom(&self) -> Prometheus { |
||||
Prometheus::new(&self.url.to_string(), &self.query.to_string()) |
||||
pub async fn query(&self, from: u64, to: u64, step: u64) -> anyhow::Result<MetricResult> { |
||||
return self.prom.query(from, to, step).await; |
||||
} |
||||
|
||||
} |
||||
|
||||
|
Loading…
Reference in new issue