Skip to content

Commit

Permalink
fix cli output
Browse files Browse the repository at this point in the history
  • Loading branch information
brayniac committed Oct 17, 2023
1 parent 7c87742 commit 1d82755
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 27 deletions.
11 changes: 4 additions & 7 deletions src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl Default for CountersSnapshot {
impl CountersSnapshot {
pub fn new() -> Self {
let mut current = HashMap::new();
let mut previous = HashMap::new();
let previous = HashMap::new();

for metric in metriken::metrics().iter() {
let any = if let Some(any) = metric.as_any() {
Expand All @@ -185,17 +185,14 @@ impl CountersSnapshot {

let metric = metric.name().to_string();

if let Some(counter) = any.downcast_ref::<metriken::Counter>() {
current.insert(metric.clone(), counter.value());
previous.insert(metric, 0);
if let Some(_counter) = any.downcast_ref::<metriken::Counter>() {
current.insert(metric.clone(), 0);
}
}
Self { current, previous }
}

pub fn update(&mut self) {
let mut current = HashMap::new();

for metric in metriken::metrics().iter() {
let any = if let Some(any) = metric.as_any() {
any
Expand All @@ -204,7 +201,7 @@ impl CountersSnapshot {
};

if let Some(counter) = any.downcast_ref::<metriken::Counter>() {
if let Some(old_value) = current.insert(metric.name().to_string(), counter.value())
if let Some(old_value) = self.current.insert(metric.name().to_string(), counter.value())
{
self.previous.insert(metric.name().to_string(), old_value);
}
Expand Down
35 changes: 15 additions & 20 deletions src/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ pub fn log(config: &Config) {
let mut window_id = 0;

let mut snapshot = MetricsSnapshot::default();

let mut prev = Instant::now();
snapshot.update();

let client = !config.workload().keyspaces().is_empty();
let pubsub = !config.workload().topics().is_empty();
Expand All @@ -35,23 +34,19 @@ pub fn log(config: &Config) {
duration = duration.saturating_sub(1);

if interval == 0 {
let now = Instant::now();
let elapsed = now.duration_since(prev).as_secs_f64();
prev = now;

snapshot.update();

output!("-----");
output!("Window: {}", window_id);

// output the client stats
if client {
client_stats(&mut snapshot, elapsed);
client_stats(&mut snapshot);
}

// output the pubsub stats
if pubsub {
pubsub_stats(&mut snapshot, elapsed);
pubsub_stats(&mut snapshot);
}

interval = config.general().interval().as_millis();
Expand All @@ -61,7 +56,7 @@ pub fn log(config: &Config) {
}

/// Outputs client stats
fn client_stats(snapshot: &mut MetricsSnapshot, elapsed: f64) {
fn client_stats(snapshot: &mut MetricsSnapshot) {
let connect_ok = snapshot.counter_rate(CONNECT_OK_COUNTER);
let connect_ex = snapshot.counter_rate(CONNECT_EX_COUNTER);
let connect_timeout = snapshot.counter_rate(CONNECT_TIMEOUT_COUNTER);
Expand Down Expand Up @@ -124,9 +119,9 @@ fn client_stats(snapshot: &mut MetricsSnapshot, elapsed: f64) {
);
output!(
"Client Response Rate (/s): Ok: {:.2} Error: {:.2} Timeout: {:.2}",
response_ok / elapsed,
response_ex / elapsed,
response_timeout / elapsed,
response_ok,
response_ex,
response_timeout,
);

let mut latencies = "Client Response Latency (us):".to_owned();
Expand All @@ -140,7 +135,7 @@ fn client_stats(snapshot: &mut MetricsSnapshot, elapsed: f64) {
}

/// Output pubsub metrics and return the number of successful publish operations
fn pubsub_stats(snapshot: &mut MetricsSnapshot, elapsed: f64) {
fn pubsub_stats(snapshot: &mut MetricsSnapshot) {
// publisher stats
let pubsub_tx_ex = snapshot.counter_rate(PUBSUB_PUBLISH_EX_COUNTER);
let pubsub_tx_ok = snapshot.counter_rate(PUBSUB_PUBLISH_OK_COUNTER);
Expand Down Expand Up @@ -171,9 +166,9 @@ fn pubsub_stats(snapshot: &mut MetricsSnapshot, elapsed: f64) {

output!(
"Publisher Publish Rate (/s): Ok: {:.2} Error: {:.2} Timeout: {:.2}",
pubsub_tx_ok / elapsed,
pubsub_tx_ex / elapsed,
pubsub_tx_timeout / elapsed,
pubsub_tx_ok,
pubsub_tx_ex,
pubsub_tx_timeout,
);

output!("Subscribers: Current: {}", PUBSUB_SUBSCRIBER_CURR.value(),);
Expand All @@ -188,10 +183,10 @@ fn pubsub_stats(snapshot: &mut MetricsSnapshot, elapsed: f64) {

output!(
"Subscriber Receive Rate (/s): Ok: {:.2} Error: {:.2} Corrupt: {:.2} Invalid: {:.2}",
pubsub_rx_ok / elapsed,
pubsub_rx_ex / elapsed,
pubsub_rx_corrupt / elapsed,
pubsub_rx_invalid / elapsed,
pubsub_rx_ok,
pubsub_rx_ex,
pubsub_rx_corrupt,
pubsub_rx_invalid,
);

let mut latencies = "Pubsub Publish Latency (us):".to_owned();
Expand Down

0 comments on commit 1d82755

Please sign in to comment.