GitXplorerGitXplorer
m

rust-statsd

public
61 stars
26 forks
1 issues

Commits

List of commits on branch master.
Unverified
50b4ab00e8ea733bcd7e97a5e5870a8242f3cae9

Bump version number

mmarkstory committed 3 months ago
Unverified
4956f2f5ddf8b7f5c73b7d30afe555bd64ca3443

Apply changes from clippy

mmarkstory committed 3 months ago
Unverified
5524da8a82f0756b10ae9c91bfad62bce2262f34

Update readme

mmarkstory committed 3 months ago
Unverified
acda9b81d9390a61fd8ece54c4c97729829a29e0

cargo fmt

mmarkstory committed 3 months ago
Unverified
6440f3f999c6f3bd632e01756fd2e14820800ca2

Wrong branch

mmarkstory committed 3 months ago
Unverified
508f46eddce762671465baef590188339fa0161f

Add CI.

mmarkstory committed 3 months ago

README

The README file for this repository.

Rust Statsd

CI status

A StatsD client implementation of statsd in rust.

Using the client library

Add the statsd package as a dependency in your Cargo.toml file:

[dependencies]
statsd = "^0.16"

You need rustc >= 1.31.0 for statsd to work.

You can then get a client instance and start tracking metrics:

// Load the crate
extern crate statsd;

// Import the client object.
use statsd::Client;

// Get a client with the prefix of `myapp`. The host should be the
// IP:port of your statsd daemon.
let client = Client::new("127.0.0.1:8125", "myapp").unwrap();

Tracking Metrics

Once you've created a client, you can track timers and metrics:

// Increment a counter by 1
client.incr("some.counter");

// Decrement a counter by 1
client.decr("some.counter");

// Update a gauge
client.gauge("some.value", 12.0);

// Modify a counter by an arbitrary float.
client.count("some.counter", 511.0);

// Send a histogram value as a float.
client.histogram("some.histogram", 511.0);

// Send a key/value.
client.kv("some.data", 15.26);

Tracking Timers

Timers can be updated using timer() and time():

// Update a timer based on a calculation you've done.
client.timer("operation.duration", 13.4);

// Time a closure
client.time("operation.duration", || {
	// Do something expensive.
});

Pipeline

Multiple metrics can be sent to StatsD once using pipeline:

let mut pipe = client.pipeline():

// Increment a counter by 1
pipe.incr("some.counter");

// Decrement a counter by 1
pipe.decr("some.counter");

// Update a gauge
pipe.gauge("some.value", 12.0);

// Modify a counter by an arbitrary float.
pipe.count("some.counter", 511.0);

// Send a histogram value as a float.
pipe.histogram("some.histogram", 511.0);

// Send a key/value.
pipe.kv("some.data", 15.26);

// Set max UDP packet size if you wish, default is 512
pipe.set_max_udp_size(128);

// Send to StatsD
pipe.send(&client);

Pipelines are also helpful to make functions simpler to test, as you can pass a pipeline and be confident that no UDP packets will be sent.

License

Licenesed under the MIT License.