Crate tk_carbon [−] [src]
Carbon client protocol implementation
Documentation | Github | Crate
High Level Interface
⚠Be careful when using this code, it's not being tested!
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:
- Establish connection to all addressses address resolves too
- Reconnect in case of failure
- 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:
⚠Be careful when using this code, it's not being tested!
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
)
Structs
Carbon |
A structure that is used to submit values to carbon |
Config |
Configuration of carbon protocol |
Init |
A helper structure for initializing protocol instance |
Proto |
Low-level interface to a single carbon connection |