Struct PrometheusBuilder
pub struct PrometheusBuilder { /* private fields */ }
Expand description
Builder for creating and installing a Prometheus recorder/exporter.
Implementations§
§impl PrometheusBuilder
impl PrometheusBuilder
pub fn new() -> PrometheusBuilder
pub fn new() -> PrometheusBuilder
Creates a new PrometheusBuilder
.
pub fn set_quantiles(
self,
quantiles: &[f64],
) -> Result<PrometheusBuilder, BuildError>
pub fn set_quantiles( self, quantiles: &[f64], ) -> Result<PrometheusBuilder, BuildError>
Sets the quantiles to use when rendering histograms.
Quantiles represent a scale of 0 to 1, where percentiles represent a scale of 1 to 100, so a quantile of 0.99 is the 99th percentile, and a quantile of 0.99 is the 99.9th percentile.
Defaults to a hard-coded set of quantiles: 0.0, 0.5, 0.9, 0.95, 0.99, 0.999, and 1.0. This means that all histograms will be exposed as Prometheus summaries.
If buckets are set (via set_buckets
or
set_buckets_for_metric
) then all histograms will be exposed
as summaries instead.
§Errors
If quantiles
is empty, an error variant will be thrown.
pub fn set_bucket_duration(
self,
value: Duration,
) -> Result<PrometheusBuilder, BuildError>
pub fn set_bucket_duration( self, value: Duration, ) -> Result<PrometheusBuilder, BuildError>
Sets the bucket width when using summaries.
Summaries are rolling, which means that they are divided into buckets of a fixed duration (width), and older buckets are dropped as they age out. This means data from a period as large as the width will be dropped at a time.
The total amount of data kept for a summary is the number of buckets times the bucket width. For example, a bucket count of 3 and a bucket width of 20 seconds would mean that 60 seconds of data is kept at most, with the oldest 20 second chunk of data being dropped as the summary rolls forward.
Use more buckets with a smaller width to roll off smaller amounts of data at a time, or fewer buckets with a larger width to roll it off in larger chunks.
Defaults to 20 seconds.
§Errors
If the duration given is zero, an error variant will be thrown.
pub fn set_bucket_count(self, count: NonZero<u32>) -> PrometheusBuilder
pub fn set_bucket_count(self, count: NonZero<u32>) -> PrometheusBuilder
Sets the bucket count when using summaries.
Summaries are rolling, which means that they are divided into buckets of a fixed duration (width), and older buckets are dropped as they age out. This means data from a period as large as the width will be dropped at a time.
The total amount of data kept for a summary is the number of buckets times the bucket width. For example, a bucket count of 3 and a bucket width of 20 seconds would mean that 60 seconds of data is kept at most, with the oldest 20 second chunk of data being dropped as the summary rolls forward.
Use more buckets with a smaller width to roll off smaller amounts of data at a time, or fewer buckets with a larger width to roll it off in larger chunks.
Defaults to 3.
pub fn set_buckets(
self,
values: &[f64],
) -> Result<PrometheusBuilder, BuildError>
pub fn set_buckets( self, values: &[f64], ) -> Result<PrometheusBuilder, BuildError>
Sets the buckets to use when rendering histograms.
Buckets values represent the higher bound of each buckets. If buckets are set, then all histograms will be rendered as true Prometheus histograms, instead of summaries.
§Errors
If values
is empty, an error variant will be thrown.
pub fn set_buckets_for_metric(
self,
matcher: Matcher,
values: &[f64],
) -> Result<PrometheusBuilder, BuildError>
pub fn set_buckets_for_metric( self, matcher: Matcher, values: &[f64], ) -> Result<PrometheusBuilder, BuildError>
Sets the bucket for a specific pattern.
The match pattern can be a full match (equality), prefix match, or suffix match. The matchers are applied in that order if two or more matchers would apply to a single metric. That is to say, if a full match and a prefix match applied to a metric, the full match would win, and if a prefix match and a suffix match applied to a metric, the prefix match would win.
Buckets values represent the higher bound of each buckets. If buckets are set, then any histograms that match will be rendered as true Prometheus histograms, instead of summaries.
This option changes the observer’s output of histogram-type metric into summaries.
It only affects matching metrics if set_buckets
was not used.
§Errors
If values
is empty, an error variant will be thrown.
pub fn idle_timeout(
self,
mask: MetricKindMask,
timeout: Option<Duration>,
) -> PrometheusBuilder
pub fn idle_timeout( self, mask: MetricKindMask, timeout: Option<Duration>, ) -> PrometheusBuilder
Sets the idle timeout for metrics.
If a metric hasn’t been updated within this timeout, it will be removed from the registry and in turn removed from the normal scrape output until the metric is emitted again. This behavior is driven by requests to generate rendered output, and so metrics will not be removed unless a request has been made recently enough to prune the idle metrics.
Further, the metric kind “mask” configures which metrics will be considered by the idle timeout. If the kind of a metric being considered for idle timeout is not of a kind represented by the mask, it will not be affected, even if it would have othered been removed for exceeding the idle timeout.
Refer to the documentation for MetricKindMask
for more
information on defining a metric kind mask.
pub fn upkeep_timeout(self, timeout: Duration) -> PrometheusBuilder
pub fn upkeep_timeout(self, timeout: Duration) -> PrometheusBuilder
Sets the upkeep interval.
The upkeep task handles periodic maintenance operations, such as draining histogram data, to ensure that all recorded data is up-to-date and prevent unbounded memory growth.
pub fn add_global_label<K, V>(self, key: K, value: V) -> PrometheusBuilder
pub fn add_global_label<K, V>(self, key: K, value: V) -> PrometheusBuilder
Adds a global label to this exporter.
Global labels are applied to all metrics. Labels defined on the metric key itself have precedence over any global labels. If this method is called multiple times, the latest value for a given label key will be used.
pub fn install_recorder(self) -> Result<PrometheusHandle, BuildError>
pub fn install_recorder(self) -> Result<PrometheusHandle, BuildError>
Builds the recorder and installs it globally, returning a handle to it.
The handle can be used to generate valid Prometheus scrape endpoint payloads directly.
§Errors
If there is an error while building the recorder, or installing the recorder, an error variant will be returned describing the error.
pub fn build_recorder(self) -> PrometheusRecorder
pub fn build_recorder(self) -> PrometheusRecorder
Builds the recorder and returns it.
Trait Implementations§
§impl Debug for PrometheusBuilder
impl Debug for PrometheusBuilder
§impl Default for PrometheusBuilder
impl Default for PrometheusBuilder
§fn default() -> PrometheusBuilder
fn default() -> PrometheusBuilder
Auto Trait Implementations§
impl Freeze for PrometheusBuilder
impl RefUnwindSafe for PrometheusBuilder
impl Send for PrometheusBuilder
impl Sync for PrometheusBuilder
impl Unpin for PrometheusBuilder
impl UnwindSafe for PrometheusBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<T> MaybeSend for Twhere
T: Send,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 224 bytes