Skip to content

v0.1.3

Compare
Choose a tag to compare
@DenisCarriere DenisCarriere released this 09 Feb 18:31
· 37 commits to main since this release

Substreams Prometheus sink module

github crates.io docs.rs GitHub Workflow Status

substreams-sink-prometheus is a tool that allows developers to pipe data extracted metrics from a blockchain into a Prometheus time series database.

πŸ“– Documentation

https://docs.rs/substreams-sink-prometheus

Further resources

πŸ›  Feature Roadmap

Gauge Metric

  • Set
  • Inc
  • Dec
  • Add
  • Sub
  • SetToCurrentTime

Counter Metric

  • Inc
  • Add

Histogram Metric

  • Observe
  • buckets
  • zero

Summary Metric

Summaries calculate percentiles of observed values.

  • Observe
  • percentiles
  • maxAgeSeconds
  • ageBuckets
  • startTimer

Registry

  • Clear
  • SetDefaultLabels
  • RemoveSingleMetric

Install

$ cargo add substreams-sink-prometheus

Quickstart

Cargo.toml

[dependencies]
substreams = "0.5"
substreams-sink-prometheus = "0.1"

src/lib.rs

use substreams::prelude::*;
use substreams::errors::Error;
use substreams_sink_prometheus::{PrometheusOperations, Counter, Gauge};

#[substreams::handlers::map]
fn prom_out(
    ... some stores ...
) -> Result<PrometheusOperations, Error> {

    let mut prom_ops: PrometheusOperations = Default::default();

    // Counter Metric
    // ==============
    // Increments the Counter by 1.
    let mut counter = Counter::new("counter_name");
    prom_ops.push(counter.inc());

    // Adds an arbitrary value to a Counter. (Returns an error if the value is < 0.)
    prom_ops.push(counter.add(123.456));

    // Gauge Metric
    // ============
    // Initialize Gauge with a name & labels
    let mut gauge = Gauge::new("gauge_name");
    gauge.set_label("custom_label");

    // Sets the Gauge to an arbitrary value.
    prom_ops.push(gauge.set(88.8));

    // Increments the Gauge by 1.
    prom_ops.push(gauge.inc());

    // Decrements the Gauge by 1.
    prom_ops.push(gauge.dec());

    // Adds an arbitrary value to a Gauge. (The value can be negative, resulting in a decrease of the Gauge.)
    prom_ops.push(gauge.add(50.0));
    prom_ops.push(gauge.add(-10.0));

    // Subtracts arbitrary value from the Gauge. (The value can be negative, resulting in an increase of the Gauge.)
    prom_ops.push(gauge.sub(25.0));
    prom_ops.push(gauge.sub(-5.0));

    // Set Gauge to the current Unix time in seconds.
    prom_ops.push(gauge.set_to_current_time());

    Ok(prom_ops)
}