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.
- Errorsqueries {{source}} →app-logs
Create a dashboard
Section titled “Create a dashboard”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.
Add a chart with the Chart helpers
Section titled “Add a chart with the Chart helpers”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):
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 timeA single number
Section titled “A single number”Chart.total is one value over the whole range, for a number or gauge chart.
settings colours it by thresholds:
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.
A text block
Section titled “A text block”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,});Write the query yourself
Section titled “Write the query yourself”The helpers are optional. A chart takes chartType and queries as the API
takes them:
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.
Divide it into sections
Section titled “Divide it into sections”A DashboardSection is a full-width
divider over the charts below it, optionally collapsed:
yield* BetterStack.Telemetry.DashboardSection("jobs", { dashboardId: app.id, name: "Background jobs", collapsed: true,});Add variables
Section titled “Add variables”variables add filters the charts can read, such as an environment picker:
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.
Group dashboards
Section titled “Group dashboards”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.
Save an exploration
Section titled “Save an exploration”An Exploration is one saved chart in
Explore. Chart.exploration(...) turns any helper’s chart into its props, and
an ExplorationGroup holds related
ones:
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 }) })),});Bring a web-app dashboard under the stack
Section titled “Bring a web-app dashboard under the stack”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:
const existing = BetterStack.Telemetry.Dashboard.lookup({ id: "1234" });Where next
Section titled “Where next”- Alerts: incidents from a chart or an exploration.
- Sources & ingest: what charts read.
- Reference:
Dashboard,DashboardChart,DashboardSection,DashboardGroup,Exploration,ExplorationGroup. - Better Stack: SQL queries in dashboards, Dashboard variables.