library / Integrations / I0017
Grafana network metrics
A small Node exporter polls your Carbium RPC every 15 seconds, serves slot, finalized lag, block height, epoch progress, TPS and call errors at /metrics, and Prometheus feeds them to Grafana panels and alert rules.
What the exporter publishes
The exporter is one Node process with one dependency, @solana/kit. Every 15 seconds it makes seven read calls to Carbium, turns the answers into Prometheus text and keeps the newest copy in memory. A small HTTP server returns that copy at /metrics. Prometheus scrapes it, and Grafana charts what Prometheus stored. Scrape as often as you like: a scrape reads the stored copy and makes no call to Carbium.
| Metric | Source call | What it tells you |
|---|---|---|
| carbium_solana_slot{commitment} | getSlot at processed, confirmed and finalized | Newest slot at each level, as three series. |
| carbium_solana_finalized_lag_slots | The processed and finalized reads | Processed minus finalized, never below 0. |
| carbium_solana_block_height | getEpochInfo at processed | Block height. |
| carbium_solana_epoch and carbium_solana_epoch_progress_ratio | getEpochInfo | Epoch number and the share of its slots already passed. |
| carbium_solana_transactions_per_second and carbium_solana_slots_per_second | getRecentPerformanceSamples | Transactions and slots over the newest sample window. |
| carbium_solana_health_ok | getHealth | 1 when it answered ok, 0 when the call failed. |
| carbium_solana_version_info{solana_core} | getVersion | The node version as a label, value 1. |
| carbium_solana_poll_errors_total{call} | The exporter | Failed calls since start, by call. |
| carbium_solana_poll_duration_seconds | The exporter | How long the last poll took. |
A call that fails drops its own series from that poll and adds one to the error counter. The other series still publish, so a failing getEpochInfo leaves the slot panel intact. Prometheus treats a missing series as stale, which Grafana draws as a gap.
The Solana side: commitments, slots and samples
The exporter talks to the RPC endpoint at https://services.carbium.sh and sends your key on every call. It builds one client at start and reuses it for the life of the process.
On mainnet since 2026-10-21 a slot takes about 200 ms and finality lands within one slot, so finalized_lag_slots reads 0 or 1 where it once hovered near 32. A climb is the signal. The three getSlot calls leave together but are separate reads, so two levels can come back equal or briefly out of order. That is why the exporter clamps the lag at 0.
getRecentPerformanceSamples returns windows of slots and transactions, each with numSlots, numTransactions and samplePeriodSecs. The exporter divides by the period for the newest window. After the switch, slots_per_second should sit near 5, the same 200 ms slot expressed per second. A new window appears only when one closes, so these two gauges step once per window.
epoch_progress_ratio is slotIndex / slotsInEpoch from getEpochInfo, which gives you a panel that fills up to the epoch boundary.
Wire Prometheus and Grafana
- Install @solana/[email protected], set "type": "module" in package.json and start the exporter with CARBIUM_KEY set. It listens on 127.0.0.1:9464 unless you set METRICS_HOST and METRICS_PORT.
- Add a scrape job to prometheus.yml with metrics_path: /metrics and the exporter's host:port as the target. A scrape_interval of 15s matches the poll.
- In Grafana, add Prometheus as a data source and build four panels: a time series of carbium_solana_slot by commitment, a stat on carbium_solana_finalized_lag_slots, a gauge on carbium_solana_epoch_progress_ratio, and a time series of increase(carbium_solana_poll_errors_total[5m]) by call.
- Add alert rules on carbium_solana_health_ok == 0 and on carbium_solana_finalized_lag_slots above a threshold you pick from what your lag stat shows. The up series of the scrape job catches a dead exporter.
The /metrics endpoint has no login. Keep it on the loopback address, or put it behind the proxy that guards your Prometheus. For a chat message on an alert, point a Grafana contact point at Slack; Slack slot-lag alerts shows the same slot check as a standalone watcher.
The exporter
Node 24 strips the types on load. The file reads one required variable, CARBIUM_KEY, and exits with a message when it is missing. The optional ones are CARBIUM_RPC_URL, POLL_SECONDS, METRICS_HOST and METRICS_PORT. Run node main.ts --once to print one poll's metrics and exit, which shows your key works before Prometheus is involved.
// I0017 · Grafana network metrics// https://carbium.sh/library/integrate/grafana-network-metrics// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { createDefaultRpcTransport, createSolanaRpcFromTransport } from "@solana/kit";import { createServer } from "node:http";const key = process.env.CARBIUM_KEY;if (!key) { console.error("Set CARBIUM_KEY."); process.exit(1);}const rpc = createSolanaRpcFromTransport( createDefaultRpcTransport({ url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh", headers: { "x-api-key": key }, }),);const once = process.argv.includes("--once");const pollMs = Number(process.env.POLL_SECONDS ?? 15) * 1000;const errors = new Map<string, number>();let body = ""; // newest exposition text, served at /metricstype Row = [labels: string, value: number];const opts = () => ({ abortSignal: AbortSignal.timeout(5_000) });const num = (x: bigint | number) => Number(x);const one = (v: number | undefined): Row[] => (v === undefined ? [] : [["", v]]);async function poll(): Promise<string> { const started = Date.now(); const names = ["getSlot/processed", "getSlot/confirmed", "getSlot/finalized", "getEpochInfo", "getRecentPerformanceSamples", "getHealth", "getVersion"]; const results = await Promise.allSettled([ rpc.getSlot({ commitment: "processed" }).send(opts()), rpc.getSlot({ commitment: "confirmed" }).send(opts()), rpc.getSlot({ commitment: "finalized" }).send(opts()), rpc.getEpochInfo({ commitment: "processed" }).send(opts()), rpc.getRecentPerformanceSamples(1).send(opts()), rpc.getHealth().send(opts()), rpc.getVersion().send(opts()), ]); results.forEach((x, i) => { if (x.status !== "rejected") return; errors.set(names[i], (errors.get(names[i]) ?? 0) + 1); console.error(`${names[i]} failed: ${x.reason instanceof Error ? x.reason.message : String(x.reason)}`); }); const [p, c, f, e, s, h, v] = results; const epoch = e.status === "fulfilled" ? e.value : undefined; const sample = s.status === "fulfilled" ? s.value[0] : undefined; const slots = ([["processed", p], ["confirmed", c], ["finalized", f]] as const).flatMap(([level, x]): Row[] => x.status === "fulfilled" ? [[`{commitment="${level}"}`, num(x.value)]] : [], ); const lag = p.status === "fulfilled" && f.status === "fulfilled" ? Math.max(0, num(p.value) - num(f.value)) : undefined; const out: string[] = []; const add = (name: string, type: "gauge" | "counter", help: string, rows: Row[]) => { const id = `carbium_solana_${name}`; if (rows.length) out.push(`# HELP ${id} ${help}`, `# TYPE ${id} ${type}`, ...rows.map(([l, val]) => `${id}${l} ${val}`)); }; add("slot", "gauge", "Newest slot at each commitment.", slots); add("finalized_lag_slots", "gauge", "Processed slot minus finalized slot, at least 0.", one(lag)); add("block_height", "gauge", "Block height at processed.", one(epoch && num(epoch.blockHeight))); add("epoch", "gauge", "Current epoch.", one(epoch && num(epoch.epoch))); add("epoch_progress_ratio", "gauge", "Share of the epoch's slots already passed.", one(epoch && num(epoch.slotIndex) / num(epoch.slotsInEpoch))); add("transactions_per_second", "gauge", "Transactions per second over the newest sample window.", one(sample && num(sample.numTransactions) / num(sample.samplePeriodSecs))); add("slots_per_second", "gauge", "Slots per second over the newest sample window.", one(sample && num(sample.numSlots) / num(sample.samplePeriodSecs))); add("health_ok", "gauge", "1 when getHealth answered ok.", [["", h.status === "fulfilled" ? 1 : 0]]); add("version_info", "gauge", "Node version as a label.", v.status === "fulfilled" ? [[`{solana_core="${v.value["solana-core"]}"}`, 1]] : []); add("poll_errors_total", "counter", "Failed calls since start, by call.", [...errors].map(([k, n]): Row => [`{call="${k}"}`, n])); add("poll_duration_seconds", "gauge", "Duration of the last poll.", one((Date.now() - started) / 1000)); return out.join("\n") + "\n";}if (!once) { const host = process.env.METRICS_HOST ?? "127.0.0.1"; const port = Number(process.env.METRICS_PORT ?? 9464); createServer((req, res) => { const hit = req.url === "/metrics" && body !== ""; res.writeHead(hit ? 200 : 404, { "content-type": "text/plain; version=0.0.4" }); res.end(hit ? body : ""); }).listen(port, host, () => console.log(`serving http://${host}:${port}/metrics`));}for (;;) { body = await poll(); if (once) { process.stdout.write(body); break; } await new Promise((r) => setTimeout(r, pollMs));}
run: node main.ts
What it costs against your limits
getSlot, getHealth and getVersion are cached reads at 1 cell each, and Free allows 5 req/s of that class. The exporter sends five of them every 15 seconds, about 0.33 req/s or 7% of Free's rate. `getEpochInfo` and `getRecentPerformanceSamples` add two more calls per poll.
The calls of one poll leave together. A class absorbs bursts up to 1,024 cells or one second of its rate, whichever is larger. If every call cost 50 cells, as getTransaction does, the seven would come to 350 cells and still fit.
Limits are per account, so all your keys share one budget. The exporter does not retry inside a poll: a 429 counts as a failed call and the next poll tries again. Credits meter this RPC work as well.
Where it ends
- It shows one node's answers through one endpoint. Cluster-wide figures such as stake, validator counts or gossip are not in it.
- A poll every 15 seconds misses a dip that starts and ends between two polls.
- TPS and slots per second step once per sample window, so chart them as trends over minutes.
- It reports no priority fees. Priority fee per compute unit covers fee reads.
- The error counter resets when the process restarts, so write panels with increase() or rate().
- The /metrics endpoint has no authentication and no TLS. It is meant for loopback or a private network behind your proxy.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| The exporter exits at start with Set CARBIUM_KEY. | Export the variable in the shell or the unit that starts it. Keep the key in an environment file that unit reads. Neither prometheus.yml nor Grafana ever needs it. |
| Every poll logs a 401 for each call, and only carbium_solana_health_ok, carbium_solana_poll_duration_seconds and the error counter appear. | 401 means Carbium did not know the key, an UNKNOWN_KEY error. Put the whole key in CARBIUM_KEY, with no quotes and no Bearer prefix. |
| The error counter climbs for several calls in the same polls and the log shows 429. | The account's calls are over its rate, and all its keys share that rate. Raise POLL_SECONDS, or find the other traffic on the account. A 429 carries a retry-after hint. |
| Prometheus shows the target down with a 404 or a refused connection. | The path must be /metrics: the exporter answers 404 for any other path and until its first poll has finished. A refused connection from another machine means the default loopback bind; set METRICS_HOST to an address that machine can reach. |
| The finalized and processed slot lines overlap on the chart and the lag stat reads 0 or 1. | That is the normal picture. Chart the lag stat for the gap and the slot panel for direction. |
Questions
Why poll on a timer instead of on each scrape?
A second Prometheus or a hand-run curl of /metrics would each add calls on your limits. A timer holds the cost at 28 calls a minute whatever reads /metrics.
Can a WebSocket slot subscription feed Grafana instead?
It can: slot subscriptions open at 5 credits and then cost 20 credits per MiB sent, Free carries 5 sockets, and a slot its leader never produced sends no slotNotification, so the stream skips it. For panels that refresh every 15 seconds the polled reads are simpler.
Why does the slot panel read three commitments?
The gap between processed and finalized shows how the cluster is finalizing, and the lag stat reads it as one number. Three cheap calls draw that gap directly.
Where does Grafana get its history?
From Prometheus, which stores every scrape. The exporter keeps only the newest copy in memory, so retention follows your Prometheus settings.