Expand description
a high-performance stats library focused on rates and latencies from timestamped events
§Features
- high throughput - millions of samples per second
- latched histogram - for analyzing the full distribution of sample lengths
- heatmaps - to generate distribution traces and waterfalls
- meters - to expose readings for client usage
- http metrics - simple metrics on http for scraping and monitoring, Prometheus compatible
- generic - channel type is generic, and used to label the type of sample
- flexible - per channel stats are accessible by registering appropriate
Interest
s
§Usage
This crate is on crates.io and can be used by adding
tic
to your Cargo.toml
[dependencies]
tic = "*"
and to your crate root
extern crate tic;
§Example: Service Mode
This example shows how to use tic
in a long-running service
use std::fmt;
use std::thread;
use std::time;
use tic::{Interest, Receiver, Sample};
// define an enum of stats labels
#[derive(Clone, PartialEq, Eq, Hash)]
pub enum Metric {
Ok,
}
// implement the fmt::Display trait
impl fmt::Display for Metric {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Metric::Ok => write!(f, "ok"),
}
}
}
// configure a receiver
let mut receiver = Receiver::configure()
.service(true)
.build();
// register some interests
// record the counts of samples with `Metric::Ok`
receiver.add_interest(Interest::Count(Metric::Ok));
// record latency percentiles of samples with `Metric::Ok`
receiver.add_interest(Interest::LatencyPercentile(Metric::Ok));
// get a sender and a clocksource
let mut sender = receiver.get_sender();
let clocksource = receiver.get_clocksource();
// run the receiver in a separate thread
thread::spawn(move || { receiver.run(); });
// put your application logic here, and increment stats
for _ in 0..100 {
let start = clocksource.counter();
// do some work that takes some time
let stop = clocksource.counter();
sender.send(Sample::new(start, stop, Metric::Ok));
}
// stats will be available on the http_listen port while main() is running
Structs§
- Clocksource
- Config
- a configuration struct for customizing
Receiver
- Controller
- a
Controller
allows interacting with a remoteReceiver
- Http
Reporter - an HTTP-based endpoint for viewing all registered metrics on a
Receiver
- Meters
Meters
are the aggregated result of stats which have been processed by theReceiver
.- Percentile
- a Percentile is the label plus floating point percentile representation
- Receiver
- a
Receiver
processes incomingSample
s and generates stats - Sample
- a start and stop time for an event
- Sender
- a Sender is used to push
Sample
s to theReceiver
it is clonable for sharing between threads
Enums§
- Interest
- an Interest registers a metric for reporting
Constants§
- SECOND
- Duration of 1 second in nanoseconds