Crates.io | prometheus-hyper |
lib.rs | prometheus-hyper |
version | 0.2.0 |
source | src |
created_at | 2021-02-12 19:05:46.830732 |
updated_at | 2024-05-28 20:26:30.675799 |
description | small Tokio/Hyper server to run Prometheus metrics |
homepage | https://gitlab.com/xMAC94x/prometheus-hyper |
repository | https://gitlab.com/xMAC94x/prometheus-hyper |
max_upload_size | |
id | 354323 |
size | 51,069 |
Helper library to export prometheus metrics using tokio and hyper. It's intended to help writing prometheus exporters without the need to setup and maintain a http (no https) webserver. If the program also uses a http server for other purposes this package is probably not the best way and prometheus should be used directly.
This crate is similar to prometheus_exporter.
If you are not in a tokio
environment you might choose that one.
Use this crate when:
/metrics
endpointDon't use this crate when:
/metrics
endpoint with your rest-framework.tokio
.This crate optimizes for typical metrics scraping, e.g. a scrape interval by few prometheus instances (usually 1) with a usual interval (e.g. 1s). It's optimized for a low foot-print, rather than being able to serve 100.000 metrics requests per sec.
Add this to your Cargo.toml
:
[dependencies]
prometheus-hyper = "0.2"
The crate exports a single struct Server
with a single fn run
:
Pass your registry to the server, and provide it with a shutdown_future.
The server will shut down, once the future completes.
tokio::spawn(Server::run(
Arc::clone(®istry),
SocketAddr::from(([0; 4], 8080)),
std::future::pending(),
));
This will start the exporter and bind the http server to 0.0.0.0:8080
. After
that you can just update the metrics as you used to.
See the documentation and the examples for more information on how to use this crate.