Durable.Stats (Durable v2.0.2)

View Source

Aggregate health of a Durable instance, read straight from its tables — the numbers behind the dashboard's Overview and Workflow pages, available to your own alerts and dashboards too.

Postgres is the source of truth here, so these work across nodes and survive restarts; use Durable.Telemetry for live per-node signals.

Common options

  • :durable — instance name (default Durable)
  • :since / :until — the window (DateTime; default the last 24 hours)
  • :workflow — limit to one workflow name
  • :include_children — count child runs too (default false: parallel fan-out and called workflows would otherwise inflate every number)

A run counts as started in the window by inserted_at and finished by completed_at. "Failed" here means failed, rolled back (compensated) or rollback-failed — every run that didn't do what it set out to.

Returns

Every function returns {:ok, result} or {:error, reason}, and has a twin ending in ! that returns the result or raises ArgumentError:

{:ok, stats} = Durable.Stats.overview(workflow: "fulfill_order")
stats = Durable.Stats.overview!(workflow: "fulfill_order")

An option of the wrong type or range is {:error, {:invalid_option, key}}: a :since that isn't a DateTime, a negative :limit, bucket_seconds: 0. Durable.Query.Opts has the whole contract.

Summary

Functions

Failures grouped by what went wrong: error type, message with numbers replaced by <n> (so "timeout after 1503ms" and "after 1499ms" group), and the step it happened at. Biggest group first.

Like error_groups/1, but returns the groups or raises ArgumentError.

Workflows with failures in the window, worst first, each with its biggest error group

Like failing_workflows/1, but returns the workflows or raises ArgumentError.

Workflow keys over the window, for one workflow with :workflow or for all

Like keys/1, but returns the numbers or raises ArgumentError.

Headline numbers for the window

Like overview/1, but returns the numbers or raises ArgumentError.

Each queue's depth per minute over the window, from Durable.Queue.Sampler, oldest first. Minutes with no sample (no node was up) are absent.

Like queue_history/1, but returns the history or raises ArgumentError.

Every queue's state right now — configured queues are listed even when idle

Like queues/1, but returns the queues or raises ArgumentError.

Per-step performance over attempts that started in the window, in the order steps first ran. Durations are active time — sleeps and waits are not attempts. Compensations are included with compensation: true.

Like step_performance/1, but returns the steps or raises ArgumentError.

The window cut into :bucket_seconds (default: ~48 buckets), oldest first, zero-filled

Like timeline/1, but returns the buckets or raises ArgumentError.

Every workflow that has run, with its numbers for the window — one grouped query, for a catalog page. Busiest first.

Like workflows/1, but returns the workflows or raises ArgumentError.

Functions

error_groups(opts \\ [])

@spec error_groups(keyword()) ::
  {:ok, [map()]} | {:error, Durable.Query.Opts.reason()}

Failures grouped by what went wrong: error type, message with numbers replaced by <n> (so "timeout after 1503ms" and "after 1499ms" group), and the step it happened at. Biggest group first.

[%{workflow: "fulfill_order", step: "ship_order", type: "RuntimeError",
   message: "carrier API returned <n>", count: 41,
   first_at: ~U[...], last_at: ~U[...], rolled_back: 41}]

:limit is the most groups returned (default 20).

{:ok, groups} = Durable.Stats.error_groups(limit: 5)
groups = Durable.Stats.error_groups!(limit: 5)

error_groups!(opts \\ [])

@spec error_groups!(keyword()) :: [map()]

Like error_groups/1, but returns the groups or raises ArgumentError.

failing_workflows(opts \\ [])

@spec failing_workflows(keyword()) ::
  {:ok, [map()]} | {:error, Durable.Query.Opts.reason()}

Workflows with failures in the window, worst first, each with its biggest error group:

[%{workflow: "fulfill_order", failed: 41, finished: 660, failure_rate: 0.062,
   last_failed_at: ~U[...], top_error: %{type:, message:, step:, count:}}]

:limit is the most workflows returned (default 5).

{:ok, failing} = Durable.Stats.failing_workflows()
failing = Durable.Stats.failing_workflows!()

failing_workflows!(opts \\ [])

@spec failing_workflows!(keyword()) :: [map()]

Like failing_workflows/1, but returns the workflows or raises ArgumentError.

keys(opts \\ [])

@spec keys(keyword()) :: {:ok, map()} | {:error, Durable.Query.Opts.reason()}

Workflow keys over the window, for one workflow with :workflow or for all:

%{
  keyed: true,          # the workflow has started a run with a key
  held: 1_284,          # keys held right now
  readded: 3_912,       # starts that found their key taken
  dropped: 41,          # ...whose input differed and was dropped
  errors: 12,           # ...answered with {:error, {:key_taken, id}}
  replaced: 3,          # ...that cancelled the holder (:cancel_existing)
  sent: 9,              # ...sent to the holder as an event ({:send_event, _})
  debounced: 30,        # ...that gave a debounced run newer input
  handed_off: 87,       # keys a start took from a finished run
  timeline: [%{at: ~U[...], returned: 160, errors: 1, replaced: 0,
               sent: 2, debounced: 5}, ...],
  top: [%{key: "article:17", readded: 48, dropped: 0,
          holder_id: "…", holder_status: :completed}, ...]
}

The counts come from Durable.Activity, which keeps a week, so they cover at most the last 7 days. :bucket_seconds and :limit (top keys, default

  1. are optional. Its timeline has every bucket, so like timeline/1 a window cut into more than 10,000 is {:error, {:too_many_buckets, count}}.

    } = Durable.Stats.keys(workflow: "process_article") %{held: held} = Durable.Stats.keys!(workflow: "process_article")

keys!(opts \\ [])

@spec keys!(keyword()) :: map()

Like keys/1, but returns the numbers or raises ArgumentError.

overview(opts \\ [])

@spec overview(keyword()) :: {:ok, map()} | {:error, Durable.Query.Opts.reason()}

Headline numbers for the window:

%{
  started: 12_482,
  finished: %{completed: 12_031, failed: 180, compensated: 34, cancelled: 21, ...},
  failure_rate: 0.017,            # failed-like ÷ finished
  duration_ms: %{p50: 380, p95: 4_210, max: 11_800},   # completed runs
  queue_wait_ms: %{p50: 120, p95: 1_300},             # scheduled → started
  backlog: 37,                    # ready to start right now
  waiting: %{input: 9, event: 96, sleeping: 23}       # right now
}

Returned as {:ok, numbers}; overview!/1 returns the map itself.

{:ok, %{failure_rate: rate}} = Durable.Stats.overview(since: hour_ago)
%{failure_rate: rate} = Durable.Stats.overview!(since: hour_ago)

overview!(opts \\ [])

@spec overview!(keyword()) :: map()

Like overview/1, but returns the numbers or raises ArgumentError.

queue_history(opts \\ [])

@spec queue_history(keyword()) ::
  {:ok, %{required(String.t()) => [map()]}}
  | {:error, Durable.Query.Opts.reason()}

Each queue's depth per minute over the window, from Durable.Queue.Sampler, oldest first. Minutes with no sample (no node was up) are absent.

%{"default" => [%{at: ~U[2026-10-16 09:00:00Z], ready: 31, scheduled: 4,
                  running: 8, waiting: 120}, ...]}

{:ok, history} = Durable.Stats.queue_history(since: hour_ago)
history = Durable.Stats.queue_history!(since: hour_ago)

queue_history!(opts \\ [])

@spec queue_history!(keyword()) :: %{required(String.t()) => [map()]}

Like queue_history/1, but returns the history or raises ArgumentError.

queues(opts \\ [])

@spec queues(keyword()) :: {:ok, [map()]} | {:error, Durable.Query.Opts.reason()}

Every queue's state right now — configured queues are listed even when idle:

[%{queue: "default", paused: false, running: 8, ready: 31, scheduled: 412,
   oldest_ready_at: ~U[...], done_last_5m: 910, wait_p95_ms: 1_300}]

wait_p95_ms is scheduled → started over the last hour.

{:ok, queues} = Durable.Stats.queues()
queues = Durable.Stats.queues!()

queues!(opts \\ [])

@spec queues!(keyword()) :: [map()]

Like queues/1, but returns the queues or raises ArgumentError.

step_performance(opts \\ [])

@spec step_performance(keyword()) ::
  {:ok, [map()]} | {:error, Durable.Query.Opts.reason()}

Per-step performance over attempts that started in the window, in the order steps first ran. Durations are active time — sleeps and waits are not attempts. Compensations are included with compensation: true.

failed_runs counts runs whose last attempt at the step failed — runs that gave up there, as opposed to failed_attempts that a retry recovered.

[%{workflow: "fulfill_order", step: "ship_order", compensation: false,
   runs: 660, attempts: 771, failed_attempts: 117, failed_runs: 41,
   retried_runs: 121, p50_ms: 640, p95_ms: 2_140, max_ms: 6_040}]

{:ok, steps} = Durable.Stats.step_performance(workflow: "fulfill_order")
steps = Durable.Stats.step_performance!(workflow: "fulfill_order")

step_performance!(opts \\ [])

@spec step_performance!(keyword()) :: [map()]

Like step_performance/1, but returns the steps or raises ArgumentError.

timeline(opts \\ [])

@spec timeline(keyword()) :: {:ok, [map()]} | {:error, Durable.Query.Opts.reason()}

The window cut into :bucket_seconds (default: ~48 buckets), oldest first, zero-filled:

[%{at: ~U[...], started: 260, completed: 251, failed: 6, cancelled: 1,
   failure_rate: 0.023, p50_ms: 1_900, p95_ms: 4_200}, ...]

failed includes rolled-back runs; p50_ms/p95_ms are over runs completed in the bucket (nil when none).

Every bucket is returned, empty or not, so a window cut into more than 10,000 of them returns {:error, {:too_many_buckets, count}} instead: ask for a shorter window or a larger :bucket_seconds. A :bucket_seconds that isn't a whole number above zero is {:error, {:invalid_option, :bucket_seconds}}.

{:ok, buckets} = Durable.Stats.timeline(bucket_seconds: 3_600)
buckets = Durable.Stats.timeline!(bucket_seconds: 3_600)

timeline!(opts \\ [])

@spec timeline!(keyword()) :: [map()]

Like timeline/1, but returns the buckets or raises ArgumentError.

workflows(opts \\ [])

@spec workflows(keyword()) :: {:ok, [map()]} | {:error, Durable.Query.Opts.reason()}

Every workflow that has run, with its numbers for the window — one grouped query, for a catalog page. Busiest first.

[%{workflow: "fulfill_order", module: "Elixir.App.Orders", started: 660,
   finished: 655, failed: 41, failure_rate: 0.063, retried: 121,
   p50_ms: 1_920, p95_ms: 4_210, running: 4, waiting: 0,
   last_run_at: ~U[...]}]

retried counts runs where some step needed a second attempt. running, waiting and last_run_at are as of now, not limited to the window.

{:ok, workflows} = Durable.Stats.workflows(since: day_ago)
workflows = Durable.Stats.workflows!(since: day_ago)

workflows!(opts \\ [])

@spec workflows!(keyword()) :: [map()]

Like workflows/1, but returns the workflows or raises ArgumentError.