Alerts
An Alert watches one chart on a dashboard, or
one saved exploration, and starts an incident when its condition holds: a
threshold on the value, a relative change, or an anomaly_rrcf deviation
from the predicted value. The incident goes to escalationTarget, your current
team by default or an escalation policy, through the alert’s own call, sms,
email, push and criticalAlert channels.
Alert on a chart
Section titled “Alert on a chart”Declare the chart, then the alert with the chart’s dashboardId and chartId:
const app = yield* BetterStack.Telemetry.Source("app-logs", { platform: "http" });const dashboard = yield* BetterStack.Telemetry.Dashboard("app", { name: "Production app" });const errors = yield* BetterStack.Telemetry.DashboardChart("errors", { dashboardId: dashboard.id, ...Chart.line({ name: "Errors", sql: Chart.timeSeries({ where: `${Chart.json("level")} = 'error'` }), }),});An incident when errors pass 100 in five minutes:
yield* BetterStack.Telemetry.Alert("error-spike", { name: "Error spike", dashboardId: dashboard.id, chartId: errors.id, alertType: "threshold", operator: "higher_than", value: 100, sourceVariable: Output.interpolate`source:${app.tableName}`, aggregationInterval: 300, checkPeriod: 60, confirmationPeriod: 300, recoveryPeriod: 300, email: true,});sourceVariable names the sources the alert runs on, as source: followed by
source table names.
aggregationInterval, checkPeriod, confirmationPeriod and recoveryPeriod
are in seconds.
Alert on an exploration
Section titled “Alert on an exploration”An alert on a saved exploration
takes explorationId instead. paused: true keeps it from checking until you
turn it on:
const rate = yield* BetterStack.Telemetry.Exploration("error-rate", { ...Chart.exploration(Chart.line({ sql: Chart.timeSeries() })),});yield* BetterStack.Telemetry.Alert("rate", { explorationId: rate.id, alertType: "threshold", operator: "higher_than", value: 1000, checkPeriod: 60, paused: true,});An alert watches exactly one chart or one exploration. dashboardId, chartId
and explorationId are create-only: changing one replaces the alert.
Where next
Section titled “Where next”- Dashboards: the charts alerts watch.
- Escalation policies: where the incident can go.
- Reference:
Alert. - Better Stack: Alerts (API).