Skip to main content
Pipes SDK exposes Prometheus-compatible metrics at the /metrics endpoint for monitoring pipeline health and performance.
Track custom Prometheus metrics in your pipeline. The Pipes SDK exposes a metrics server that you can use to add counters, gauges, histograms, and summaries.
import { commonAbis, evmDecoder, evmPortalSource } from "@subsquid/pipes/evm";
import { metricsServer } from "@subsquid/pipes/metrics/node";

async function main() {
const stream = evmPortalSource({
  portal: "https://portal.sqd.dev/datasets/ethereum-mainnet",
  metrics: metricsServer({ port: 9090 }),
}).pipe(
  evmDecoder({
    range: { from: "latest" },
    events: {
      transfers: commonAbis.erc20.events.Transfer,
    },
  })
);

for await (const { data, ctx } of stream) {
  // Add custom counter metric
  ctx.metrics
    .counter({
      name: "my_transfers_counter",
      help: "Number of processed transactions",
    })
    .inc(data.transfers.length);

  // Use profiler to measure performance
  const span = ctx.profiler.start("processing");
  await processData(data);
  span.end();
}
}

void main()
Access metrics at http://localhost:9090/metrics to verify they’re being exposed correctly.
# HELP my_transfers_counter Number of processed transactions
# TYPE my_transfers_counter counter
my_transfers_counter 218598
Use Grafana dashboards to visualize block processing rate, error rates, and latency trends from your Prometheus metrics.

Available Metric Types

You can create different types of Prometheus metrics:
for await (const { data, ctx } of stream) {
  // Counter - monotonically increasing value
  ctx.metrics.counter({ name: "events_total", help: "Total events" }).inc();

  // Gauge - value that can go up or down
  ctx.metrics
    .gauge({ name: "queue_size", help: "Current queue size" })
    .set(queueSize);

  // Histogram - observations with configurable buckets
  ctx.metrics
    .histogram({ name: "batch_size", help: "Batch size distribution" })
    .observe(data.transfers.length);
}
Counter and Gauge are the most common metric types. Use Counter for cumulative events (total processed blocks), Gauge for current values (current lag, queue size).
Expose metrics with metricsServer() on your source, then visualize them with Pipes UI.