Expand description
§rylv-metrics
A high-performance DogStatsD metrics client for Rust with client-side aggregation.
§Features
- High Performance: Lock-free data structures and optimized UDP batching
- Client-Side Aggregation: Reduces network overhead by aggregating metrics before sending
- Multiple Writer Backends: Simple,
LinuxBatch,AppleBatch, and Custom writers - Metric Types: Histograms, Counters, and Gauges
§Quick Start
use rylv_metrics::{
MetricCollector, MetricCollectorOptions, MetricCollectorTrait, RylvStr, SharedCollector,
};
use rylv_metrics::{histogram, count, count_add, gauge};
use std::net::SocketAddr;
use std::time::Duration;
let options = MetricCollectorOptions {
max_udp_packet_size: 1432,
max_udp_batch_size: 10,
flush_interval: Duration::from_secs(10),
writer_type: rylv_metrics::DEFAULT_STATS_WRITER_TYPE,
..Default::default()
};
let bind_addr: SocketAddr = "0.0.0.0:0".parse().unwrap();
let dst_addr: SocketAddr = "127.0.0.1:8125".parse().unwrap();
let inner = SharedCollector::default();
let collector = MetricCollector::new(bind_addr, dst_addr, options, inner).unwrap();
// Direct API — use RylvStr::from_static() for zero-copy aggregation keys
collector.histogram(RylvStr::from_static("request.latency"), 42, &mut [RylvStr::from_static("endpoint:api")]);
collector.count(RylvStr::from_static("request.count"), &mut [RylvStr::from_static("endpoint:api")]);
collector.count_add(RylvStr::from_static("bytes.sent"), 1024, &mut [RylvStr::from_static("endpoint:api")]);
collector.gauge(RylvStr::from_static("connections.active"), 100, &mut [RylvStr::from_static("pool:main")]);
// Convenience macros — allocate on first key insertion, but more ergonomic
histogram!(collector, "request.latency", 42, "endpoint:api");
count!(collector, "request.count", "endpoint:api");
count_add!(collector, "bytes.sent", 1024, "endpoint:api");
gauge!(collector, "connections.active", 100, "pool:main");Macros§
- count
- Macro for incrementing a counter by one with variable number of tags.
- count_
add - Macro for incrementing a counter by a value with variable number of tags.
- count_
add_ prepared - Macro for incrementing a counter by value with a prepared metric key.
- count_
add_ sorted - Macro for incrementing a counter by value with pre-sorted tags.
- count_
prepared - Macro for incrementing a counter by one with a prepared metric key.
- count_
sorted - Macro for incrementing a counter by one with pre-sorted tags.
- gauge
- Macro for recording a gauge value with variable number of tags.
- gauge_
prepared - Macro for recording a gauge value with a prepared metric key.
- gauge_
sorted - Macro for recording a gauge value with pre-sorted tags.
- histogram
- Macro for recording histogram values with variable number of tags.
- histogram_
prepared - Macro for recording histogram values with a prepared metric key.
- histogram_
sorted - Macro for recording histogram values with pre-sorted tags.
- sorted_
tags - Macro for building reusable
SortedTagsbound to a collector’s hasher.
Structs§
- Histogram
Config - Configuration for histogram precision.
- Metric
Frame Ref - Borrowed representation of a drained metric frame.
- Prepared
Metric - Collector-bound precomputed metric key for hot paths.
- SigFig
- Number of significant figures for histogram precision (0..=5).
- Sorted
Tags - Pre-sorted reusable tag set for hot paths.
Enums§
- Histogram
Base Metric - Base histogram metrics that can be emitted alongside configured percentiles.
- Metric
Kind - Metric kind emitted by the drain APIs.
- Metric
Suffix - Suffix descriptor for a borrowed metric frame.
- Metrics
Error - Errors that can occur during metric collection and transmission.
- RylvStr
- A flexible string type that can hold static references, borrowed references, or owned values. Used for metric names and tags.
Traits§
- Drain
Metric Collector Trait - Trait for collectors that support draining aggregated metrics.
- Metric
Collector Trait - Trait defining the interface for metric collection.
Type Aliases§
- Metric
Result - Result type for metric operations.