Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump dependencies release #234

Merged
merged 6 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
806 changes: 452 additions & 354 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ homepage = "https://hubblo-org.github.io/scaphandre-documentation"
[dependencies]
loggerv = "0.7.2"
log = "0.4"
clap = "2.33.3"
regex = "1"
# clap string feature is required to allow dynamic values otherwise it ended up with a lifetime pb.
# https://docs.rs/clap/4.0.19/clap/builder/struct.Str.html
clap = { version = "4.0.18", features = ["cargo", "string"] }
regex = "1.7.0"
riemann_client = { version = "0.9.0", optional = true }
hostname = "0.3.1"
protobuf = "2.20.0"
protobuf = "2.28.0"
serde = { version = "1.0", features = ["derive"], optional = true }
serde_json = { version = "1.0", optional = true }
ordered-float = "2.0"
warp10 = { version = "1.0.0", optional = true }
rand = { version = "0.7.3" }
#time = { version = "0.3.11", features = ["std"] }
#time blocked because used by chrono and warp10
time = "0.2.25"
colored = "2.0.0"
chrono = "0.4.19"
Expand All @@ -34,6 +38,7 @@ tokio = { version = "1.26.0", features = ["full"], optional = true}
sysinfo = { version = "0.28.3"}

[target.'cfg(target_os="linux")'.dependencies]
#procfs = "0.13.2"
procfs = { version = "0.12.0" }

[target.'cfg(target_os="windows")'.dependencies]
Expand Down
63 changes: 31 additions & 32 deletions src/exporters/json.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::exporters::*;
use crate::sensors::Sensor;
use clap::Arg;
use clap::{value_parser, Arg};
use colored::*;
use regex::Regex;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -28,50 +28,54 @@ impl Exporter for JSONExporter {

/// Returns options needed for that exporter, as a HashMap

fn get_options() -> Vec<clap::Arg<'static, 'static>> {
fn get_options() -> Vec<clap::Arg> {
let mut options = Vec::new();
let arg = Arg::with_name("timeout")
let arg = Arg::new("timeout")
.help("Maximum time spent measuring, in seconds.")
.long("timeout")
.short("t")
.short('t')
.required(false)
.takes_value(true);
.value_parser(value_parser!(u64))
.action(clap::ArgAction::Set);
options.push(arg);

let arg = Arg::with_name("step_duration")
let arg = Arg::new("step_duration")
.default_value("2")
.help("Set measurement step duration in second.")
.long("step")
.short("s")
.short('s')
.required(false)
.takes_value(true);
.value_parser(value_parser!(u64))
.action(clap::ArgAction::Set);
options.push(arg);

let arg = Arg::with_name("step_duration_nano")
let arg = Arg::new("step_duration_nano")
.default_value("0")
.help("Set measurement step duration in nano second.")
.long("step_nano")
.short("n")
.short('n')
.required(false)
.takes_value(true);
.value_parser(value_parser!(u32))
.action(clap::ArgAction::Set);
options.push(arg);

let arg = Arg::with_name("file_path")
let arg = Arg::new("file_path")
.default_value("")
.help("Destination file for the report.")
.long("file")
.short("f")
.short('f')
.required(false)
.takes_value(true);
.action(clap::ArgAction::Set);
options.push(arg);

let arg = Arg::with_name("max_top_consumers")
let arg = Arg::new("max_top_consumers")
.default_value("10")
.help("Maximum number of processes to watch.")
.long("max-top-consumers")
.short("m")
.short('m')
.required(false)
.takes_value(true);
.value_parser(value_parser!(u16))
.action(clap::ArgAction::Set);
options.push(arg);

#[cfg(feature = "containers")]
Expand Down Expand Up @@ -117,7 +121,6 @@ impl Exporter for JSONExporter {
// .required(false)
// .takes_value(false);
//options.push(arg);

options
}
}
Expand Down Expand Up @@ -211,21 +214,17 @@ impl JSONExporter {
let mut metric_generator = MetricGenerator::new(
topology,
utils::get_hostname(),
parameters.is_present("qemu"),
parameters.is_present("containers"),
parameters.get_flag("qemu"),
parameters.get_flag("containers"),
);

// We have a default value of 2s so it is safe to unwrap the option
// Panic if a non numerical value is passed
let step_duration: u64 = parameters
.value_of("step_duration")
.unwrap()
.parse()
let step_duration: u64 = *parameters
.get_one("step_duration")
.expect("Wrong step_duration value, should be a number of seconds");
let step_duration_nano: u32 = parameters
.value_of("step_duration_nano")
.unwrap()
.parse()
let step_duration_nano: u32 = *parameters
.get_one("step_duration_nano")
.expect("Wrong step_duration_nano value, should be a number of nano seconds");

self.regex = if !parameters.is_present("regex_filter")
Expand Down Expand Up @@ -255,10 +254,10 @@ impl JSONExporter {
}

info!("Measurement step is: {}s", step_duration);
if let Some(timeout) = parameters.value_of("timeout") {
if let Some(timeout) = parameters.get_one::<u64>("timeout") {
let now = Instant::now();

let timeout_secs: u64 = timeout.parse().unwrap();
let timeout_secs: u64 = *timeout;
while now.elapsed().as_secs() <= timeout_secs {
self.iterate(&parameters, &mut metric_generator);
thread::sleep(Duration::new(step_duration, step_duration_nano));
Expand Down Expand Up @@ -431,7 +430,7 @@ impl JSONExporter {
consumption: format!("{}", metric.metric_value).parse::<f32>().unwrap(),
resources_usage: None,
timestamp: metric.timestamp.as_secs_f64(),
container: match parameters.is_present("containers") {
container: match parameters.get_flag("containers") {
true => metric.attributes.get("container_id").map(|container_id| {
Container {
id: String::from(container_id),
Expand Down Expand Up @@ -561,7 +560,7 @@ impl JSONExporter {
sockets: all_sockets,
};

let file_path = parameters.value_of("file_path").unwrap();
let file_path = parameters.get_one::<String>("file_path").unwrap();
// Print json
if file_path.is_empty() {
let json: String =
Expand Down
2 changes: 1 addition & 1 deletion src/exporters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,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() -> Vec<clap::Arg<'static, 'static>>;
fn get_options() -> Vec<clap::Arg>;
}

/// MetricGenerator is an exporter helper structure to collect Scaphandre metrics.
Expand Down
52 changes: 26 additions & 26 deletions src/exporters/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,80 +50,80 @@ impl Exporter for PrometheusExporter {

runner(
(*self.sensor.get_topology()).unwrap(),
parameters.value_of("address").unwrap().to_string(),
parameters.value_of("port").unwrap().to_string(),
parameters.value_of("suffix").unwrap().to_string(),
parameters.is_present("qemu"),
parameters.is_present("containers"),
parameters.get_one::<String>("address").unwrap().to_string(),
parameters.get_one::<String>("port").unwrap().to_string(),
parameters.get_one::<String>("suffix").unwrap().to_string(),
parameters.get_flag("qemu"),
parameters.get_flag("containers"),
get_hostname(),
);
}
/// Returns options understood by the exporter.
fn get_options() -> Vec<clap::Arg<'static, 'static>> {
fn get_options() -> Vec<clap::Arg> {
let mut options = Vec::new();
let arg = Arg::with_name("address")
let arg = Arg::new("address")
.default_value(DEFAULT_IP_ADDRESS)
.help("ipv6 or ipv4 address to expose the service to")
.long("address")
.short("a")
.short('a')
.required(false)
.takes_value(true);
.action(clap::ArgAction::Set);
options.push(arg);

let arg = Arg::with_name("port")
let arg = Arg::new("port")
.default_value("8080")
.help("TCP port number to expose the service")
.long("port")
.short("p")
.short('p')
.required(false)
.takes_value(true);
.action(clap::ArgAction::Set);
options.push(arg);

let arg = Arg::with_name("suffix")
let arg = Arg::new("suffix")
.default_value("metrics")
.help("url suffix to access metrics")
.long("suffix")
.short("s")
.short('s')
.required(false)
.takes_value(true);
.action(clap::ArgAction::Set);
options.push(arg);

let arg = Arg::with_name("qemu")
let arg = Arg::new("qemu")
.help("Apply labels to metrics of processes looking like a Qemu/KVM virtual machine")
.long("qemu")
.short("q")
.short('q')
.required(false)
.takes_value(false);
.action(clap::ArgAction::SetTrue);
options.push(arg);

let arg = Arg::with_name("containers")
let arg = Arg::new("containers")
.help("Monitor and apply labels for processes running as containers")
.long("containers")
.required(false)
.takes_value(false);
.action(clap::ArgAction::SetTrue);
options.push(arg);

let arg = Arg::with_name("kubernetes_host")
let arg = Arg::new("kubernetes_host")
.help("FQDN of the kubernetes API server")
.long("kubernetes-host")
.required(false)
.takes_value(true);
.action(clap::ArgAction::Set);
options.push(arg);

let arg = Arg::with_name("kubernetes_scheme")
let arg = Arg::new("kubernetes_scheme")
.help("Protocol used to access kubernetes API server")
.long("kubernetes-scheme")
.default_value("http")
.required(false)
.takes_value(true);
.action(clap::ArgAction::Set);
options.push(arg);

let arg = Arg::with_name("kubernetes_port")
let arg = Arg::new("kubernetes_port")
.help("Kubernetes API server port number")
.long("kubernetes-port")
.default_value("6443")
.required(false)
.takes_value(true);
.action(clap::ArgAction::Set);
options.push(arg);

options
Expand Down
2 changes: 1 addition & 1 deletion src/exporters/qemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Exporter for QemuExporter {
}
}

fn get_options() -> Vec<clap::Arg<'static, 'static>> {
fn get_options() -> Vec<clap::Arg> {
Vec::new()
}
}
Expand Down
Loading