2017-06-29 21:52:37 +00:00
|
|
|
dipstick
|
|
|
|
--------
|
2017-08-19 18:09:17 +00:00
|
|
|
|
2017-08-23 17:59:17 +00:00
|
|
|
[![Build Status](https://travis-ci.org/fralalonde/dipstick.svg?branch=master)](https://travis-ci.org/fralalonde/dipstick)
|
2017-08-19 18:09:17 +00:00
|
|
|
|
2017-08-18 17:55:04 +00:00
|
|
|
A fast and modular metrics library decoupling app instrumentation from reporting backend.
|
|
|
|
Similar to popular logging frameworks, but with counters and timers.
|
|
|
|
Can be configured for combined outputs (log + statsd), random sampling, local aggregation of metrics, recurrent background publication, etc.
|
2017-06-29 21:52:37 +00:00
|
|
|
|
2017-08-21 19:31:52 +00:00
|
|
|
## Design
|
|
|
|
Dipstick's design goals are to:
|
2017-08-21 21:34:49 +00:00
|
|
|
- support as many metrics backends as possible while favoring none
|
|
|
|
- support all types of applications, from embedded to servers
|
|
|
|
- promote metrics conventions that facilitate app monitoring and maintenance
|
|
|
|
- stay out of the way in the code and at runtime (ergonomic, fast, resilient)
|
2017-07-24 20:36:23 +00:00
|
|
|
|
2017-08-21 19:31:52 +00:00
|
|
|
## Code
|
2017-09-05 04:24:43 +00:00
|
|
|
Here's an example showing usage of a predefined timer with closure syntax.
|
2017-09-02 05:16:39 +00:00
|
|
|
Each timer value is :
|
|
|
|
- Written immediately to the "app_metrics" logger.
|
2017-09-05 04:24:43 +00:00
|
|
|
- Sent to statsd immediately, one time out of ten (randomly sampled).
|
2017-08-21 19:31:52 +00:00
|
|
|
```rust
|
2017-08-21 21:36:35 +00:00
|
|
|
use dipstick::*;
|
2017-09-02 05:16:39 +00:00
|
|
|
|
|
|
|
let app_metrics = metrics((
|
|
|
|
log("app_metrics"),
|
|
|
|
sample(0.1, statsd("stats:8125"))
|
|
|
|
));
|
|
|
|
|
|
|
|
let timer = app_metrics.timer("timer_b");
|
2017-09-05 04:24:43 +00:00
|
|
|
|
|
|
|
let value2 = time!(timer, compute_value2());
|
2017-09-02 05:16:39 +00:00
|
|
|
```
|
|
|
|
|
2017-09-05 04:24:43 +00:00
|
|
|
In this other example, an _ad-hoc_ timer with macro syntax is used.
|
2017-09-02 05:16:39 +00:00
|
|
|
- Each new timer value is aggregated with the previous values.
|
|
|
|
- Aggregation tracks count, sum, max and min values (locklessly).
|
|
|
|
- Aggregated scores are written to log every 10 seconds.
|
|
|
|
- `cache(sink)` is used to prevent metrics of the same to be created multiple times.
|
|
|
|
```rust
|
|
|
|
use dipstick::*;
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
let (sink, source) = aggregate();
|
|
|
|
let app_metrics = metrics(cache(sink));
|
|
|
|
publish(source, log("last_ten_seconds")).publish_every(Duration::from_secs(10));
|
|
|
|
|
2017-09-05 04:24:43 +00:00
|
|
|
let value2 = time!(app_metrics.timer("timer_b"), compute_value2());
|
2017-06-29 21:52:37 +00:00
|
|
|
```
|
2017-09-02 05:16:39 +00:00
|
|
|
|
|
|
|
Other example(s?) can be found in the /examples dir.
|
2017-08-21 19:31:52 +00:00
|
|
|
|
2017-09-05 04:24:43 +00:00
|
|
|
## Performance
|
|
|
|
Predefined timers use a bit more code but are generally faster because their
|
|
|
|
initialization cost is is only paid once.
|
|
|
|
Ad-hoc timers are redefined "inline" on each use. They are more flexible, but have more overhead because their init cost is paid on each use.
|
|
|
|
Defining a metric `cache()` reduces that cost for recurring metrics.
|
|
|
|
|
2017-09-20 17:13:44 +00:00
|
|
|
Run benchmarks with `cargo +nightly bench --features bench`.
|
2017-09-05 04:24:43 +00:00
|
|
|
|
2017-08-21 21:34:49 +00:00
|
|
|
## TODO
|
2017-08-21 19:31:52 +00:00
|
|
|
Although already usable, Dipstick is still under heavy development and makes no guarantees
|
|
|
|
of any kind at this point. See the following list for any potential caveats :
|
2017-08-21 21:34:49 +00:00
|
|
|
- META turn TODOs into GitHub issues
|
2017-07-24 20:36:23 +00:00
|
|
|
- generic publisher / sources
|
2017-08-18 17:55:04 +00:00
|
|
|
- dispatch scopes
|
2017-08-21 21:20:31 +00:00
|
|
|
- feature flags
|
2017-09-20 17:13:44 +00:00
|
|
|
- derive stats
|
2017-09-05 04:24:43 +00:00
|
|
|
- non-tokio publish scheduler
|
2017-08-18 17:55:04 +00:00
|
|
|
- microsecond-precision intervals
|
2017-08-21 19:31:52 +00:00
|
|
|
- heartbeat metric on publish
|
2017-08-21 21:34:49 +00:00
|
|
|
- logger templates
|
2017-08-18 17:55:04 +00:00
|
|
|
- configurable aggregation
|
|
|
|
- non-aggregating buffers
|
|
|
|
- tagged / ad-hoc metrics
|
2017-09-25 10:43:04 +00:00
|
|
|
- framework glue (rocket, iron, gotham, indicatif, etc.)
|
|
|
|
- more tests & benchmarks
|
2017-08-21 21:34:49 +00:00
|
|
|
- complete doc / inline samples
|
2017-09-25 10:43:04 +00:00
|
|
|
- more example apps
|
|
|
|
- A cool logo
|
|
|
|
- method annotation processors `#[timer("name")]`
|
2017-09-27 15:01:43 +00:00
|
|
|
- fastsinks (M / &M) vs. safesinks (Arc<M>)
|