pub struct MetricsEncoder<W: Write> { /* private fields */ }
Expand description
MetricsEncoder
provides methods to encode metrics in a text format
that can be understood by Prometheus.
Metrics are encoded with the block time included, to allow Prometheus to discard out-of-order samples collected from replicas that are behind.
See Exposition Formats for an informal specification of the text format.
Implementations§
Source§impl<W: Write> MetricsEncoder<W>
impl<W: Write> MetricsEncoder<W>
Sourcepub fn new(writer: W, now_millis: i64) -> Self
pub fn new(writer: W, now_millis: i64) -> Self
Constructs a new encoder dumping metrics with the given timestamp into the specified writer.
Sourcepub fn into_inner(self) -> W
pub fn into_inner(self) -> W
Returns the internal buffer that was used to record the metrics.
Sourcepub fn encode_histogram(
&mut self,
name: &str,
buckets: impl Iterator<Item = (f64, f64)>,
sum: f64,
help: &str,
) -> Result<()>
pub fn encode_histogram( &mut self, name: &str, buckets: impl Iterator<Item = (f64, f64)>, sum: f64, help: &str, ) -> Result<()>
Encodes the metadata and the value of a histogram.
SUM is the sum of all observed values, before they were put into buckets.
BUCKETS is a list (key, value) pairs, where KEY is the bucket and VALUE is the number of items in this bucket (i.e., it’s not a cumulative value).
pub fn histogram_vec<'a>( &'a mut self, name: &'a str, help: &'a str, ) -> Result<LabeledHistogramBuilder<'a, W>>
pub fn encode_single_value( &mut self, typ: &str, name: &str, value: f64, help: &str, ) -> Result<()>
Sourcepub fn encode_counter(
&mut self,
name: &str,
value: f64,
help: &str,
) -> Result<()>
pub fn encode_counter( &mut self, name: &str, value: f64, help: &str, ) -> Result<()>
Encodes the metadata and the value of a counter.
§Panics
This function panics if the name
argument does not match pattern [a-zA-Z_][a-zA-Z0-9_].
Sourcepub fn encode_gauge(&mut self, name: &str, value: f64, help: &str) -> Result<()>
pub fn encode_gauge(&mut self, name: &str, value: f64, help: &str) -> Result<()>
Encodes the metadata and the value of a gauge.
§Panics
This function panics if the name
argument does not match pattern [a-zA-Z_][a-zA-Z0-9_].