|
|
@ -1,19 +1,14 @@ |
|
|
|
use clap::{App, Arg, SubCommand}; |
|
|
|
use clap::{App, Arg, SubCommand}; |
|
|
|
|
|
|
|
use subbeat::types::QueryConfig; |
|
|
|
|
|
|
|
|
|
|
|
pub struct CLI { |
|
|
|
pub struct CLI { |
|
|
|
pub url: String, |
|
|
|
pub query_config: QueryConfig, |
|
|
|
pub key: String, |
|
|
|
|
|
|
|
pub datasource_url: String, |
|
|
|
|
|
|
|
pub query: String, |
|
|
|
|
|
|
|
pub from: u64, |
|
|
|
|
|
|
|
pub to: u64, |
|
|
|
|
|
|
|
pub step: u64, |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl CLI { |
|
|
|
impl CLI { |
|
|
|
pub fn new() -> CLI { |
|
|
|
pub fn new() -> CLI { |
|
|
|
let matches = App::new("subbeat") |
|
|
|
let matches = App::new("subbeat") |
|
|
|
.version("0.0.2") |
|
|
|
.version("0.0.4") |
|
|
|
.about("Timeseries toolkit") |
|
|
|
.about("Timeseries toolkit") |
|
|
|
.subcommand( |
|
|
|
.subcommand( |
|
|
|
SubCommand::with_name("grafana") |
|
|
|
SubCommand::with_name("grafana") |
|
|
@ -63,6 +58,40 @@ impl CLI { |
|
|
|
.index(7), |
|
|
|
.index(7), |
|
|
|
), |
|
|
|
), |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
.subcommand( |
|
|
|
|
|
|
|
SubCommand::with_name("prometheus") |
|
|
|
|
|
|
|
.about("Use prometheus API as datasource") |
|
|
|
|
|
|
|
.arg( |
|
|
|
|
|
|
|
Arg::with_name("PROM_URL") |
|
|
|
|
|
|
|
.help("URL to your Grafana instance") |
|
|
|
|
|
|
|
.required(true) |
|
|
|
|
|
|
|
.index(1), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.arg( |
|
|
|
|
|
|
|
Arg::with_name("query") |
|
|
|
|
|
|
|
.help("your query to datasource") |
|
|
|
|
|
|
|
.required(true) |
|
|
|
|
|
|
|
.index(2), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.arg( |
|
|
|
|
|
|
|
Arg::with_name("from") |
|
|
|
|
|
|
|
.help("timestamp") |
|
|
|
|
|
|
|
.required(true) |
|
|
|
|
|
|
|
.index(3), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.arg( |
|
|
|
|
|
|
|
Arg::with_name("to") |
|
|
|
|
|
|
|
.help("timestampt") |
|
|
|
|
|
|
|
.required(true) |
|
|
|
|
|
|
|
.index(4), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.arg( |
|
|
|
|
|
|
|
Arg::with_name("step") |
|
|
|
|
|
|
|
.help("aggregation step") |
|
|
|
|
|
|
|
.required(true) |
|
|
|
|
|
|
|
.index(5), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
) |
|
|
|
.get_matches(); |
|
|
|
.get_matches(); |
|
|
|
|
|
|
|
|
|
|
|
if let Some(matches) = matches.subcommand_matches("grafana") { |
|
|
|
if let Some(matches) = matches.subcommand_matches("grafana") { |
|
|
@ -74,24 +103,39 @@ impl CLI { |
|
|
|
let to = matches.value_of("to").unwrap().parse().unwrap(); |
|
|
|
let to = matches.value_of("to").unwrap().parse().unwrap(); |
|
|
|
let step = matches.value_of("step").unwrap().parse().unwrap(); |
|
|
|
let step = matches.value_of("step").unwrap().parse().unwrap(); |
|
|
|
return CLI { |
|
|
|
return CLI { |
|
|
|
url: url.to_owned(), |
|
|
|
query_config: QueryConfig { |
|
|
|
key: key.to_owned(), |
|
|
|
datasource_type: subbeat::types::DatasourceType::Grafana, |
|
|
|
datasource_url: datasource_url.to_owned(), |
|
|
|
url: url.to_owned(), |
|
|
|
query: query.to_owned(), |
|
|
|
key: key.to_owned(), |
|
|
|
from, |
|
|
|
datasource_url: datasource_url.to_owned(), |
|
|
|
to, |
|
|
|
query: query.to_owned(), |
|
|
|
step, |
|
|
|
from, |
|
|
|
|
|
|
|
to, |
|
|
|
|
|
|
|
step, |
|
|
|
|
|
|
|
}, |
|
|
|
}; |
|
|
|
}; |
|
|
|
} else { |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(matches) = matches.subcommand_matches("prometheus") { |
|
|
|
|
|
|
|
let url = matches.value_of("PROM_URL").unwrap(); |
|
|
|
|
|
|
|
let query = matches.value_of("query").unwrap(); |
|
|
|
|
|
|
|
let from = matches.value_of("from").unwrap().parse().unwrap(); |
|
|
|
|
|
|
|
let to = matches.value_of("to").unwrap().parse().unwrap(); |
|
|
|
|
|
|
|
let step = matches.value_of("step").unwrap().parse().unwrap(); |
|
|
|
return CLI { |
|
|
|
return CLI { |
|
|
|
url: "url.to_owned()".to_string(), |
|
|
|
query_config: QueryConfig { |
|
|
|
key: "key.to_owned()".to_string(), |
|
|
|
datasource_type: subbeat::types::DatasourceType::Grafana, |
|
|
|
datasource_url: "datasource_url.to_owned()".to_string(), |
|
|
|
url: url.to_owned(), |
|
|
|
query: "query.to_owned()".to_string(), |
|
|
|
key: "key".to_owned(), |
|
|
|
from: 0, |
|
|
|
datasource_url: "datasource_url".to_owned(), |
|
|
|
to: 0, |
|
|
|
query: query.to_owned(), |
|
|
|
step: 0, |
|
|
|
from, |
|
|
|
|
|
|
|
to, |
|
|
|
|
|
|
|
step, |
|
|
|
|
|
|
|
}, |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
panic!("Unknown datasource"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|