Crate libcantal

Source
Expand description

A library that exposes metrics sent to cantal

See mmap protocol for more information about the protocol.

§Example

use libcantal::{Counter, Integer, Value, start, print};

// Declare metrics as static variables, so you can use it in a module
// freely, i.e. increment/decrement at any time
lazy_static! {
    static ref COUNTER: Counter = Counter::new();
    static ref INTEGER: Integer = Integer::new();
}

// Put metrics in a collection
let metrics = [
    (json!({"metric": "counter"}), &*COUNTER as &Value),
    (json!({"metric": "integer"}), &*INTEGER as &Value),
];
// The collection guard. When it's alive, all the metrics are exposed
let _coll = start(&metrics[..]).expect("cantal works");

// ...
// Somewhere later use the metrics:
COUNTER.incr(1);
INTEGER.set((COUNTER.get() / 7) as i64);

// And at any time you can print the collection for debugging
print(&metrics[..], stdout()).ok();

Structs§

ActiveCollection
An active collection currently publishing metrics
Counter
A kind of metric (Value) that exports ever-increasing counter
Error
Error of exporting metrics
Integer
A kind of metric (Value) that exports gauge with integer value
Json
A helper that allows to serialize a collection of metrics as JSON

Enums§

LevelKind
A kind of level (gauge) metric, only used for Value trait
RawType
A raw type of metric, only used for Value trait

Traits§

Collection
A collection of metrics
Name
Name of the metric
NameVisitor
A structure used to serialize Name objects to submit to agent
Value
A value stored in a collection
Visitor
A trait used to enumerate a collection

Functions§

print
Print all metrics of a collection to a file
start
Start publishing metrics
start_with_reading
Start publishing metrics by reading old values first