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>
impl<'a> MetricsExporter<'a>
sourcepub fn new(registry: Arc<Registry>) -> Self
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).
sourcepub fn with_format(self, format: Format) -> Self
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.
sourcepub fn with_legacy_exporter<F>(self, exporter_fn: F) -> Selfwhere
F: FnOnce(PrometheusBuilder) -> PrometheusBuilder,
Available on crate feature legacy
only.
pub fn with_legacy_exporter<F>(self, exporter_fn: F) -> Selfwhere
F: FnOnce(PrometheusBuilder) -> PrometheusBuilder,
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.
sourcepub fn with_graceful_shutdown<F>(self, shutdown: F) -> Self
pub fn with_graceful_shutdown<F>(self, shutdown: F) -> Self
Configures graceful shutdown for the exporter server.
sourcepub async fn start(self, bind_address: SocketAddr) -> Result<()>
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:
GET
on any path: serves the metrics in the text format configured usingSelf::with_format()
§Errors
Returns an error if binding to the specified address fails.
sourcepub fn bind(self, bind_address: SocketAddr) -> Result<MetricsServer<'a>>
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.
sourcepub async fn push_to_gateway(self, endpoint: Uri, interval: Duration)
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<'_>
impl Debug for MetricsExporter<'_>
source§impl Default for MetricsExporter<'_>
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).