Brussels / 2 & 3 February 2019


Introducing rust-prometheus

How Rust makes metrics safe and fast

This talk is to give a brief introduction to the rust-prometheus library, which is a Rust client for Prometheus, a monitoring and alerting toolkit. After a brief look at basic usage, this talk will dive into how Rust features make the library safe and fast. Finally, we will discuss some ways to use Procedural Macros to reduce metric lookup by over 10x via generated static lookups.

Intended audience: Rust beginner


  1. Introduction (5 min)
    • Self introduction
    • What is Rust-Prometheus: A brief introduction to Prometheus and the client library
    • How to use: A short example of using the library to collect different kind of metrics
  2. How Rust Shines
    • Safe (5 min)
      • Why we care about safety
      • Type-safe generic labels: Use generic label length so that label length can be checked at compile time.
      • Rust’s Send & Sync markers
      • Rust’s #[must_use] attribute
    • Fast (5 min)
      • Why we care about performance
      • Local !Sync metrics: Shared global metrics across threads is not efficient, e.g. causing cache eviction. Local metrics to solve under the cost of normal variables!
      • Static metric vectors via proc_macros: A macro to provide efficient metric vectors.
  3. How static metric macro is implemented (10 min)
    • A small explanation of the macro implementation so that listeners will have a blueprint about the capability and the approach of Rust procedural macros.
    • Benchmarks showing speed difference.
  4. Future Plan (2 min)
    • Thread-local metrics: Enables seamlessly local metrics and less contention
    • More metrics, like Prometheus Summary
    • A more consistent API
    • Metrics pulling
    • Contributions are welcome!
  5. Production Use Case (5 min)


Wish Shi