Struct vise_exporter::MetricsExporter

source ·
pub struct MetricsExporter<'a> { /* private fields */ }
Expand description

Metrics exporter to Prometheus.

An exporter scrapes metrics from a Registry. A Default exporter will use the registry of all metrics auto-registered in an app and all its (transitive) dependencies, i.e. one created using [Registry::collect()]. To have more granular control over the registry, you can provide it explicitly using Self::new().

§Examples

See crate-level docs for the examples of usage.

Implementations§

source§

impl<'a> MetricsExporter<'a>

source

pub fn new(registry: Arc<Registry>) -> Self

Creates an exporter based on the provided metrics Registry. Note that the registry is in Arc, meaning it can be used elsewhere (e.g., to export data in another format).

source

pub fn with_format(self, format: Format) -> Self

Sets the export Format. By default, Format::OpenMetricsForPrometheus is used (i.e., OpenMetrics text format with minor changes so that it is fully parsed by Prometheus).

See Format docs for more details on differences between export formats. Note that using Format::OpenMetrics is not fully supported by Prometheus at the time of writing.

source

pub fn with_legacy_exporter<F>(self, exporter_fn: F) -> Self
where F: FnOnce(PrometheusBuilder) -> PrometheusBuilder,

Available on crate feature legacy only.

Installs a legacy exporter for the metrics defined using the metrics façade. The specified closure allows customizing the exporter, e.g. specifying buckets for histograms.

The exporter can only be installed once during app lifetime, so if it was installed previously, the same instance will be reused, and the closure won’t be called.

§Panics

If exporter_fn panics, it is propagated to the caller.

source

pub fn with_graceful_shutdown<F>(self, shutdown: F) -> Self
where F: Future<Output = ()> + Send + 'a,

Configures graceful shutdown for the exporter server.

source

pub async fn start(self, bind_address: SocketAddr) -> Result<()>

Starts the server on the specified address. This future resolves when the server is shut down.

The server will expose the following endpoints:

§Errors

Returns an error if binding to the specified address fails.

source

pub fn bind(self, bind_address: SocketAddr) -> Result<MetricsServer<'a>>

Creates an HTTP exporter server and binds it to the specified address.

§Errors

Returns an error if binding to the specified address fails.

source

pub async fn push_to_gateway(self, endpoint: Uri, interval: Duration)

Starts pushing metrics to the endpoint with the specified interval between pushes.

Trait Implementations§

source§

impl Debug for MetricsExporter<'_>

source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for MetricsExporter<'_>

Creates an exporter based on MetricsCollection::default().collect() output (i.e., with all metrics registered by the app and libs it depends on).

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<'a> Freeze for MetricsExporter<'a>

§

impl<'a> !RefUnwindSafe for MetricsExporter<'a>

§

impl<'a> Send for MetricsExporter<'a>

§

impl<'a> !Sync for MetricsExporter<'a>

§

impl<'a> Unpin for MetricsExporter<'a>

§

impl<'a> !UnwindSafe for MetricsExporter<'a>

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

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>,

§

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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more