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