Crate tic [] [src]

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 Interests

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)
        .http_listen("localhost:42024".to_owned())
        .build();

// register some interests
receiver.add_interest(Interest::Count(Metric::Ok));
receiver.add_interest(Interest::Percentile(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

Meters
Percentile

a Percentile is the label plus floating point percentile representation

Receiver

a Receiver processes incoming Samples and generates stats

Sample

a start and stop time for an event

Sender

a Sender is used to push Samples to the Receiver it is clonable for sharing between threads

Enums

Interest

an Interest registers a metric for reporting