use clap::{crate_authors, crate_version, App, AppSettings, Arg, SubCommand};
use scaphandre::{get_exporters_options, run};
fn main() {
#[cfg(target_os = "linux")]
let sensors = ["powercap_rapl"];
#[cfg(target_os = "windows")]
let sensors = ["msr_rapl"];
let exporters_options = get_exporters_options();
let exporters = exporters_options.keys();
let exporters: Vec<&str> = exporters.into_iter().map(|x| x.as_str()).collect();
#[cfg(target_os = "linux")]
let sensor_default_value = String::from("powercap_rapl");
#[cfg(not(target_os = "linux"))]
let sensor_default_value = String::from("msr_rapl");
let mut matches = App::new("scaphandre")
.author(crate_authors!())
.version(crate_version!())
.about("Extensible metrology agent for energy/electricity consumption related metrics")
.setting(AppSettings::SubcommandRequiredElseHelp)
.arg(
Arg::with_name("v")
.short("v")
.multiple(true)
.help("Sets the level of verbosity.")
)
.arg(
Arg::with_name("no-header")
.value_name("no-header")
.help("Prevents the header to be displayed in the terminal output.")
.required(false)
.takes_value(false)
.long("no-header")
)
.arg(
Arg::with_name("sensor")
.value_name("sensor")
.help("Sensor module to apply on the host to get energy consumption metrics.")
.required(false)
.takes_value(true)
.default_value(&sensor_default_value)
.possible_values(&sensors)
.short("s")
.long("sensor")
).arg(
Arg::with_name("sensor-buffer-per-domain-max-kB")
.value_name("sensor-buffer-per-domain-max-kB")
.help("Maximum memory size allowed, in KiloBytes, for storing energy consumption of each domain.")
.required(false)
.takes_value(true)
.default_value("1")
).arg(
Arg::with_name("sensor-buffer-per-socket-max-kB")
.value_name("sensor-buffer-per-socket-max-kB")
.help("Maximum memory size allowed, in KiloBytes, for storing energy consumption of each socket.")
.required(false)
.takes_value(true)
.default_value("1")
).arg(
Arg::with_name("vm")
.value_name("vm")
.help("Tell scaphandre if he is running in a virtual machine.")
.long("vm")
.required(false)
.takes_value(false)
);
for exporter in exporters {
let mut subcmd = SubCommand::with_name(exporter).about(
match exporter {
"stdout" => "Stdout exporter allows you to output the power consumption data in the terminal",
"json" => "JSON exporter allows you to output the power consumption data in a json file",
"prometheus" => "Prometheus exporter exposes power consumption metrics on an http endpoint (/metrics is default) in prometheus accepted format",
"riemann" => "Riemann exporter sends power consumption metrics to a Riemann server",
"qemu" => "Qemu exporter watches all Qemu/KVM virtual machines running on the host and exposes metrics of each of them in a dedicated folder",
"warp10" => "Warp10 exporter sends data to a Warp10 host, through HTTP",
_ => "Unknown exporter",
}
);
let myopts = exporters_options.get(exporter).unwrap();
for opt in myopts {
subcmd = subcmd.arg(opt);
}
matches = matches.subcommand(subcmd);
}
run(matches.get_matches());
}