v0.1.2
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.
π 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)
}