Skip to content
betterstack-alchemyUnofficial

Dashboards

A Dashboard shows charts over your logs, metrics and traces. The dashboard holds the time range, refresh interval and query variables. Its charts and section dividers are resources of their own, DashboardChart and DashboardSection, that point at it by dashboardId. Each chart is a set of SQL queries over the dashboard’s source, laid out on a 12-column grid.

Production appdashboard · now-6h
Errorsline_chart · w 8
Errorsnumber_chart · w 4
Runbookmarkdown · w 12
app-logssource
  • Errorsqueries {{source}} →app-logs
Charts sit inside the dashboard on its 12-column grid. Their SQL reads the dashboard's source through the {{source}} variable, bounded by the dashboard's range.
alchemy.run.ts
const app = yield* BetterStack.Telemetry.Dashboard("app", {
name: "Production app",
dateRangeFrom: "now-6h",
dateRangeTo: "now",
});

A dashboard can also start from a template (templateId) or be set up for a source (sourceId). Both are create-only, so changing one replaces it. Telemetry.dashboardTemplates() lists the templates.

Telemetry.Chart builds a chart’s chartType, queries and settings, and the SQL every time-series chart repeats. Spread it into the chart’s props next to dashboardId and its place on the grid (x, y, w, h):

alchemy.run.ts
const errors = `${Chart.json("level")} = 'error'`;
yield* BetterStack.Telemetry.DashboardChart("errors", {
dashboardId: app.id,
...Chart.line({ name: "Errors", sql: Chart.timeSeries({ where: errors }) }),
x: 0,
y: 0,
w: 8,
h: 4,
});

Chart.json("level") reads a field of the log’s JSON with the right JSONExtract. Chart.timeSeries({ where }) is the query for one value per time bucket over the dashboard’s range:

SELECT {{time}} AS time, count(*) AS value FROM {{source}}
WHERE dt BETWEEN {{start_time}} AND {{end_time}} AND (level = 'error') GROUP BY time

Chart.total is one value over the whole range, for a number or gauge chart. settings colours it by thresholds:

alchemy.run.ts
yield* BetterStack.Telemetry.DashboardChart("error-count", {
dashboardId: app.id,
...Chart.number({
name: "Errors",
sql: Chart.total({ where: errors }),
settings: { colorMode: "high_red", colorUpperThreshold: 100, colorLowerThreshold: 10 },
}),
x: 8,
y: 0,
w: 4,
h: 4,
});

The helpers cover line, bar, number, table, pie, gauge, heatmap, scatter, logs (a live tail of matching lines) and markdown.

alchemy.run.ts
yield* BetterStack.Telemetry.DashboardChart("runbook", {
dashboardId: app.id,
...Chart.markdown("On call? Start with the [runbook](https://wiki.example.com/runbook)."),
x: 0,
y: 4,
w: 12,
h: 2,
});

The helpers are optional. A chart takes chartType and queries as the API takes them:

alchemy.run.ts
yield* BetterStack.Telemetry.DashboardChart("slow", {
dashboardId: app.id,
chartType: "table_chart",
name: "Slowest endpoints",
queries: [
{
queryType: "sql_expression",
sqlQuery:
"SELECT JSONExtract(raw, 'path', 'Nullable(String)') AS path, avg(JSONExtract(raw, 'duration_ms', 'Nullable(Float64)')) AS value FROM {{source}} WHERE dt BETWEEN {{start_time}} AND {{end_time}} GROUP BY path ORDER BY value DESC LIMIT 10",
},
],
});

queries and settings are compared against your previous deploy rather than the live chart, so an edit made in the web app stays until you change the chart here.

A DashboardSection is a full-width divider over the charts below it, optionally collapsed:

alchemy.run.ts
yield* BetterStack.Telemetry.DashboardSection("jobs", {
dashboardId: app.id,
name: "Background jobs",
collapsed: true,
});

variables add filters the charts can read, such as an environment picker:

alchemy.run.ts
yield* BetterStack.Telemetry.Dashboard("by-env", {
name: "By environment",
variables: [
{ name: "env", variableType: "select_value", defaultValues: ["production", "staging"] },
],
});

An update replaces every variable. The built-in time, start_time, end_time and source variables are always there.

alchemy.run.ts
const production = yield* BetterStack.Telemetry.DashboardGroup("production", {
name: "Production",
});
yield* BetterStack.Telemetry.Dashboard("checkout", {
name: "Checkout",
dashboardGroupId: production.id,
});

Deleting a DashboardGroup keeps its dashboards, outside any group.

An Exploration is one saved chart in Explore. Chart.exploration(...) turns any helper’s chart into its props, and an ExplorationGroup holds related ones:

alchemy.run.ts
const monitoring = yield* BetterStack.Telemetry.ExplorationGroup("monitoring", {
name: "Production monitoring",
});
yield* BetterStack.Telemetry.Exploration("error-rate", {
name: "Error rate",
dateRangeFrom: "now-24h",
dateRangeTo: "now",
explorationGroupId: monitoring.id,
...Chart.exploration(Chart.line({ sql: Chart.timeSeries({ where: errors }) })),
});

Declare it with its exact name and deploy with --adopt to take it over, or reference it read-only by the number in its address:

alchemy.run.ts
const existing = BetterStack.Telemetry.Dashboard.lookup({ id: "1234" });