#prometheus #exporter #tokio #http #hyper


small Tokio/Hyper server to run Prometheus metrics

6 releases

0.1.5 Sep 4, 2022
0.1.4 Mar 31, 2022
0.1.3 Nov 19, 2021
0.1.2 Mar 9, 2021
0.1.1 Feb 15, 2021

#170 in HTTP server

Download history 214/week @ 2023-02-09 227/week @ 2023-02-16 248/week @ 2023-02-23 229/week @ 2023-03-02 373/week @ 2023-03-09 212/week @ 2023-03-16 339/week @ 2023-03-23 248/week @ 2023-03-30 237/week @ 2023-04-06 412/week @ 2023-04-13 187/week @ 2023-04-20 217/week @ 2023-04-27 264/week @ 2023-05-04 308/week @ 2023-05-11 316/week @ 2023-05-18 383/week @ 2023-05-25

1,307 downloads per month
Used in 2 crates

Apache-2.0 OR MIT

177 lines

Crates.io docs.rs pipeline status coverage report license dependencies lines of code


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 this one. Keep in mind there is an vulnerability for tiny-http < 0.8: https://rustsec.org/advisories/RUSTSEC-2020-0031.html

Use this crate when:

  • you write an async app that wants to export metrics
  • want to interact directly with prometheus.
  • don't want to care about the webserver to host the /metrics endpoint

Don't use this crate when:

  • you write a rest-api, in that case you should prob just implement the /metrics endpoint with your rest-framework.
  • you want to avoid tokio.
  • you are writing a library, in that case use plain prometheus and let the binary application decide which HTTP server to use.

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:

prometheus-hyper = "0.1"

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.

    SocketAddr::from(([0; 4], 8080)),

This will start the exporter and bind the http server to 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.


~192K SLoC