diff --git a/src/cli.rs b/src/cli.rs index 6cef687..a065809 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -106,37 +106,37 @@ impl CLI { Arg::with_name("ORG_ID") .help("URL to your influxdb instance") .required(true) - .index(1), + .index(2), ) .arg( Arg::with_name("TOKEN") .help("URL to your influxdb instance") .required(true) - .index(1), + .index(3), ) .arg( Arg::with_name("query") .help("your flux query to datasource") .required(true) - .index(2), + .index(4), ) .arg( Arg::with_name("from") .help("timestamp") .required(true) - .index(3), + .index(5), ) .arg( Arg::with_name("to") .help("timestampt") .required(true) - .index(4), + .index(6), ) .arg( Arg::with_name("step") .help("aggregation step") .required(true) - .index(5), + .index(7), ), ) .get_matches(); @@ -184,7 +184,7 @@ impl CLI { }; if let Some(matches) = matches.subcommand_matches("influx") { - let url = matches.value_of("PROM_URL").unwrap(); + let url = matches.value_of("INFLUX_URL").unwrap(); let org_id = matches.value_of("ORG_ID").unwrap(); let token = matches.value_of("TOKEN").unwrap(); let query = matches.value_of("query").unwrap(); diff --git a/src/datasources/influx.rs b/src/datasources/influx.rs index 09bd7aa..694802b 100644 --- a/src/datasources/influx.rs +++ b/src/datasources/influx.rs @@ -38,12 +38,16 @@ impl Metric for Influx { async fn query_chunk(&self, from: u64, to: u64, step: u64) -> types::Result { let url = format!( - "{}/api/v2/query?orgId={}", + "{}/api/v2/query?orgID={}", normalize_url(self.url.to_owned()), self.org_id ); + + println!("URL: {}", url); let mut headers = HashMap::new(); + headers.insert("Accept".to_string(), "application/csv".to_owned()); headers.insert("Authorization".to_string(), format!("Token {}", self.token).to_owned()); + headers.insert("Content-type".to_string(), "application/vnd.flux".to_owned()); let (_status_code, value) = utils::post_with_headers(&url, headers).await?; return parse_result(value); diff --git a/src/utils.rs b/src/utils.rs index b718d69..17e9db0 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -68,8 +68,8 @@ pub async fn post_with_headers(url: &String, headers: HashMap) - let req_result = builder.body(Body::from("from(bucket:\"main-backet\") - // |> range(start:-1m) - // |> filter(fn:(r) => r._measurement == \"cpu\")")); + |> range(start:-1m) + |> filter(fn:(r) => r._measurement == \"cpu\")")); if req_result.is_err() { println!("{:?}", req_result);