A minimal PostgreSQL metrics collector with a companion web dashboard. Single static binaries, zero runtime dependencies.
- Features
- Prerequisites
- Quick Start
- Web Dashboard (yama-web)
- How collection is scheduled
- Adding Metrics
- Development
- Project Structure
- Collects PostgreSQL metrics via configurable SQL queries
- Per-metric enable/disable and collection interval overrides
- Embedded BadgerDB storage — no external database server
- REST API for querying collected data points
- Web dashboard (
yama-web): live auto-refreshing panels served by a standalone binary - Graceful shutdown on SIGTERM/SIGINT
- Static binaries, pure Go: copy and run
- A running PostgreSQL instance
- Writable filesystem for the data directory
make build
Produces ./bin/yama (the agent) and ./bin/yama-web (the dashboard
frontend).
cp configs/config.yaml.example ./config.yaml
cp configs/metrics.yaml.example ./metrics.yaml
Edit config.yaml — set at minimum postgres.host and postgres.user.
The password can be left empty and supplied via the PG_PASSWORD
environment variable.
By default the agent uses at most 1 concurrent PostgreSQL connection
(postgres.max_db_connections, minimum 1): all metric collections run
serially over it. Raise it only if the monitored instance can afford more
connections — as a rule of thumb, pick N so that the total query time of
one collection cycle comfortably fits within your shortest interval.
export PG_PASSWORD="your-password"
./bin/yama --config ./config.yaml --metrics ./metrics.yaml
All requests return a JSON array of {"timestamp":"...","value":...} points
ordered by timestamp ascending; a metric with no points in the window
returns [].
Last 3 hours up to now (the default window):
curl "http://localhost:8080/api/v1/metrics/select_1/data"
A specific time period via from/to (RFC3339 timestamps, both inclusive;
to defaults to now when omitted):
curl "http://localhost:8080/api/v1/metrics/select_1/data?from=2026-09-24T10:00:00Z&to=2026-09-24T11:00:00Z"
From a fixed point until now:
curl "http://localhost:8080/api/v1/metrics/select_1/data?from=2026-09-24T10:30:00Z"
Example response:
[
{"timestamp":"2026-09-24T10:00:05.123456789Z","value":1},
{"timestamp":"2026-09-24T10:00:15.123501002Z","value":1}
]Unparseable from/to values return 400 Bad Request with a JSON error
naming the invalid parameter; non-GET methods return 405 Method Not Allowed.
Ctrl+C or kill -TERM <pid> — the agent drains and exits cleanly.
yama-web is an independent dashboard binary: point it at any running,
unmodified agent and it serves a Grafana-style page of that agent's
metrics — no SSH, no curl, no Grafana server to install. It talks to the
agent's read-only API server-side (the browser only ever talks to the
frontend), so it can run on your laptop against a remote agent with just
the agent's HTTP port reachable.
cp configs/webui.yaml.example ./webui.yaml
cp configs/graphs.yaml.example ./graphs.yaml
webui.yaml (system settings):
| Field | Default | Meaning |
|---|---|---|
agent.host |
localhost |
Host of the YAMA agent to visualize |
agent.port |
8080 |
The agent's api.listen port |
agent.timeout |
5s |
Per-request timeout for calls to the agent |
ui.listen |
:8081 |
Dashboard listen address |
refresh.interval |
10s |
Automatic panel refresh interval |
graphs.yaml defines the panels — one per graph, in file order (at most
two per row):
graphs:
- name: "Active sessions"
metric: pg_active_sessions
description: "count(*) from pg_stat_activity"
- name: "Database activity"
metric: [db_stats.commits, db_stats.reads]
description: "several series in one panel"name is the panel title, metric is the metric name from the agent's
metrics.yaml — either a single name or a list of names, freely mixable
(any stored series, including multi-metric sub-series). A graph with
several metrics renders one panel with one line per series (distinct
colors, per-series legend); a single-metric graph keeps the
min/max/current legend. description is optional. Graphs are defined
exclusively in this file — there is no UI-side editing.
./bin/yama-web --config ./webui.yaml --graphs ./graphs.yaml
Then open http://localhost:8081.
- Each panel starts with the last hour of its metrics. Hover over the plot to inspect the nearest sample's local date, time and value. Axis labels and hover times use your browser's timezone, including daylight saving transitions. Each viewer sees their own local times after every refresh. With JavaScript disabled, the axis shows UTC. The crosshair and tooltip follow the pointer and stay visible during automatic refresh. A single-series legend shows the minimum, maximum and current value. Multi-series legends show each metric's current value in its configured color.
- An empty panel identifies the window that has no readings.
- If the agent becomes unreachable, a visible banner appears and panels switch to an error state; when the agent comes back, everything recovers automatically — no frontend restart needed. The frontend also starts fine while the agent is down.
- The page uses a light warm theme; all assets (including the vendored htmx) are embedded in the binary and served by the frontend itself — no CDN, no external requests, no Node/npm toolchain.
Choose 1m, 5m, 15m, 30m, 1h, 3h, 6h, 12h or 24h for the dashboard. Each panel inherits that range until you choose a panel override. Clearing the override restores the dashboard selection. A relative range advances with each poll. The URL records your choices so you can share a view or revisit it with Back.
| Example query | Result |
|---|---|
?range=3h |
All panels show the last three hours. |
?range=3h&p.Active%20Sessions.range=15m |
Active Sessions shows fifteen minutes and other panels inherit three hours. |
?from=2026-10-20T18:00:00Z&to=2026-10-20T21:00:00Z |
Polls repeatedly fetch the same fixed period. |
Use either range or a complete, increasing RFC3339 from and to pair.
Prefix any of these keys with p.<graph name>. for one panel. URL-encode
graph names and timestamp offsets. Invalid or conflicting panel selections
inherit the dashboard range; an invalid dashboard range defaults to one hour.
At twelve hours and above, ticks include the local date. For dense series,
each chart draws up to 1,000 representative samples per series. The visible
curve retains bucket extrema and the first and last readings; the legend
and vertical scale use all in-range samples.
Chart summaries display full decimal values. Each visible series also shows its arithmetic mean over all readings in the panel's selected period, using its override or the inherited dashboard range. The mean uses the full data before rendering reduction and rounds to the nearest whole number.
On a multi-series panel, click a legend chip to isolate that metric. Ctrl+click (Cmd+click on macOS) adds or removes a series. Clicking the sole visible series, or removing the last selected series restores the complete graph. Dimmed chips remain available for selection.
The server fetches only selected metrics and fits the scale and summaries
to them. Each metric retains its configured color. Selection is shared by
repeated URL fields such as p.Database.series=db_stats.commits and
p.Database.series=db_stats.reads. Invalid names or duplicate selections
show all series. Selection survives polling, zoom, reset and browser history.
Drag horizontally inside a chart with the mouse to inspect a smaller period. The selected panel fetches that fixed period again and fits its scale to the readings. A short enough period shows every sample within the 1,000-point budget. Other panels keep their selections.
Use Reset to restore the panel's range before zooming, or choose a preset
to return to a rolling range. Zoom and Reset update browser history and can
be shared by URL. Nested zooms keep the original reset destination in
p.<graph name>.zoomBack. Automatic and manual refresh retain zoomed bounds.
Drags shorter than eight pixels or ending outside the plot are cancelled.
Press Escape to cancel a selection. This interaction uses a desktop mouse.
Choose Off, 5s, 10s, 30s, 1m or 5m, or enter a custom whole minute/hour
interval such as 15m or 2h (one minute through 24 hours).
?refresh=30s shares the cadence; without a valid parameter the
webui.yaml refresh interval is used. Cadence changes replace the current
history entry. Off pauses both chart and connectivity polling.
Refresh now fetches all selected windows once, including while paused. Relative ranges advance to the current time; fixed ranges retain their bounds. The last-updated time uses your browser timezone and remains visible while paused. Failed updates retain the last successful time.
The embedded stylesheet in internal/web/server/assets/app.css defines
the tokens shared by panels, legends, tooltips and dashboard controls.
| Purpose | CSS custom properties |
|---|---|
| Page, panel and inset backgrounds | --bg, --panel, --surface-soft |
| Borders and chart guides | --border, --grid |
| Text, secondary text, accent and errors | --text, --muted, --accent, --error |
| Interface and detail typography | --font-ui, --font-detail |
| Spacing scale | --space-1, --space-2, --space-3, --space-4, --space-6 |
| Corner radii and floating tooltip shadow | --radius-sm, --radius-panel, --shadow-float |
The chart renderer assigns palette colors by position in the graph's
configured metric list. The matching legend chip receives --series-color.
Collection runs in cycles driven by collector.interval: the agent wakes,
determines every metric whose time since last collection has reached its
effective interval (its own interval override, else the global one), and
collects them all within that cycle — sequentially when
postgres.max_db_connections is 1 (the default), or up to that many at a
time otherwise. Every data point in a cycle carries the same timestamp:
the cycle wake time, so series stay aligned even when a cycle takes long to
drain.
Per-metric intervals interact with cycles as follows:
- The scheduler wakes exactly when the earliest metric is next due (a timer
set to
last collection + effective interval), so each metric is collected at approximately its own cadence. A shorter per-metric interval (e.g. 1s inside a 5s global) is collected every ~1s while global metrics stay on the 5s cadence. - A longer per-metric interval (e.g. 30s inside a 5s global) collects only when due — every 30s — with no redundant work.
- If a metric's previous collection is still running when it comes due again, that cycle is skipped (no queue pile-up) and it resumes on its next due cycle.
Edit metrics.yaml — no code changes required:
metrics:
- name: pg_active_sessions
query: "SELECT count(*) FROM pg_stat_activity WHERE state = 'active'"
type: gauge
interval: 5sRestart YAMA to apply changes.
Each metric declares one of three types via the type field (anything else
is rejected at startup):
| Type | Meaning | Typical use |
|---|---|---|
gauge |
A point-in-time value that can go up or down | session counts, table sizes, replication lag |
counter |
A cumulative, monotonically increasing value | pg_stat_* totals such as transactions or tuples read |
multi |
One query producing several named series | several pg_stat_* values from a single scan |
Notes:
- A
gaugeorcounterquery MUST return exactly one row with one numeric column — that value is stored as the data point (raw, for both types; rate/delta computation over counters is not performed by the agent). - Every point of one collection cycle shares the cycle timestamp (see How collection is scheduled), regardless of metric type.
A multi metric runs one query per collection that returns exactly one
row with one or more numeric columns; each column becomes its own stored
series named <metric>.<column>, typed per the columns map:
metrics:
- name: db_stats
query: "SELECT xact_commit AS commits, xact_rollback AS rollbacks, blks_read AS reads FROM pg_stat_database WHERE datname = current_database()"
type: multi
columns:
commits: counter
rollbacks: counter
reads: counter- Every column MUST be declared in
columns(with typecounterorgauge), andcolumnsis only valid onmultimetrics — invalid configurations abort startup naming the metric and field. - At runtime the query's returned columns MUST exactly match the declared set. Any mismatch (renamed, dropped, or extra column) fails that collection run only: it is logged with both column sets, no points are written, and later runs continue.
- The sub-series (
db_stats.commits,db_stats.reads, ...) are ordinary series: they appear in the agent API like any metric and can be mixed freely with other metrics in dashboard graphs. - Configured names must not collide: a declared metric named
db_stats.commitsalongside the multi metric above is rejected at startup.
make build # build both binaries (yama, yama-web)
make test # run tests
make lint # go vet + gofmt check
make css # optional: recompile the dashboard CSS (Tailwind standalone CLI)
make clean # remove build artifacts
The repo tracks the tooling configuration (.opencode/, openspec/),
but not the installed dependencies (node_modules, Go module cache).
-
Go toolchain — install Go (see
go.modfor the required version), then download modules:go mod download -
OpenSpec / Superpowers tooling (only needed for spec-driven development with OpenCode) — the plugin is pinned in
.opencode/package.json; restore it with:npm install --prefix .opencodeor run
opencode plugin add superpowersonce. Thesuperpowers-bridgeOpenSpec schema lives inopenspec/schemas/superpowers-bridge/and needs no extra setup. -
OpenSpec CLI (optional) — install the
openspecCLI if you plan to create/validate changes (openspec schema validateetc.).
cmd/yama/ Agent entry point
cmd/yama-web/ Dashboard frontend entry point
internal/config/ Agent configuration loading and validation
internal/postgres/ PostgreSQL connection management
internal/collect/ Metric collector and scheduler
internal/store/ BadgerDB storage layer
internal/api/ REST API handlers
internal/web/ Dashboard frontend (config, agent client, chart, server)
configs/ Example configuration files