cadence-macros
An extensible Statsd client for Rust!
Cadence is a fast and flexible way to emit Statsd metrics from your application.
The cadence-macros
crate provides some wrappers to eliminate much of the boilerplate
that is often needed to emit metrics along with any tags that are associated with
them.
Features
- Support for emitting counters, timers, histograms, distributions, gauges, meters, and sets to Statsd over UDP (or optionally Unix sockets).
- Support for alternate backends via the
MetricSink
trait. - Support for Datadog style metrics tags.
- Macros to simplify common calls to emit metrics
- A simple yet flexible API for sending metrics.
Install
To make use of cadence-macros
in your project, add it as a dependency in your Cargo.toml
file.
[]
= "x.y.z"
Usage
To make use of the macros in this crate, you'll need to set a global default Statsd client.
Configure a cadence::StatsdClient
as usual and use the set_global_default
function to
set it as the default. After that, you can make use of the macros in this crate.
use UdpSocket;
use *;
use ;
use ;
// Normal setup for a high-performance Cadence instance
let socket = bind.unwrap;
socket.set_nonblocking.unwrap;
let host = ;
let udp_sink = from.unwrap;
let queuing_sink = from;
let client = from_sink;
// Set the default client to use for macro calls
set_global_default;
// Macros!
statsd_count!;
statsd_count!;
statsd_count!;
statsd_time!;
statsd_time!;
statsd_time!;
statsd_gauge!;
statsd_gauge!;
statsd_gauge!;
statsd_meter!;
statsd_meter!;
statsd_meter!;
statsd_histogram!;
statsd_histogram!;
statsd_histogram!;
statsd_distribution!;
statsd_distribution!;
statsd_distribution!;
statsd_set!;
statsd_set!;
statsd_set!;
Limitations
Some limitations with the current implemenation of Cadence macros are described below
- Value tags are not supported. For example the following style of tag cannot be
set when using macros:
client.count_with_tags("some.counter", 123).with_tag_value("beta").send()
- Only a single type of value for each type of metric is supported. For example, only
u64
can be used with thestatsd_time!
macro, not astd::time::Duration
. Onlyu64
can be used with thestatsd_gauge!
macro, not af64
.
Other
For more information about Cadence, see the README in the repository root.