Substreams
Prometheus sink module
substreams-sink-prometheus
is a tool that allows developers to pipe data extracted metrics from a blockchain into a Prometheus time series database.
Summaries calculate percentiles of observed values. - [ ] Observe - [ ] percentiles - [ ] maxAgeSeconds - [ ] ageBuckets - [ ] startTimer
$ cargo add substreams-sink-prometheus
Cargo.toml
toml
[dependencies]
substreams = "0.5"
substreams-sink-prometheus = "0.1"
src/lib.rs
```rust use substreams::prelude::*; use substreams::errors::Error; use substreamssinkprometheus::{PrometheusOperations, Counter, Gauge};
fn prom_out(
... some stores ...
) -> Result
let mut prom_ops: PrometheusOperations = Default::default();
// 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());
// 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));
// Set Counter to the current Unix time in seconds.
prom_ops.push(counter.set_to_current_time());
Ok(prom_ops)
} ```