Browse Source

basic influx queries

main
Alexey Velikiy 3 years ago
parent
commit
667605800c
  1. 48
      Cargo.lock
  2. 1
      Cargo.toml
  3. 15
      src/datasources/influx.rs

48
Cargo.lock generated

@ -81,6 +81,19 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [
"libc",
"num-integer",
"num-traits",
"time",
"winapi",
]
[[package]] [[package]]
name = "clap" name = "clap"
version = "2.33.3" version = "2.33.3"
@ -421,6 +434,25 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "num-integer"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
dependencies = [
"autocfg",
]
[[package]] [[package]]
name = "num_cpus" name = "num_cpus"
version = "1.13.0" version = "1.13.0"
@ -735,6 +767,7 @@ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
"bytes", "bytes",
"chrono",
"clap", "clap",
"csv", "csv",
"hyper", "hyper",
@ -800,6 +833,17 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "time"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [
"libc",
"wasi",
"winapi",
]
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.12.0" version = "1.12.0"
@ -923,9 +967,9 @@ dependencies = [
[[package]] [[package]]
name = "wasi" name = "wasi"
version = "0.10.2+wasi-snapshot-preview1" version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]] [[package]]
name = "winapi" name = "winapi"

1
Cargo.toml

@ -23,3 +23,4 @@ serde_qs = "0.8.5"
async-trait = "0.1.51" async-trait = "0.1.51"
anyhow = "1.0.13" anyhow = "1.0.13"
csv = "1.1" csv = "1.1"
chrono = "0.4.19"

15
src/datasources/influx.rs

@ -37,12 +37,25 @@ impl Influx {
pub fn parse_result(reader: Reader<impl Buf>) -> types::Result<MetricResult> { pub fn parse_result(reader: Reader<impl Buf>) -> types::Result<MetricResult> {
let mut rdr = csv::Reader::from_reader(reader); let mut rdr = csv::Reader::from_reader(reader);
// for h in rdr.headers() {
// println!("{:?}", h);
// }
// println!("len: {:?}", rdr.headers().unwrap().get(9));
let measurement = rdr.headers().unwrap().get(9).unwrap().to_owned();
// println!("_measurement {}", measurement);
let mut ts = Vec::new();
for result in rdr.records() { for result in rdr.records() {
let record = result?; let record = result?;
println!("{:?}", record); let t = chrono::DateTime:: parse_from_rfc3339(record.get(5).unwrap()).unwrap().timestamp() as u64;
let v = record.get(6).unwrap().parse::<f64>().unwrap();
ts.push((t,v));
// println!("{:?} > {:?}", t, v);
// println!("{:?}", record);
} }
let mut result: MetricResult = Default::default(); let mut result: MetricResult = Default::default();
result.data.insert(measurement, ts);
// result.data.insert(metric_name, values.to_owned()); // result.data.insert(metric_name, values.to_owned());
Ok(result) Ok(result)

Loading…
Cancel
Save