Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d3be377
feat: adding timestamp to Metric struct
bpetit May 14, 2021
a3fc1e3
style(timestamps): cargo fmt
bpetit May 14, 2021
7547a49
Merge branch 'main' into fix/harmonizing-timestamps
bpetit Sep 21, 2021
65a5595
fix: test configuration
bpetit Sep 21, 2021
22f4ccb
refactor: using metric generator for stdout exporter's host metrics
bpetit Sep 21, 2021
40d456a
fix: power value for individual socket was topology power value
bpetit Sep 21, 2021
7dfc719
fix: sockets/domains now working with metric generator in stdout expo…
bpetit Sep 22, 2021
eeb074e
refactor: process metrics now come from metricgenerator in stdout
bpetit Sep 22, 2021
6767393
fix: missing tab
bpetit Sep 22, 2021
cbaaa3e
feat: add timestamp to process metrics in json exporter
bpetit Sep 22, 2021
c69bccd
feat: adding timestamp to socket metric in json exp
bpetit Sep 22, 2021
593a64e
feat: add timestamp to domains metrics in json exp
bpetit Sep 22, 2021
0528082
style: cargo fmt
bpetit Sep 23, 2021
afeccfd
style: cargo fmt
bpetit Sep 23, 2021
54c70d7
Merge branch 'main' into fix/harmonizing-timestamps
bpetit Sep 27, 2021
dbcd26a
refactor: extracted metric generator from the loop in stdout and json…
bpetit Sep 28, 2021
f0db7a0
fix: using pop_metrics everywhere to avoid duplicates, removing get_m…
bpetit Sep 28, 2021
a707559
fix: removed qemu option for json as it is not useful yet
bpetit Sep 29, 2021
ffa3e8e
docs: removed timestamp metric from docs
bpetit Sep 30, 2021
dfda1dd
chore: lowering trace msg log level
bpetit Sep 30, 2021
cd478bb
fix: topology record timestamp is now the same as the last record of …
bpetit Oct 5, 2021
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
Next Next commit
refactor: using metric generator for stdout exporter's host metrics
  • Loading branch information
bpetit committed Sep 21, 2021
commit 22f4ccb07b0c3647cfaf1389cd7351a3ab0a12eb
14 changes: 14 additions & 0 deletions src/exporters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct Metric {
timestamp: Duration,
}

#[derive(Clone)]
enum MetricValueType {
// IntSigned(i64),
// Float(f32),
Expand All @@ -53,6 +54,18 @@ enum MetricValueType {
IntUnsigned(u64),
}

impl fmt::Display for MetricValueType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self {
// MetricValueType::IntSigned(value) => write!(f, "{}", value),
// MetricValueType::Float(value) => write!(f, "{}", value),
MetricValueType::Text(text) => write!(f, "{}", text),
MetricValueType::FloatDouble(value) => write!(f, "{}", value),
MetricValueType::IntUnsigned(value) => write!(f, "{}", value),
}
}
}

impl fmt::Debug for MetricValueType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self {
Expand All @@ -65,6 +78,7 @@ impl fmt::Debug for MetricValueType {
}
}


/// An Exporter is what tells scaphandre when to collect metrics and how to export
/// or expose them.
/// Its basic role is to instanciate a Sensor, get the data the sensor has to offer
Expand Down
2 changes: 1 addition & 1 deletion src/exporters/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl Exporter for PrometheusExporter {
options.push(arg);

let arg = Arg::with_name("qemu")
.help("Instruct that scaphandre is running on an hypervisor")
.help("Apply labels to metrics of processes looking like a Qemu/KVM virtual machine")
.long("qemu")
.short("q")
.required(false)
Expand Down
39 changes: 29 additions & 10 deletions src/exporters/stdout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ impl Exporter for StdoutExporter {
.takes_value(true);
options.push(arg);

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

options
}
}
Expand Down Expand Up @@ -118,14 +126,14 @@ impl StdoutExporter {
println!("Measurement step is: {}s", step_duration);
if timeout_secs == 0 {
loop {
self.iterate(&regex_filter, process_number);
self.iterate(&regex_filter, process_number, parameters.is_present("qemu"));
thread::sleep(Duration::new(step_duration, 0));
}
} else {
let now = Instant::now();

while now.elapsed().as_secs() <= timeout_secs {
self.iterate(&regex_filter, process_number);
self.iterate(&regex_filter, process_number, parameters.is_present("qemu"));
thread::sleep(Duration::new(step_duration, 0));
}
}
Expand All @@ -151,16 +159,27 @@ impl StdoutExporter {
}
}

fn iterate(&mut self, regex_filter: &Option<Regex>, process_number: u16) {
fn iterate(&mut self, regex_filter: &Option<Regex>, process_number: u16, qemu: bool) {
self.topology.refresh();
self.show_metrics(regex_filter, process_number);
self.show_metrics(regex_filter, process_number, qemu);
}

fn show_metrics(&self, regex_filter: &Option<Regex>, process_number: u16) {
let host_power = match self.topology.get_records_diff_power_microwatts() {
Some(record) => record.value.parse::<u64>().unwrap(),
None => 0,
fn show_metrics(&self, regex_filter: &Option<Regex>, process_number: u16, qemu: bool) {
let hostname = utils::get_hostname();
let mut metric_generator = MetricGenerator::new(&self.topology, &hostname);
metric_generator.gen_all_metrics(qemu);

let metrics = metric_generator.get_metrics();
let mut metrics_iter = metrics.iter();
let host_power = match metrics_iter.find(|x| x.name == "scaph_host_power_microwatts") {
Some(m) => m.metric_value.clone(),
None => MetricValueType::Text("0".to_string())
};
//let host_power = match self.topology.get_records_diff_power_microwatts() {
// Some(record) => record.value.parse::<u64>().unwrap(),
// None => 0,
//};

let mut sockets_power: HashMap<u16, (u64, HashMap<String, Option<Record>>)> =
HashMap::new();
let sockets = self.topology.get_sockets_passive();
Expand All @@ -173,7 +192,7 @@ impl StdoutExporter {
}
let domain_names = self.topology.domains_names.as_ref().unwrap();

println!("Host:\t{} W", (host_power as f32 / 1000000.0));
println!("Host:\t{} W", (format!("{}", host_power).parse::<f64>().unwrap() / 1000000.0));
println!("\tpackage \t{}", domain_names.join("\t\t"));

for (s_id, v) in sockets_power.iter() {
Expand Down Expand Up @@ -222,7 +241,7 @@ impl StdoutExporter {
println!(
"{} W\t{}\t{:?}",
((c.1 as f32 / (host_time * procfs::ticks_per_second().unwrap() as f32))
* host_power as f32)
* format!("{}", host_power).parse::<f32>().unwrap())
/ 1000000.0,
c.0.pid,
c.0.exe().unwrap_or_default()
Expand Down