Skip to content

Commit

Permalink
enhancement: add a new DogStatsD-specific exporter (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobz authored Jan 6, 2025
1 parent e6cf124 commit c15fed2
Show file tree
Hide file tree
Showing 35 changed files with 2,734 additions and 44 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[workspace]
resolver = "2"
members = [
"metrics",
"metrics-benchmark",
"metrics-exporter-dogstatsd",
"metrics-exporter-prometheus",
"metrics-exporter-tcp",
"metrics-observer",
Expand All @@ -24,7 +26,6 @@ crossbeam-utils = { version = "0.8", default-features = false }
getopts = { version = "0.2", default-features = false }
hashbrown = { version = "0.15", default-features = false, features = ["default-hasher", "raw-entry"] }
hdrhistogram = { version = "7.2", default-features = false }
home = { version = "0.5", default-features = false }
http-body-util = { version = "0.1", default-features = false }
hyper = { version = "1.1", default-features = false, features = ["server", "client"] }
hyper-rustls = { version = "0.27", default-features = false, features = ["aws-lc-rs", "http1", "rustls-native-certs"] }
Expand Down
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
too-many-lines-threshold = 150
ignore-interior-mutability = ["metrics::key::Key"]
doc-valid-idents = ["DogStatsD", ".."]
13 changes: 13 additions & 0 deletions metrics-exporter-dogstatsd/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

<!-- next-header -->

## [Unreleased] - ReleaseDate

### Added

- Genesis.
20 changes: 20 additions & 0 deletions metrics-exporter-dogstatsd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "metrics-exporter-dogstatsd"
version = "0.1.0"
edition = "2021"

[dependencies]
bytes = { version = "1", default-features = false }
ryu = { version = "1", default-features = false }
itoa = { version = "1", default-features = false }
metrics = { version = "^0.24", path = "../metrics" }
metrics-util = { version = "^0.18", path = "../metrics-util" }
thiserror = { workspace = true }
tracing = { workspace = true }

[dev-dependencies]
proptest = { workspace = true }
rand = { workspace = true }
rand_xoshiro = { version = "0.6", default-features = false }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = ["fmt"] }
28 changes: 28 additions & 0 deletions metrics-exporter-dogstatsd/examples/dogstatsd_idle_counter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::time::{Duration, Instant};

use metrics::counter;
use metrics_exporter_dogstatsd::DogStatsDBuilder;

fn main() {
tracing_subscriber::fmt::init();

DogStatsDBuilder::default()
.with_remote_address("localhost:9125")
.expect("failed to parse remote address")
.with_telemetry(false)
.install()
.expect("failed to install DogStatsD recorder");

counter!("idle_metric").increment(1);

// Loop over and over, incrementing our counter every 10 seconds or so.
let mut last_update = Instant::now();
loop {
if last_update.elapsed() > Duration::from_secs(10) {
counter!("idle_metric").increment(1);
last_update = Instant::now();
}

std::thread::sleep(Duration::from_secs(1));
}
}
36 changes: 36 additions & 0 deletions metrics-exporter-dogstatsd/examples/dogstatsd_synchronous.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use metrics::{counter, gauge, histogram};
use metrics_exporter_dogstatsd::DogStatsDBuilder;
use rand::{thread_rng, Rng, SeedableRng as _};
use rand_xoshiro::Xoshiro256StarStar;

fn main() {
tracing_subscriber::fmt::init();

DogStatsDBuilder::default()
.with_remote_address("localhost:9125")
.expect("failed to parse remote address")
.install()
.expect("failed to install DogStatsD recorder");

counter!("idle_metric").increment(1);
gauge!("testing").set(42.0);

let server_loops = counter!("tcp_server_loops", "system" => "foo");
let server_loops_delta_secs = histogram!("tcp_server_loop_delta_secs", "system" => "foo");

let mut rng = Xoshiro256StarStar::from_rng(thread_rng()).unwrap();

// Loop over and over, pretending to do some work.
loop {
server_loops.increment(1);
server_loops_delta_secs.record(rng.gen_range(0.0..1.0));

let increment_gauge = thread_rng().gen_bool(0.75);
let gauge = gauge!("lucky_iterations");
if increment_gauge {
gauge.increment(1.0);
} else {
gauge.decrement(1.0);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc 996294ee8ec0a637930c95346f0165bbaba2cbf701d321de8d713d7f723f0ff0 # shrinks to payload_limit = 43, inputs = [Histogram(Key { name: KeyName("A0AA0A0A"), labels: [], hashed: true, hash: 18423047812237334005 }, [-0.0, 3.1748022040256364e164], 10000000)]
Loading

0 comments on commit c15fed2

Please sign in to comment.