|
|
@ -1,7 +1,11 @@ |
|
|
|
|
|
|
|
use std::io::BufRead; |
|
|
|
|
|
|
|
|
|
|
|
use hyper::{Body, Client, Method, Request}; |
|
|
|
use hyper::{Body, Client, Method, Request}; |
|
|
|
use tokio::io::{stdout, AsyncWriteExt as _}; |
|
|
|
use tokio::io::{stdout, AsyncWriteExt as _}; |
|
|
|
|
|
|
|
use serde_json::json; |
|
|
|
|
|
|
|
|
|
|
|
use crate::types; |
|
|
|
use crate::types; |
|
|
|
|
|
|
|
use bytes::Buf as _; |
|
|
|
|
|
|
|
|
|
|
|
pub struct GrafanaService { |
|
|
|
pub struct GrafanaService { |
|
|
|
url: String, |
|
|
|
url: String, |
|
|
@ -33,12 +37,36 @@ impl GrafanaService { |
|
|
|
.uri(self.url.clone() + "/api/datasources/proxy/1/api/v1/query_range") |
|
|
|
.uri(self.url.clone() + "/api/datasources/proxy/1/api/v1/query_range") |
|
|
|
.header("content-type", "application/json") |
|
|
|
.header("content-type", "application/json") |
|
|
|
.header("Authorization", format!("Bearer {}", self.api_key)) |
|
|
|
.header("Authorization", format!("Bearer {}", self.api_key)) |
|
|
|
.body(Body::from(r#"{"query":"go_memstats_alloc_bytes_total", "start": "1634163645", "end": "1634163945", "step": "15"}"#)) |
|
|
|
.body(Body::from(json!({
|
|
|
|
|
|
|
|
"query":"go_memstats_alloc_bytes_total",
|
|
|
|
|
|
|
|
"start": "1634163645", |
|
|
|
|
|
|
|
"end": "1634163945",
|
|
|
|
|
|
|
|
"step": "15" |
|
|
|
|
|
|
|
}).to_string()) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
.unwrap(); |
|
|
|
.unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
let client = Client::new(); |
|
|
|
let client = Client::new(); |
|
|
|
let resp = client.request(req).await?; |
|
|
|
let res = client.request(req).await?; |
|
|
|
println!("Response: {}", resp.status()); |
|
|
|
println!("Response: {}", res.status()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// while let Some(next) = resp.body().data().await {
|
|
|
|
|
|
|
|
// let chunk = next?;
|
|
|
|
|
|
|
|
// io::stdout().write_all(&chunk).await?;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let body = hyper::body::aggregate(res).await?; |
|
|
|
|
|
|
|
let mut reader = body.reader(); |
|
|
|
|
|
|
|
let mut line = String::new(); |
|
|
|
|
|
|
|
loop { |
|
|
|
|
|
|
|
match reader.read_line(&mut line) { |
|
|
|
|
|
|
|
Ok(_) => println!("{}", line), |
|
|
|
|
|
|
|
Err(_) => break
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|