Skip to main content

PrometheusText

Struct PrometheusText 

Source
pub struct PrometheusText { /* private fields */ }
Expand description

Encodes MetricEvents into Prometheus text exposition format (version 0.0.4).

Output format for a metric with labels:

metric_name{label1="val1",label2="val2"} value timestamp_ms\n

Output format for a metric with no labels:

metric_name value timestamp_ms\n

The timestamp is in milliseconds since the Unix epoch (integer).

Label values are escaped: \\\, "\", newline → \n.

When precision is set, metric values are formatted to the specified number of decimal places (e.g., precision=2 formats 99.60573 as 99.61).

Implementations§

Source§

impl PrometheusText

Source

pub fn new(precision: Option<u8>) -> Self

Create a new PrometheusText encoder.

precision optionally limits the number of decimal places in metric values. None preserves full f64 precision (default behavior).

Trait Implementations§

Source§

impl Default for PrometheusText

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Encoder for PrometheusText

Source§

fn encode_metric( &self, event: &MetricEvent, buf: &mut Vec<u8>, ) -> Result<(), SondaError>

Encode a metric event into Prometheus text exposition format.

Writes the formatted line into buf. Bytes are appended; the buffer is not cleared before writing. Writes into the caller-provided buffer without additional heap allocations.

Source§

fn encode_log( &self, _event: &LogEvent, _buf: &mut Vec<u8>, ) -> Result<(), SondaError>

Encode a log event into the provided buffer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.