Skip to main content

Crate rylv_metrics

Crate rylv_metrics 

Source
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 SortedTags bound to a collector’s hasher.

Structs§

HistogramConfig
Configuration for histogram precision.
MetricFrameRef
Borrowed representation of a drained metric frame.
PreparedMetric
Collector-bound precomputed metric key for hot paths.
SigFig
Number of significant figures for histogram precision (0..=5).
SortedTags
Pre-sorted reusable tag set for hot paths.

Enums§

HistogramBaseMetric
Base histogram metrics that can be emitted alongside configured percentiles.
MetricKind
Metric kind emitted by the drain APIs.
MetricSuffix
Suffix descriptor for a borrowed metric frame.
MetricsError
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§

DrainMetricCollectorTrait
Trait for collectors that support draining aggregated metrics.
MetricCollectorTrait
Trait defining the interface for metric collection.

Type Aliases§

MetricResult
Result type for metric operations.