From 9350619afa279325c78d86d1a376f8b0aa7dd16a Mon Sep 17 00:00:00 2001 From: anatoly yakovenko Date: Sat, 6 Oct 2018 14:37:14 -0700 Subject: [PATCH] log to influx once (#1438) --- src/counter.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/counter.rs b/src/counter.rs index 3b12e24408..9aa6a33230 100644 --- a/src/counter.rs +++ b/src/counter.rs @@ -72,7 +72,6 @@ impl Counter { self.lograte.store(lograte, Ordering::Relaxed); } if times % lograte == 0 && times > 0 { - let lastlog = self.lastlog.load(Ordering::Relaxed); info!( "COUNTER:{{\"name\": \"{}\", \"counts\": {}, \"samples\": {}, \"now\": {}, \"events\": {}}}", self.name, @@ -81,15 +80,20 @@ impl Counter { timing::timestamp(), events, ); - metrics::submit( - influxdb::Point::new(&format!("counter-{}", self.name)) - .add_field( - "count", - influxdb::Value::Integer(counts as i64 - lastlog as i64), - ).to_owned(), - ); - self.lastlog + + let lastlog = self.lastlog.load(Ordering::Relaxed); + let prev = self + .lastlog .compare_and_swap(lastlog, counts, Ordering::Relaxed); + if prev == lastlog { + metrics::submit( + influxdb::Point::new(&format!("counter-{}", self.name)) + .add_field( + "count", + influxdb::Value::Integer(counts as i64 - lastlog as i64), + ).to_owned(), + ); + } } } }