Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat/refactor_args
- Finalize refactor.
  • Loading branch information
uggla committed Apr 24, 2021
commit 4506d702857ae1f14c71ddcb031f22fef6dc7c3f
52 changes: 1 addition & 51 deletions src/exporters/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::exporters::*;
use crate::sensors::{Sensor, Topology};
use clap::Arg;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fs;
use std::fs::File;
use std::path::PathBuf;
Expand All @@ -23,56 +22,7 @@ impl Exporter for JSONExporter {
}

/// Returns options needed for that exporter, as a HashMap
fn get_options() -> HashMap<String, ExporterOption> {
let mut options = HashMap::new();
options.insert(
String::from("timeout"),
ExporterOption {
default_value: Some(String::from("10")),
long: String::from("timeout"),
short: String::from("t"),
required: false,
takes_value: true,
help: String::from("Maximum time spent measuring, in seconds."),
},
);
options.insert(
String::from("step_duration"),
ExporterOption {
default_value: Some(String::from("2")),
long: String::from("step"),
short: String::from("s"),
required: false,
takes_value: true,
help: String::from("Set measurement step duration in second."),
},
);
options.insert(
String::from("step_duration_nano"),
ExporterOption {
default_value: Some(String::from("0")),
long: String::from("step_nano"),
short: String::from("n"),
required: false,
takes_value: true,
help: String::from("Set measurement step duration in nano second."),
},
);
options.insert(
String::from("file_path"),
ExporterOption {
default_value: Some(String::from("")),
long: String::from("file"),
short: String::from("f"),
required: false,
takes_value: true,
help: String::from("Destination file for the report."),
},
);
options
}

fn get_options_new() -> Vec<clap::Arg<'static, 'static>> {
fn get_options() -> Vec<clap::Arg<'static, 'static>> {
let mut options = Vec::new();
let arg = Arg::with_name("timeout")
.default_value("10")
Expand Down
18 changes: 1 addition & 17 deletions src/exporters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,7 @@ pub trait Exporter {
/// Entry point for all Exporters
fn run(&mut self, parameters: ArgMatches);
/// Get the options passed via the command line
fn get_options() -> HashMap<String, ExporterOption>;
fn get_options_new() -> Vec<clap::Arg<'static, 'static>>;
}

pub struct ExporterOption {
/// States whether the option is mandatory or not
pub required: bool,
/// Does the option need a value to be specified ?
pub takes_value: bool,
/// The default value, if needed
pub default_value: Option<String>,
/// One letter to identify the option (useful for the CLI)
pub short: String,
/// A word to identify the option
pub long: String,
/// A brief description to explain what the option does
pub help: String,
fn get_options() -> Vec<clap::Arg<'static, 'static>>;
}

/// MetricGenerator is an exporter helper structure to collect Scaphandre metrics.
Expand Down
53 changes: 1 addition & 52 deletions src/exporters/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,58 +56,7 @@ impl Exporter for PrometheusExporter {
}
}
/// Returns options understood by the exporter.
fn get_options() -> HashMap<String, ExporterOption> {
let mut options = HashMap::new();

options.insert(
String::from("address"),
ExporterOption {
default_value: Some(String::from(DEFAULT_IP_ADDRESS)),
help: String::from("ipv6 or ipv4 address to expose the service to"),
long: String::from("address"),
short: String::from("a"),
required: false,
takes_value: true,
},
);
options.insert(
String::from("port"),
ExporterOption {
default_value: Some(String::from("8080")),
help: String::from("TCP port number to expose the service"),
long: String::from("port"),
short: String::from("p"),
required: false,
takes_value: true,
},
);
options.insert(
String::from("suffix"),
ExporterOption {
default_value: Some(String::from("metrics")),
help: String::from("url suffix to access metrics"),
long: String::from("suffix"),
short: String::from("s"),
required: false,
takes_value: true,
},
);
options.insert(
String::from("qemu"),
ExporterOption {
default_value: None,
help: String::from("Instruct that scaphandre is running on an hypervisor"),
long: String::from("qemu"),
short: String::from("q"),
required: false,
takes_value: false,
},
);

options
}

fn get_options_new() -> Vec<clap::Arg<'static, 'static>> {
fn get_options() -> Vec<clap::Arg<'static, 'static>> {
let mut options = Vec::new();
let arg = Arg::with_name("address")
.default_value(DEFAULT_IP_ADDRESS)
Expand Down
7 changes: 1 addition & 6 deletions src/exporters/qemu.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::exporters::Exporter;
use crate::sensors::{utils::ProcessRecord, Sensor, Topology};
use std::collections::HashMap;
use std::{fs, io, thread, time};

/// An Exporter that extracts power consumption data of running
Expand Down Expand Up @@ -35,11 +34,7 @@ impl Exporter for QemuExporter {
}
}

fn get_options() -> HashMap<String, super::ExporterOption> {
HashMap::new()
}

fn get_options_new() -> Vec<clap::Arg<'static, 'static>> {
fn get_options() -> Vec<clap::Arg<'static, 'static>> {
Vec::new()
}
}
Expand Down
53 changes: 1 addition & 52 deletions src/exporters/riemann.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,58 +211,7 @@ impl Exporter for RiemannExporter {
}

/// Returns options understood by the exporter.
fn get_options() -> HashMap<String, ExporterOption> {
let mut options = HashMap::new();

options.insert(
String::from("address"),
ExporterOption {
default_value: Some(String::from(DEFAULT_IP_ADDRESS)),
help: String::from("Riemann ipv6 or ipv4 address"),
long: String::from("address"),
short: String::from("a"),
required: false,
takes_value: true,
},
);
options.insert(
String::from("port"),
ExporterOption {
default_value: Some(String::from(DEFAULT_PORT)),
help: String::from("Riemann TCP port number"),
long: String::from("port"),
short: String::from("p"),
required: false,
takes_value: true,
},
);
options.insert(
String::from("dispatch_duration"),
ExporterOption {
default_value: Some(String::from("5")),
help: String::from("Duration between metrics dispatch"),
long: String::from("dispatch"),
short: String::from("d"),
required: false,
takes_value: true,
},
);
options.insert(
String::from("qemu"),
ExporterOption {
default_value: None,
help: String::from("Instruct that scaphandre is running on an hypervisor"),
long: String::from("qemu"),
short: String::from("q"),
required: false,
takes_value: false,
},
);

options
}

fn get_options_new() -> Vec<clap::Arg<'static, 'static>> {
fn get_options() -> Vec<clap::Arg<'static, 'static>> {
let mut options = Vec::new();
let arg = Arg::with_name("address")
.default_value(DEFAULT_IP_ADDRESS)
Expand Down
29 changes: 1 addition & 28 deletions src/exporters/stdout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,7 @@ impl Exporter for StdoutExporter {
}

/// Returns options needed for that exporter, as a HashMap
fn get_options() -> HashMap<String, ExporterOption> {
let mut options = HashMap::new();
options.insert(
String::from("timeout"),
ExporterOption {
default_value: Some(String::from("10")),
long: String::from("timeout"),
short: String::from("t"),
required: false,
takes_value: true,
help: String::from("Maximum time spent measuring, in seconds."),
},
);
options.insert(
String::from("step_duration"),
ExporterOption {
default_value: Some(String::from("2")),
long: String::from("step"),
short: String::from("s"),
required: false,
takes_value: true,
help: String::from("Set measurement step duration in second."),
},
);
options
}

fn get_options_new() -> Vec<clap::Arg<'static, 'static>> {
fn get_options() -> Vec<clap::Arg<'static, 'static>> {
let mut options = Vec::new();
let arg = Arg::with_name("timeout")
.default_value("10")
Expand Down
87 changes: 1 addition & 86 deletions src/exporters/warpten.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::exporters::*;
use crate::sensors::{RecordGenerator, Sensor, Topology};
use clap::Arg;
use std::collections::HashMap;
use std::time::Duration;
use std::{env, thread};
use utils::get_scaphandre_version;
Expand Down Expand Up @@ -52,91 +51,7 @@ impl Exporter for Warp10Exporter {
}

/// Options for configuring the exporter.
fn get_options() -> HashMap<String, super::ExporterOption> {
let mut options = HashMap::new();

options.insert(
String::from("host"),
ExporterOption {
default_value: Some(String::from("localhost")),
help: String::from("Warp10 host's FQDN or IP address to send data to"),
long: String::from("host"),
short: String::from("H"),
required: false,
takes_value: true,
},
);
options.insert(
String::from("scheme"),
ExporterOption {
default_value: Some(String::from("http")),
help: String::from("Either 'http' or 'https'"),
long: String::from("scheme"),
short: String::from("s"),
required: false,
takes_value: true,
},
);
options.insert(
String::from("port"),
ExporterOption {
default_value: Some(String::from("8080")),
help: String::from("TCP port to join Warp10 on the host"),
long: String::from("port"),
short: String::from("p"),
required: false,
takes_value: true,
},
);
options.insert(
String::from("write-token"),
ExporterOption {
default_value: None,
help: String::from("Auth. token to write on Warp10"),
long: String::from("write-token"),
short: String::from("t"),
required: false,
takes_value: true,
},
);
//options.insert(
// String::from("read-token"),
// ExporterOption {
// default_value: None,
// help: String::from("Auth. token to read on Warp10"),
// long: String::from("read-token"),
// short: String::from("r"),
// required: false,
// takes_value: true,
// },
//);
options.insert(
String::from("step"),
ExporterOption {
default_value: Some(String::from("30")),
help: String::from("Time step between measurements, in seconds."),
long: String::from("step"),
short: String::from("S"),
required: false,
takes_value: true,
},
);
options.insert(
String::from("qemu"),
ExporterOption {
default_value: None,
help: String::from("Tells scaphandre it is running on a Qemu hypervisor."),
long: String::from("qemu"),
short: String::from("q"),
required: false,
takes_value: false,
},
);

options
}

fn get_options_new() -> Vec<clap::Arg<'static, 'static>> {
fn get_options() -> Vec<clap::Arg<'static, 'static>> {
let mut options = Vec::new();
let arg = Arg::with_name("host")
.default_value("localhost")
Expand Down
Loading