Struct metrics_exporter_dogstatsd::StatsdBuilder
source · [−]pub struct StatsdBuilder { /* private fields */ }
Expand description
Builder for creating and installing a Statsd recorder/exporter.
Implementations
sourceimpl StatsdBuilder
impl StatsdBuilder
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new StatsdBuilder
.
sourcepub fn with_push_gateway<T>(
self,
endpoint: T,
interval: Duration
) -> Result<Self, BuildError> where
T: AsRef<str>,
pub fn with_push_gateway<T>(
self,
endpoint: T,
interval: Duration
) -> Result<Self, BuildError> where
T: AsRef<str>,
Configures the exporter to push periodic requests to a statsd agent
Errors
If the given endpoint cannot be parsed into a valid SocketAddr, an error variant will be returned describing the error.
sourcepub fn set_quantiles(self, quantiles: &[f64]) -> Result<Self, BuildError>
pub fn set_quantiles(self, quantiles: &[f64]) -> Result<Self, 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.
sourcepub fn set_buckets(self, values: &[f64]) -> Result<Self, BuildError>
pub fn set_buckets(self, values: &[f64]) -> Result<Self, 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 Statsd histograms, instead of summaries.
Errors
If values
is empty, an error variant will be thrown.
sourcepub fn set_buckets_for_metric(
self,
matcher: Matcher,
values: &[f64]
) -> Result<Self, BuildError>
pub fn set_buckets_for_metric(
self,
matcher: Matcher,
values: &[f64]
) -> Result<Self, 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 Statsd 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.
sourcepub fn add_global_tag<K, V>(self, key: K, value: V) -> Self where
K: Into<String>,
V: Into<String>,
pub fn add_global_tag<K, V>(self, key: K, value: V) -> Self where
K: Into<String>,
V: Into<String>,
Adds a global tag to this exporter.
Global tags are applied to all metrics. Tags defined on the metric key itself have precedence over any global tags. If this method is called multiple times, the latest value for a given label key will be used.
sourcepub fn set_max_packet_size(self, size: usize) -> Self
pub fn set_max_packet_size(self, size: usize) -> Self
Sets the maximum size of packets going out to the gateway.
Defaults to 1432 bytes
sourcepub fn set_global_prefix<P>(self, prefix: P) -> Self where
P: Into<String>,
pub fn set_global_prefix<P>(self, prefix: P) -> Self where
P: Into<String>,
Adds a global prefix for every metric name.
Global prefix is applied to all metrics. Its intended use is to introduce a configurable namespace for every metric generated by the application such that different deployments can operate on their own family of metrics without overlap.
sourcepub fn idle_timeout(self, mask: MetricKindMask, timeout: Option<Duration>) -> Self
pub fn idle_timeout(self, mask: MetricKindMask, timeout: Option<Duration>) -> Self
Sets the idle timeout for metrics.
If a metric hasn’t been updated within this timeout, it will be removed from the registry 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.
When a metric is rendered its value is replaced with a “zero-value” for that MetricKind
however any metric with a state “zero-value” will not be rendered and will be cleaned up
when its corresponding idle timeout expires.
sourcepub fn install(self) -> Result<(), BuildError>
pub fn install(self) -> Result<(), BuildError>
Builds the recorder and exporter and installs them globally.
When called from within a Tokio runtime, the exporter future is spawned directly into the runtime. Otherwise, a new single-threaded Tokio runtime is created on a background thread, and the exporter is spawned there.
Errors
If there is an error while either building the recorder and exporter, or installing the recorder and exporter, an error variant will be returned describing the error.
sourcepub fn build(
self
) -> Result<(StatsdRecorder, Pin<Box<dyn Future<Output = Result<()>> + Send + 'static>>), BuildError>
pub fn build(
self
) -> Result<(StatsdRecorder, Pin<Box<dyn Future<Output = Result<()>> + Send + 'static>>), BuildError>
Builds the recorder and exporter and returns them both.
In most cases, users should prefer to use install
to create
and install the recorder and exporter automatically for them. If a caller is combining
recorders, or needs to schedule the exporter to run in a particular way, this method, or
build_recorder
, provide the flexibility to do so.
Panics
This method must be called from within an existing Tokio runtime or it will panic.
Errors
If there is an error while building the recorder and exporter, an error variant will be returned describing the error.
sourcepub fn build_recorder(self) -> StatsdRecorder
pub fn build_recorder(self) -> StatsdRecorder
Builds the recorder and returns it.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for StatsdBuilder
impl Send for StatsdBuilder
impl Sync for StatsdBuilder
impl Unpin for StatsdBuilder
impl UnwindSafe for StatsdBuilder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn 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>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more