Browse Source

influx continue

main
Alexey Velikiy 3 years ago
parent
commit
e65c17c3ce
  1. 14
      src/cli.rs
  2. 6
      src/datasources/influx.rs
  3. 4
      src/utils.rs

14
src/cli.rs

@ -106,37 +106,37 @@ impl CLI {
Arg::with_name("ORG_ID") Arg::with_name("ORG_ID")
.help("URL to your influxdb instance") .help("URL to your influxdb instance")
.required(true) .required(true)
.index(1), .index(2),
) )
.arg( .arg(
Arg::with_name("TOKEN") Arg::with_name("TOKEN")
.help("URL to your influxdb instance") .help("URL to your influxdb instance")
.required(true) .required(true)
.index(1), .index(3),
) )
.arg( .arg(
Arg::with_name("query") Arg::with_name("query")
.help("your flux query to datasource") .help("your flux query to datasource")
.required(true) .required(true)
.index(2), .index(4),
) )
.arg( .arg(
Arg::with_name("from") Arg::with_name("from")
.help("timestamp") .help("timestamp")
.required(true) .required(true)
.index(3), .index(5),
) )
.arg( .arg(
Arg::with_name("to") Arg::with_name("to")
.help("timestampt") .help("timestampt")
.required(true) .required(true)
.index(4), .index(6),
) )
.arg( .arg(
Arg::with_name("step") Arg::with_name("step")
.help("aggregation step") .help("aggregation step")
.required(true) .required(true)
.index(5), .index(7),
), ),
) )
.get_matches(); .get_matches();
@ -184,7 +184,7 @@ impl CLI {
}; };
if let Some(matches) = matches.subcommand_matches("influx") { 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 org_id = matches.value_of("ORG_ID").unwrap();
let token = matches.value_of("TOKEN").unwrap(); let token = matches.value_of("TOKEN").unwrap();
let query = matches.value_of("query").unwrap(); let query = matches.value_of("query").unwrap();

6
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<MetricResult> { async fn query_chunk(&self, from: u64, to: u64, step: u64) -> types::Result<MetricResult> {
let url = format!( let url = format!(
"{}/api/v2/query?orgId={}", "{}/api/v2/query?orgID={}",
normalize_url(self.url.to_owned()), normalize_url(self.url.to_owned()),
self.org_id self.org_id
); );
println!("URL: {}", url);
let mut headers = HashMap::new(); 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("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?; let (_status_code, value) = utils::post_with_headers(&url, headers).await?;
return parse_result(value); return parse_result(value);

4
src/utils.rs

@ -68,8 +68,8 @@ pub async fn post_with_headers(url: &String, headers: HashMap<String, String>) -
let req_result = builder.body(Body::from("from(bucket:\"main-backet\") let req_result = builder.body(Body::from("from(bucket:\"main-backet\")
// |> range(start:-1m) |> range(start:-1m)
// |> filter(fn:(r) => r._measurement == \"cpu\")")); |> filter(fn:(r) => r._measurement == \"cpu\")"));
if req_result.is_err() { if req_result.is_err() {
println!("{:?}", req_result); println!("{:?}", req_result);

Loading…
Cancel
Save