TimelessMetrics.Alert (timeless_metrics v6.0.10)

Copy Markdown View Source

Alert engine that evaluates threshold rules against metric data.

Piggybacks on the rollup tick interval — no extra timer. Call evaluate/1 from the rollup tick or manually.

State transitions: ok → pending → firing → resolved Delivers structured JSON webhooks on firing and resolved transitions.

Summary

Functions

Acknowledge a history entry by ID.

Clear history entries.

Create an alert rule.

Delete an alert rule and its state.

Evaluate all enabled alert rules against current data.

List recent alert history entries, newest first.

List all alert rules with their current state.

Update an alert rule (partial update).

Functions

acknowledge_alert(db, history_id)

Acknowledge a history entry by ID.

clear_history(db, opts \\ [])

Clear history entries.

Options:

  • :acknowledged_only - only delete acknowledged entries (default true)
  • :before - delete entries older than this timestamp (default: 7 days ago)

create_rule(db, opts)

Create an alert rule.

Returns {:ok, id}.

delete_rule(db, rule_id)

Delete an alert rule and its state.

evaluate(store)

Evaluate all enabled alert rules against current data.

Called from the rollup tick or manually.

list_history(db, opts \\ [])

List recent alert history entries, newest first.

Options:

  • :limit - max entries (default 50)
  • :rule_id - filter by rule ID
  • :acknowledged - filter: true, false, or nil (all)

list_rules(db)

List all alert rules with their current state.

update_rule(db, rule_id, opts)

Update an alert rule (partial update).

Supported fields: name, metric, labels, condition, threshold, duration, aggregate, webhook_url, enabled. Only provided fields are updated.

Returns :ok.