Browse Source

output to main

main
Alexey Velikiy 3 years ago
parent
commit
4ea4381f58
  1. 7
      src/grafana_service.rs
  2. 2
      src/grafana_service/prometheus.rs
  3. 10
      src/main.rs

7
src/grafana_service.rs

@ -1,4 +1,4 @@
use crate::types;
use crate::{metric::MetricResult, types};
use hyper::{Body, Client, Method, Request, StatusCode};
use tokio::io::{stdout, AsyncWriteExt as _};
@ -34,7 +34,7 @@ impl GrafanaService {
Ok(())
}
pub async fn extract_metrics(&self, panel_url: &str) -> types::Result<()> {
pub async fn extract_metrics(&self, panel_url: &str) -> types::Result<MetricResult> {
let pm = prometheus::Prometheus::new(
self,
"/api/datasources/proxy/1/api/v1/query_range",
@ -43,8 +43,7 @@ impl GrafanaService {
);
let r = pm.query(1634672070, 1634672970).await?;
Ok(())
Ok(r)
}
async fn get(&self, suburl: &str) -> types::Result<(StatusCode, serde_json::Value)> {

2
src/grafana_service/prometheus.rs

@ -71,7 +71,7 @@ fn parse_result(value: Value) -> types::Result<MetricResult> {
let mut result = MetricResult::new();
result.insert(metric_name, values.to_owned());
println!("{:?}", result);
// println!("{:?}", result);
return Ok(result);
}

10
src/main.rs

@ -29,8 +29,16 @@ async fn main() -> types::Result<()> {
// gs.test_connection().await?;
// gs.get_datasources().await?;
gs.extract_metrics("http://localhost:3000/d/YeBxHjzWz/starter-app-stats?editPanel=2&orgId=1")
let r = gs.extract_metrics("http://localhost:3000/d/YeBxHjzWz/starter-app-stats?editPanel=2&orgId=1")
.await?;
let key = r.keys().nth(0).unwrap();
println!("{}", key);
let vs = &r[key];
for (t, v) in vs.iter() {
println!("{}\t{}", t, v);
}
Ok(())
}

Loading…
Cancel
Save