2 unstable releases

0.2.0 Dec 27, 2023
0.1.0 Mar 24, 2022

#15 in #aggregate

36 downloads per month

MIT/Apache

56KB
1K SLoC

Metriki

Metriki is a rust library ported from Dropwizard Metrics.

Like Dropwizard Metrics, Metriki aggregates metrics on client-side and outputs limited amount data.

Quick Start

// create a timer to track the execution rate and latency of this function
// to use macros you will need to turn on `macros` feature of metriki_core
#[timed]
fn your_function() {
  // a function metered by a timer for its rate and latency
}

use metriki_core::global::global_registry;
use metriki_influxdb_reporter::InfluxDbReporterBuilder;

// by default, the timer is registered in this global_registry()
let registry = global_registry();

// start a reporter to send data into influxdb
InfluxDbReporterBuilder::default()
    .url("localhost:8086")
    .username(String::from("influxdbuser"))
    .password(String::from("yourpassword"))
    .database("db")
    .registry(registry.clone())
    .build()
    .unwrap()
    .start();

Components

Concepts

Metrics

  • Counter: a value that can be increased and decreased.
  • Meter: measures rate of an event.
  • Histogram: records distribution of data over time.
  • Timer: a combination of meter and histogram.
  • Gauge: a function that provides value when queried.

MetricsRegistry

An entrypoint and holder of all metrics.

MetricsSet

A trait to be implemented so that dynamic metrics can be added into registry. Metrics from the set are pulled into registry everytime when reporters and exporters pulling values from the registry.

Reporter

A component to report metric data periodically. Typically used for data sinks which has a push-model.

Exporter

A component to expose metric data to external queriers. Typically for pull based data sinks.

License

MIT/Apache-2.0


lib.rs:

Metriki Tokio Instrument

This library provides tokio-metrics integration for metriki.

Setup

This library provides RuntimeMetrics by default. Accroding to tokio-metrics, tokio_unstable is required for this feature. See the doc for steps to setup the cargo configuration.

To disable unstable features, you can include this library with default-features = false.

Usage

An Example is provided in the codebase.

Check docs of tokio-metrics for meaning of the metrics.

Dependencies

~6–14MB
~136K SLoC