Aetos
A Rust proc macro library for generating Prometheus metrics rendering code from annotated structs.
Quick Start
use ;
use HashMap;
// Optional prefix for all metrics
let metrics = MyMetrics ;
println!;
This outputs:
# HELP myapp_requests_total Total requests
# TYPE myapp_requests_total counter
myapp_requests_total 1000
# HELP myapp_events Events by type
# TYPE myapp_events counter
myapp_events{event_type="add"} 10
myapp_events{event_type="remove"} 5
# HELP myapp_http_requests HTTP requests by method and status
# TYPE myapp_http_requests counter
myapp_http_requests{method="GET",status="200"} 150
myapp_http_requests{method="POST",status="404"} 3
Collection Types
Labeled metrics accept anything that implements IntoIterator<&(K, V)> or IntoIterator<(&K, &V)> (Vec, HashMap, BTreeMap, slices, etc.).
- Single label:
KimplementsDisplay - Multiple labels:
KimplementsLabel
Override Metric Names
Use the name attribute to export a different metric name than the field name (see Quick Start example).
Histograms
Histograms track value distributions across predefined buckets:
use ;
// Labeled histogram
define_histogram!;
// Unlabeled histogram
define_histogram!;
let mut m = Metrics ;
m.response_time.observe;
m.queue_time.observe;
println!;
If you don't want to manually specify buckets, you can use these functions to generate them
use ;
define_histogram!;
// Generates buckets: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
use ;
define_histogram!;
// Generates buckets: [0.001, 0.002, 0.004, 0.008, 0.016, 0.032, 0.064, 0.128]