#carbon #metrics #graphite #tokio

tk-carbon

Implementation of carbon (graphite) client protocol on top of tokio-rs

2 unstable releases

Uses old Rust 2015

0.2.0 Nov 24, 2017
0.1.0 Mar 2, 2017

#1656 in Asynchronous

MIT/Apache

61KB
649 lines

Carbon Bindings for Tokio

Status: Beta

Documentation | Github | Crate

A library to submit data to carbon (graphite). Works in asynchronous main loop using tokio.

Features:

  1. Pluggable name resolution (service discovery)
  2. Reconnects to the new host(s) on the fly
  3. Connects to multiple hosts and duplicates records if name resolves to multiple hosts.

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

Carbon client protocol implementation

Documentation | Github | Crate

High Level Interface

let (carbon, init) = Carbon::new(&Config::new().done());
init.connect_to(resolver.subscribe("localhost:2003"), &handle);
// now you can submit metrics
carbon.add_metric("my.metric", 10);

This allows protocol to:

  1. Establish connection to all addressses address resolves too
  2. Reconnect in case of failure
  3. Reconnect to new host(s) when IPs the DNS name resolves to changes

See examples for more full examples.

Lower Level Interface

In case you don't want to use connection pooling, you may connect carbon instance to a specific connection:

use tk_carbon::{Carbon, Config};

let (carbon, init) = Carbon::new(&Config::new().done());
handle.spawn(TcpStream::connect(&addr, &handle)
    .and_then(move |sock| init.from_connection(sock, &handle2))
    .map_err(|e| unimplemented!()));
// use carbon the same way as above
carbon.add_metric("my.metric", 10);

General

Carbon object is the same for connection pool and raw interface and may be used from any thread as long as the tokio loop running the networking code is still alive.

You don't have to wait until connection is established to send metrics, they will be buffered up till configuration limit (see docs on Config)

Dependencies

~7MB
~106K SLoC