vise_exporter/
lib.rs

1//! Metric exporter based on the `hyper` web server / client.
2//!
3//! An exporter scrapes metrics from a [`Registry`](vise::Registry) and allows exporting them to Prometheus by either
4//! running a web server or pushing to the Prometheus push gateway. An exporter should only be initialized
5//! in applications, not libraries.
6//!
7//! # Examples
8//!
9//! Running a pull-based exporter with graceful shutdown:
10//!
11//! ```
12//! use tokio::sync::watch;
13//! use vise_exporter::MetricsExporter;
14//!
15//! async fn my_app() {
16//!     let (shutdown_sender, mut shutdown_receiver) = watch::channel(());
17//!     let exporter = MetricsExporter::default()
18//!         .with_graceful_shutdown(async move {
19//!             shutdown_receiver.changed().await.ok();
20//!         });
21//!     let bind_address = "0.0.0.0:3312".parse().unwrap();
22//!     tokio::spawn(exporter.start(bind_address));
23//!
24//!     // Then, once the app is shutting down:
25//!     shutdown_sender.send_replace(());
26//! }
27//! ```
28//!
29//! Running a push-based exporter that scrapes metrics each 10 seconds:
30//!
31//! ```
32//! # use std::time::Duration;
33//! # use tokio::sync::watch;
34//! # use vise_exporter::MetricsExporter;
35//! async fn my_app() {
36//!     let exporter = MetricsExporter::default();
37//!     let exporter_task = exporter.push_to_gateway(
38//!         "http://prom-gateway/job/pushgateway/instance/my_app".parse().unwrap(),
39//!         Duration::from_secs(10),
40//!     );
41//!     tokio::spawn(exporter_task);
42//! }
43//! ```
44
45// Documentation settings.
46#![doc(html_root_url = "https://docs.rs/vise-exporter/0.3.2")]
47#![cfg_attr(docsrs, feature(doc_cfg))]
48// Linter settings.
49#![warn(missing_debug_implementations, missing_docs, bare_trait_objects)]
50#![warn(clippy::all, clippy::pedantic)]
51#![allow(clippy::must_use_candidate, clippy::module_name_repetitions)]
52
53mod exporter;
54mod metrics;
55
56pub use crate::exporter::{MetricsExporter, MetricsServer};
57
58#[cfg(doctest)]
59doc_comment::doctest!("../README.md");