diff --git a/metrics-exporter-prometheus/src/lib.rs b/metrics-exporter-prometheus/src/lib.rs index 40ba661..3f62d81 100644 --- a/metrics-exporter-prometheus/src/lib.rs +++ b/metrics-exporter-prometheus/src/lib.rs @@ -13,13 +13,14 @@ use metrics_util::{ parse_quantiles, CompositeKey, Handle, Histogram, MetricKind, Quantile, Registry, }; use parking_lot::RwLock; +use std::collections::HashMap; use std::io; use std::iter::FromIterator; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::sync::Arc; #[cfg(feature = "tokio-exporter")] use std::thread; -use std::{collections::HashMap, time::SystemTime}; +use std::time::SystemTime; use thiserror::Error as ThisError; #[cfg(feature = "tokio-exporter")] use tokio::{pin, runtime, select}; @@ -180,7 +181,15 @@ impl Inner { mut distributions, } = self.get_recent_metrics(); - let mut output = String::new(); + let ts = SystemTime::now() + .duration_since(SystemTime::UNIX_EPOCH) + .map(|d| d.as_secs()) + .unwrap_or(0); + + let mut output = format!( + "# metrics snapshot (ts={}) (prometheus exposition format)\n", + ts + ); let descriptions = self.descriptions.read(); @@ -203,7 +212,6 @@ impl Inner { output.push_str(value.to_string().as_str()); output.push_str("\n"); } - output.push_str("\n"); } for (name, mut by_labels) in gauges.drain() { @@ -225,7 +233,6 @@ impl Inner { output.push_str(value.to_string().as_str()); output.push_str("\n"); } - output.push_str("\n"); } let mut sorted_overrides = self @@ -308,8 +315,6 @@ impl Inner { output.push_str(count.to_string().as_str()); output.push_str("\n"); } - - output.push_str("\n"); } output