Map counters to metrics

This commit is contained in:
Michael Vines 2018-07-07 20:08:14 -07:00 committed by Greg Fitzgerald
parent 3b1aa846b5
commit 0ee86ff313
2 changed files with 12 additions and 0 deletions

View File

@ -1,3 +1,5 @@
use influx_db_client as influxdb;
use metrics;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::Duration;
use timing;
@ -45,6 +47,15 @@ impl Counter {
timing::timestamp(),
);
}
metrics::submit(
influxdb::Point::new(&format!("counter_{}", self.name))
.add_field("count", influxdb::Value::Integer(events as i64))
.add_field(
"duration_ms",
influxdb::Value::Integer(timing::duration_as_ms(&dur) as i64),
)
.to_owned(),
);
}
}
#[cfg(test)]

View File

@ -56,6 +56,7 @@ impl InfluxDbMetricsWriter {
impl MetricsWriter for InfluxDbMetricsWriter {
fn write(&self, points: Vec<influxdb::Point>) {
if let Some(ref client) = self.client {
info!("submitting {} points", points.len());
if let Err(err) = client.write_points(
influxdb::Points { point: points },
Some(influxdb::Precision::Milliseconds),