The code in this repo is reproducible by design: docker compose up rebuilds
the warehouse and the sensor stream exactly. Metabase, however, is configured
by hand through its web UI, and that configuration lives inside Metabase's own
database — not in Git. This runbook captures those manual steps so anyone (or
future-you) can rebuild the dashboard from scratch.
Why this file exists: the GUI clicks are the one un-reproducible seam in an otherwise reproducible project. Section 7 explains how that seam could be closed entirely by configuring Metabase as code.
docker compose up --buildThis builds the sensor image and starts five containers: postgres,
metabase, and three machines (machine-cnc01, machine-cnc02,
machine-press01). Each machine backfills ~2000 historical cycles immediately,
then streams live, so there is data to query within seconds.
Leave this terminal running. To stop later: Ctrl+C, then docker compose down
(add -v to also wipe the stored data for a clean slate).
The logs show each machine backfilling, then streaming live cycles (note the
wear= counter climbing and resetting, and state= switching between running /
idle / down):
In a second terminal, confirm rows are landing in Postgres:
docker compose exec postgres psql -U sensors -d plant \
-c "SELECT machine_id, count(*) FROM sensor_readings GROUP BY 1;"Expected: three machines, each with a few thousand rows and climbing. This confirms the OT → warehouse half of the pipeline before touching the BI layer.
You can also connect with a single connection string instead of flags:
docker compose exec postgres \
psql "postgresql://sensors:sensors_pw@localhost:5432/plant" \
-c "SELECT count(*) FROM sensor_readings;"-
Open http://localhost:3000 (first load takes ~30s while Metabase initialises) and create the admin account.
-
Add database → PostgreSQL. Fill the connection. Either:
- paste the connection string
jdbc:postgresql://postgres:5432/plantinto the Connection string field to pre-fill host/port/database, then add the credentials below; or - type the fields directly.
Field Value Note Host postgresthe Docker service name, NOT localhost— Metabase reaches the DB over the internal Docker networkPort 5432Database name plantUsername sensorsPassword sensors_pw - paste the connection string
-
Save. Metabase syncs the schema and you'll see the
Sensor Readingstable.Browsing that table confirms the warehouse is connected and populated:
Gotcha: using
localhostas the host is the most common mistake — inside the Metabase container,localhostmeans Metabase itself, not Postgres.
For each query file in ../sql/kpi/:
-
+ New → SQL query → plant. The + New menu (top right) is where every question and the dashboard are created:
-
Open the
.sqlfile, copy all, paste into the editor, click Run (▶). The results appear as a table below the editor: -
Confirm it returns rows, then click the Visualization button (bottom-left) to open the chart picker. It opens on the current type (here, Table):
Pick the chart type for this question — e.g. Line for hourly downtime — and the preview updates immediately:
Chart type per question:
Question (paste from) Visualization Axis / settings 01_oee_by_machine.sqlBar X = machine_id, Y =oee02_failure_breakdown.sqlBar X = failure_type, Y =events03_hourly_downtime.sqlLine X = hour, Y =pct_downtime04_tool_wear_trend.sqlLine X = ts, Y =tool_wear_min05_data_quality_checks.sqlTable leave as table; all values should be 0 -
Save each into the "Our analytics" collection with a clear name (e.g. OEE by Machine). A one-line Description is optional but shows up on hover and in the collection list.
Verify a saved question by opening it and checking its column headers match the table above — that confirms each question holds its own query and not, say, the OEE query pasted five times.
-
+ New → Dashboard. Name it
Plant Operations, save to "Our analytics". You start in edit mode with an empty grid: -
Click + (Add a card); a panel lists your saved questions — click each of the five to drop it onto the canvas:
-
Drag / resize cards. Recommended layout, reading descriptive → diagnostic:
- Row 1: OEE by Machine (wide) — the headline.
- Row 2: Failure Breakdown by Type + Downtime % by Hour.
- Row 3: Tool Wear Trend + Data Quality Checks.
- Row 4 (optional, live): Live Sensor Monitor (all-machines tool wear) — pairs with the single-machine Tool Wear Trend for a focus-vs-compare view.
-
(Optional) Add a machine filter: click the filter icon, then choose a filter type. For filtering by machine, use Text or Category:
After adding it, connect the filter to each card by mapping it to that card's
machine_idcolumn. -
Save.
The finished result — five cards reading descriptive → diagnostic:
Filter caveat: the Tool Wear question is hardcoded to a single machine (
CNC-01) and shows the live tail (ORDER BY ts DESC LIMIT 1000), so it has nomachine_idvariable and can't connect to the dashboard filter. Either leave it pinned as a fixed example, or change itsWHEREclause to a Field Filter (WHERE {{machine_id}}mapped to Sensor Readings → Machine Id) so it follows the filter like the other cards. A plain{{machine_id}}text variable will NOT connect to a category filter — it must be a Field Filter.
The sensors stream continuously, so Postgres is always gaining new rows — but a Metabase chart runs its SQL once when it loads and then shows that snapshot. It doesn't re-query on its own until you tell it to. To turn the dashboard into a continuously-updating view, enable auto-refresh:
- Open the dashboard and click the clock icon (top-right).
- Pick an interval — 1 minute is the shortest.
Now the whole dashboard re-queries on that cadence and reflects the newest data without a manual reload.
Prove the stream is actually live by counting rows twice, a minute apart — the number climbs:
docker compose exec postgres psql -U sensors -d plant \
-c "SELECT count(*) FROM sensor_readings;"Honest wording: Metabase's fastest auto-refresh is 1 minute, so this is near-real-time, not millisecond-live. For an operations/BI dashboard that's exactly what "real-time" means in practice — nobody watches OEE tick by the second. True sub-second streaming would need a different tool (e.g. Grafana with a streaming source). The data stream itself is genuinely live; only the dashboard's refresh is on a timer.
"My live chart is stuck on old data." Two things to know. (1) Hourly / aggregate charts dilute new rows into a large current-hour bucket, so they barely move minute to minute — a new point only appears when the hour rolls over. To see movement, plot a raw per-row value against
ts(e.g. tool wear or torque). (2) Metabase returns at most 2000 rows per query; an unboundedORDER BY tshands back the first 2000 — the OLDEST rows (the backfill) — so the chart freezes on ancient history. Filter to a recent window (WHERE ts > now() - interval '5 minutes') so the result is small and current;now()re-evaluates on each refresh, sliding the window forward. The ready-made example issql/kpi/06_live_sensor_monitor.sql.
The all-machines live monitor (06) — three independent sawtooths, each machine
wearing and resetting on its own cycle, extending right on every refresh:
Sections 3–5 are manual because Metabase stores its configuration in its own application database, not in this repo. For a portfolio that trade-off is fine — this runbook documents the clicks. In a production setting you would not click; you would manage Metabase as code, so the dashboard is version-controlled, reviewable, and rebuildable without anyone touching a mouse. Two standard approaches:
- Metabase serialization. Metabase can export all questions, dashboards, and
database connections to YAML and re-import them
(
docker compose exec metabase ... export/import, or the equivalent API calls). You commit that YAML to the repo; restoring the dashboard becomes one command instead of this whole runbook. - Metabase REST API. Every action in Sections 3–5 (add database, create card, create dashboard, add filter) has an API endpoint. A small setup script could perform them in order, making the entire BI layer reproducible from code.
A further step is to move the transformations themselves out of Metabase into a tool like dbt: the KPI SQL would live in version-controlled models that dbt runs against Postgres, and Metabase would query the resulting tables. That makes the SQL the single source of truth (rather than the copies pasted into Metabase), with tests and lineage on top.
None of this is necessary for the demo — but knowing where the manual seam is, and how you'd close it, is the point. The honest summary:
The pipeline (Docker, Postgres, sensors) is reproducible from code. The BI layer is currently reproducible from this runbook. To make the BI layer reproducible from code too, manage Metabase via serialization/API and move the transformations into dbt.














