Browse Source

some commit

main
Alexey Velikiy 3 years ago
parent
commit
92427a4a11
  1. 25
      Cargo.lock
  2. 2
      Cargo.toml
  3. 34
      src/grafana_service.rs

25
Cargo.lock generated

@ -544,6 +544,12 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "ryu"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
[[package]] [[package]]
name = "schannel" name = "schannel"
version = "0.1.19" version = "0.1.19"
@ -583,6 +589,23 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "serde"
version = "1.0.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913"
[[package]]
name = "serde_json"
version = "1.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]] [[package]]
name = "signal-hook-registry" name = "signal-hook-registry"
version = "1.4.0" version = "1.4.0"
@ -624,9 +647,11 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
name = "subbeat" name = "subbeat"
version = "0.0.2" version = "0.0.2"
dependencies = [ dependencies = [
"bytes",
"clap", "clap",
"hyper", "hyper",
"hyper-tls", "hyper-tls",
"serde_json",
"tokio", "tokio",
] ]

2
Cargo.toml

@ -11,7 +11,9 @@ repository = "https://github.com/subbeat/subbeat"
readme = "README.md" readme = "README.md"
[dependencies] [dependencies]
bytes = "1"
tokio = { version = "1", features = ["full"] } tokio = { version = "1", features = ["full"] }
clap = "2.33.3" clap = "2.33.3"
hyper = { version = "0.14.13", features = ["full"] } hyper = { version = "0.14.13", features = ["full"] }
hyper-tls = "0.5.0" hyper-tls = "0.5.0"
serde_json = "1.0.59"

34
src/grafana_service.rs

@ -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(())
} }
} }

Loading…
Cancel
Save