Bump metrics-recorder-prometheus to 0.2.0

This commit is contained in:
Toby Lawrence 2019-05-01 11:38:49 -04:00
parent b8b3ddfe63
commit 102fa42cee
No known key found for this signature in database
GPG Key ID: 3BB201B0EEE9212E
2 changed files with 13 additions and 5 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "metrics-recorder-prometheus"
version = "0.1.0"
version = "0.2.0"
authors = ["Toby Lawrence <toby@nuclearfurnace.com>"]
edition = "2018"

View File

@ -1,8 +1,8 @@
//! Records metrics in the Prometheus exposition format.
use std::time::SystemTime;
use hdrhistogram::Histogram;
use metrics_core::Recorder;
use metrics_util::{Quantile, parse_quantiles};
use metrics_util::{parse_quantiles, Quantile};
use std::time::SystemTime;
/// Records metrics in the Prometheus exposition format.
pub struct PrometheusRecorder {
@ -16,11 +16,15 @@ impl PrometheusRecorder {
/// Configures the recorder with these default quantiles: 0.0, 0.5, 0.9, 0.95, 0.99, 0.999, and
/// 1.0. If you want to customize the quantiles used, you can call
/// [`PrometheusRecorder::with_quantiles`].
///
/// The configured quantiles are used when rendering any histograms.
pub fn new() -> Self {
Self::with_quantiles(&[0.0, 0.5, 0.9, 0.95, 0.99, 0.999, 1.0])
}
/// Creates a new [`PrometheusRecorder`] with the given set of quantiles.
///
/// The configured quantiles are used when rendering any histograms.
pub fn with_quantiles(quantiles: &[f64]) -> Self {
let actual_quantiles = parse_quantiles(quantiles);
Self {
@ -102,9 +106,13 @@ impl Into<String> for PrometheusRecorder {
}
fn get_prom_expo_header() -> String {
let ts = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)
let ts = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.map(|d| d.as_secs())
.unwrap_or(0);
format!("# metrics snapshot (ts={}) (prometheus exposition format)", ts)
format!(
"# metrics snapshot (ts={}) (prometheus exposition format)",
ts
)
}