log to influx once (#1438)

This commit is contained in:
anatoly yakovenko 2018-10-06 14:37:14 -07:00 committed by GitHub
parent d8d8f0bfc8
commit 9350619afa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -72,7 +72,6 @@ impl Counter {
self.lograte.store(lograte, Ordering::Relaxed); self.lograte.store(lograte, Ordering::Relaxed);
} }
if times % lograte == 0 && times > 0 { if times % lograte == 0 && times > 0 {
let lastlog = self.lastlog.load(Ordering::Relaxed);
info!( info!(
"COUNTER:{{\"name\": \"{}\", \"counts\": {}, \"samples\": {}, \"now\": {}, \"events\": {}}}", "COUNTER:{{\"name\": \"{}\", \"counts\": {}, \"samples\": {}, \"now\": {}, \"events\": {}}}",
self.name, self.name,
@ -81,15 +80,20 @@ impl Counter {
timing::timestamp(), timing::timestamp(),
events, events,
); );
metrics::submit(
influxdb::Point::new(&format!("counter-{}", self.name)) let lastlog = self.lastlog.load(Ordering::Relaxed);
.add_field( let prev = self
"count", .lastlog
influxdb::Value::Integer(counts as i64 - lastlog as i64),
).to_owned(),
);
self.lastlog
.compare_and_swap(lastlog, counts, Ordering::Relaxed); .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(),
);
}
} }
} }
} }