Skip to content

Releases: pinax-network/substreams-sink-prometheus.rs

v0.2.0

02 Aug 20:52
Compare
Choose a tag to compare

Bump up proto version to work with latest backend

v0.1.10

01 Aug 13:00
Compare
Choose a tag to compare

Bump up proto version

v0.1.9

19 Feb 22:25
Compare
Choose a tag to compare
  • Implement Summary & Histogram
// Summary Metric
// ==============
// Initialize Summary
let mut summary = Summary::from("summary_name");

/// Observe adds a single observation to the summary.
/// Observations are usually positive or zero.
/// Negative observations are accepted but prevent current versions of Prometheus from properly detecting counter resets in the sum of observations
prom_ops.push(summary.observe(88.8));

// Start a timer. Calling the returned function will observe the duration in seconds in the summary.
prom_ops.push(summary.start_timer());

// Histogram Metric
// ==============
// Initialize Summary
let mut histogram = Histogram::from("histogram_name");

/// Observe adds a single observation to the histogram.
/// Observations are usually positive or zero.
/// Negative observations are accepted but prevent current versions of Prometheus from properly detecting counter resets in the sum of observations
prom_ops.push(histogram.observe(88.8));

// Start a timer. Calling the returned function will observe the duration in seconds in the histogram.
prom_ops.push(histogram.start_timer());

// Initialize the metrics for the given combination of labels to zero
prom_ops.push(histogram.zero(HashMap::from([("label1".to_string(), "value1".to_string())])));

v0.1.8

15 Feb 02:12
Compare
Choose a tag to compare
  • add REMOVE & RESET operations
  • implement CLI features
    • last_block_number
    • last_block_timestamp
    • head_block_drift
    • logging on counter/gauge (NODE_ENV='production' to hide)

v0.1.7

14 Feb 19:00
Compare
Choose a tag to compare
  • Update prometheus protobuf messages

v0.1.4

09 Feb 22:28
Compare
Choose a tag to compare

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 std::collections::HashMap;
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> {

    // Initialize Prometheus Operations container
    let mut prom_ops: PrometheusOperations = Default::default();

    // Counter Metric
    // ==============
    // Initialize Gauge with a name & labels
    let mut counter = Counter::from("counter_name");

    // Increments the Counter by 1.
    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));

    // Labels
    // ======
    // Create a HashMap of labels
    let mut labels = HashMap::new();
    labels.insert("label1".to_string(), "value1".to_string());

    // Gauge Metric
    // ============
    // Initialize Gauge
    let mut gauge = Gauge::from("gauge_name").with(labels);

    // 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   rease 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    rease 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)
}

v0.1.3

09 Feb 18:31
Compare
Choose a tag to compare

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)
}

v0.1.2

08 Feb 03:06
Compare
Choose a tag to compare

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;

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

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

    // Gauge Metric
    // ============
    // Sets the Gauge to an arbitrary value.
    prom_ops.push_set("gauge_name", 123.456, vec![]);
    prom_ops.push_set("gauge_custom", 888.8, vec!["custom_label"]);

    // Increments the Gauge by 1.
    prom_ops.push_inc("gauge_name", vec![]);

    // Decrements the Gauge by 1.
    prom_ops.push_dec("gauge_name", vec![]);
    
    // Adds an arbitrary value to a Gauge. (The value can be negative, resulting in a decrease of the Gauge.)
    prom_ops.push_add("gauge_name", 50.0, vec![]);
    prom_ops.push_add("gauge_name", -10.0, vec![]);

    // Subtracts arbitrary value from the Gauge. (The value can be negative, resulting in an increase of the Gauge.)
    prom_ops.push_sub("gauge_name", 25.0, vec![]);
    prom_ops.push_sub("gauge_name", -5.0, vec![]);

    // Set Gauge to the current Unix time in seconds.
    prom_ops.push_set_to_current_time("gauge_name", vec![]);

    // Counter Metric
    // ==============
    // process your data, push to Prometheus metrics
    prom_ops.push_counter_inc("counter_name", vec![]);

    // Adds an arbitrary value to a Counter. (Returns an error if the value is < 0.)
    prom_ops.push_counter_add("counter_name", 123.456, vec![]);

    Ok(prom_ops)
}

v0.1.1

04 Feb 22:07
Compare
Choose a tag to compare

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

Prometheus Gauge

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

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;

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

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

    // process your data, push to Prometheus metrics
    prom_ops.push_set(vec!["some_key"], 123.456);
    prom_ops.push_inc(vec!["increment_key"]);
    prom_ops.push_dec(vec!["decrement_key"]);
    prom_ops.push_add(vec!["add_key"], 2.0);
    prom_ops.push_sub(vec!["substract_key"], 100.0);

    Ok(prom_ops)
}