diff --git a/src/exporters/mod.rs b/src/exporters/mod.rs index 04befba1..cfcb4c8d 100644 --- a/src/exporters/mod.rs +++ b/src/exporters/mod.rs @@ -692,7 +692,7 @@ impl MetricGenerator { attributes.insert("exe".to_string(), exe.clone()); if let Some(cmdline_str) = cmdline { - attributes.insert("cmdline".to_string(), cmdline_str.replace("\"", "\\\"")); + attributes.insert("cmdline".to_string(), cmdline_str.replace('"', "\\\"")); if self.qemu { if let Some(vmname) = utils::filter_qemu_cmdline(&cmdline_str) { diff --git a/src/exporters/prometheus.rs b/src/exporters/prometheus.rs index 3911c6e3..9cafd937 100644 --- a/src/exporters/prometheus.rs +++ b/src/exporters/prometheus.rs @@ -194,7 +194,7 @@ fn format_metric(key: &str, value: &str, labels: Option<&HashMap if let Some(labels) = labels { result.push('{'); for (k, v) in labels.iter() { - result.push_str(&format!("{}=\"{}\",", k, v.replace("\"", "_"))); + result.push_str(&format!("{}=\"{}\",", k, v.replace('"', "_"))); } result.remove(result.len() - 1); result.push('}'); diff --git a/src/exporters/riemann.rs b/src/exporters/riemann.rs index 45378e37..29ee41df 100644 --- a/src/exporters/riemann.rs +++ b/src/exporters/riemann.rs @@ -38,17 +38,16 @@ impl RiemannClient { .unwrap() .parse::() .expect("Fail parsing port number"); - let client: Client; - if parameters.is_present("mtls") { + let client: Client = if parameters.is_present("mtls") { let cafile = parameters.value_of("cafile").unwrap(); let certfile = parameters.value_of("certfile").unwrap(); let keyfile = parameters.value_of("keyfile").unwrap(); - client = Client::connect_tls(&address, port, cafile, certfile, keyfile) - .expect("Fail to connect to Riemann server using mTLS"); + Client::connect_tls(&address, port, cafile, certfile, keyfile) + .expect("Fail to connect to Riemann server using mTLS") } else { - client = Client::connect(&(address, port)) - .expect("Fail to connect to Riemann server using raw TCP"); - } + Client::connect(&(address, port)) + .expect("Fail to connect to Riemann server using raw TCP") + }; RiemannClient { client } } @@ -88,7 +87,7 @@ impl RiemannClient { i64::try_from(value).expect("Metric cannot be converted to signed integer."), ), MetricValueType::Text(ref value) => { - let value = value.replace(",", ".").replace("\n", ""); + let value = value.replace(',', ".").replace('\n', ""); if value.contains('.') { event.set_metric_d(value.parse::().expect("Cannot parse metric value.")); } else { @@ -184,7 +183,7 @@ impl Exporter for RiemannExporter { attributes.insert("exe".to_string(), exe.clone()); if let Some(cmdline_str) = cmdline { - attributes.insert("cmdline".to_string(), cmdline_str.replace("\"", "\\\"")); + attributes.insert("cmdline".to_string(), cmdline_str.replace('"', "\\\"")); if parameters.is_present("qemu") { if let Some(vmname) = utils::filter_qemu_cmdline(&cmdline_str) { @@ -197,9 +196,7 @@ impl Exporter for RiemannExporter { // to differentiate services/metrics let metric_name = format!( "{}_{}_{}", - "scaph_process_power_consumption_microwatts", - pid.to_string(), - exe + "scaph_process_power_consumption_microwatts", pid, exe ); if let Some(power) = metric_generator .topology diff --git a/src/exporters/stdout.rs b/src/exporters/stdout.rs index 6f55e638..85be82a3 100644 --- a/src/exporters/stdout.rs +++ b/src/exporters/stdout.rs @@ -99,17 +99,16 @@ impl StdoutExporter { .parse() .expect("Wrong process_number value, should be a number"); - let regex_filter: Option; - if !parameters.is_present("regex_filter") + let regex_filter: Option = if !parameters.is_present("regex_filter") || parameters.value_of("regex_filter").unwrap().is_empty() { - regex_filter = None; + None } else { - regex_filter = Some( + Some( Regex::new(parameters.value_of("regex_filter").unwrap()) .expect("Wrong regex_filter, regexp is invalid"), - ); - } + ) + }; if parameters.occurrences_of("regex_filter") == 1 && parameters.occurrences_of("process_number") == 1 @@ -229,20 +228,20 @@ impl StdoutExporter { println!("{}\n", to_print); } - let consumers: Vec<(procfs::process::Process, u64)>; - if let Some(regex_filter) = regex_filter { - println!("Processes filtered by '{}':", regex_filter.as_str()); - consumers = metric_generator - .topology - .proc_tracker - .get_filtered_processes(regex_filter); - } else { - println!("Top {} consumers:", process_number); - consumers = metric_generator - .topology - .proc_tracker - .get_top_consumers(process_number); - } + let consumers: Vec<(procfs::process::Process, u64)> = + if let Some(regex_filter) = regex_filter { + println!("Processes filtered by '{}':", regex_filter.as_str()); + metric_generator + .topology + .proc_tracker + .get_filtered_processes(regex_filter) + } else { + println!("Top {} consumers:", process_number); + metric_generator + .topology + .proc_tracker + .get_top_consumers(process_number) + }; info!("consumers : {:?}", consumers); println!("Power\t\tPID\tExe"); diff --git a/src/exporters/warpten.rs b/src/exporters/warpten.rs index adfba807..8017ad6d 100644 --- a/src/exporters/warpten.rs +++ b/src/exporters/warpten.rs @@ -19,17 +19,16 @@ impl Exporter for Warp10Exporter { let host = parameters.value_of("host").unwrap(); let scheme = parameters.value_of("scheme").unwrap(); let port = parameters.value_of("port").unwrap(); - let write_token; - if let Some(token) = parameters.value_of("write-token") { - write_token = token.to_owned(); + let write_token = if let Some(token) = parameters.value_of("write-token") { + token.to_owned() } else { - write_token = match env::var("SCAPH_WARP10_WRITE_TOKEN") { + match env::var("SCAPH_WARP10_WRITE_TOKEN") { Ok(val) => val, Err(_e) => panic!( "SCAPH_WARP10_WRITE_TOKEN not found in env, nor write-token flag was used." ), - }; - } + } + }; //let read_token = parameters.value_of("read-token"); let step = parameters.value_of("step").unwrap(); let qemu = parameters.is_present("qemu"); @@ -343,14 +342,12 @@ impl Warp10Exporter { } plabels.push(warp10::Label::new( "cmdline", - &cmdline_str.replace("\"", "\\\""), + &cmdline_str.replace('"', "\\\""), )); } let metric_name = format!( "{}_{}_{}", - "scaph_process_power_consumption_microwats", - pid.to_string(), - exe + "scaph_process_power_consumption_microwats", pid, exe ); if let Some(power) = self.topology.get_process_power_consumption_microwatts(pid) { process_data.push(warp10::Data::new( diff --git a/src/sensors/utils.rs b/src/sensors/utils.rs index 4b1c5a64..95f1b3b8 100644 --- a/src/sensors/utils.rs +++ b/src/sensors/utils.rs @@ -205,7 +205,7 @@ impl ProcessTracker { if let Some(container) = containers.iter().find(|x| x.Id == container_id) { let mut names = String::from(""); for n in &container.Names { - names.push_str(&n.trim().replace("/", "")); + names.push_str(&n.trim().replace('/', "")); } description.insert(String::from("container_names"), names); description.insert(