Oban.Met (Oban Met v1.3.3)

View Source

Met is a distributed, compacting, multidimensional, telemetry-powered time series datastore for Oban that requires no configuration. It gathers data for queues, job counts, execution metrics, active crontabs, historic metrics, and more.

Met powers the charts and runtime details shown in the Oban Web dashboard.

Features

  • 🤖 Autonomous - Supervises a collection of autonomous modules that dynamically start and stop alongside Oban instances without any code changes.

  • 🎩 Distributed - Metrics are shared between all connected nodes via pubsub. Leadership is used to restrict expensive operations, such as performing counts, to a single node.

  • 📼 Recorded - Telemetry events and scraped data are stored in-memory as time series data. Values are stored as either gauges or space efficient "sketches".

  • 🪐 Multidimensional - Metrics are stored with labels such as node, queue, worker, etc. that can be filtered and grouped dynamically at runtime.

  • 🗜️ Compacting - Time series values are periodically compacted into larger windows of time to save space and optimize querying historic data. Compaction periods use safe defaults, but are configurable.

  • ✏️ Estimating - In supporting systems (Postgres), count queries use optimized estimates automatically for tables with a large number of jobs.

  • 🔎 Queryable - Historic metrics may be filtered and grouped by any label, sliced by arbitrary time intervals, and numeric values aggregated at dynamic percentiles (e.g. P50, P99) without pre-computed histogram buckets.

  • 🤝 Handoff - Ephemeral data storage via data replication with handoff between nodes. All nodes have a shared view of the cluster's data and, with the Oban.Notifiers.PG notifier, new nodes are caught up when they come online.

Installation

Oban Met is included with Oban Web and manual installation is only necessary in hybrid environments (separate Web and Worker nodes).

To receive metrics from non-web nodes in a system with separate "web" and "worker" applications you must explicitly include oban_met as a dependency for "workers".

{:oban_met, "~> 1.3"}

Met requires Oban v2.23 or later.

Usage

No configuration is necessary and Oban Met will start automatically in a typical application. A variety of options are provided for more complex or nuanced usage.

Querying Metrics

Met records four series, each labeled by node, queue, and state, and the job series also by worker:

  • exec_count - a gauge of jobs that finished executing each second, labeled by their state after execution, e.g. completed or retryable
  • exec_time - a sketch of job execution times
  • wait_time - a sketch of how long jobs waited in the queue before executing
  • full_count - a gauge of jobs in the database, counted periodically by the leader node

Use Oban.Met.latest/3 for current values and Oban.Met.timeslice/3 for history, filtered and grouped by any label:

Oban.Met.latest(:full_count, group: "state")
%{"available" => 9, "completed" => 80, "executing" => 5}

Oban.Met.timeslice(:exec_time, by: 5, group: "queue", operation: {:pct, 0.95})
[{11, 9970235387.03, "analysis"}, ..., {0, 1520977874.33, "events"}]

Producer checks from every node are available through Oban.Met.checks/1, and the merged crontab from every node through Oban.Met.crontab/1.

Configuration

Met starts without configuration, but every supervised component accepts options that may be provided two ways:

  • Through the application environment, where they apply to all Oban instances:

    config :oban_met, reporter: [estimate_limit: 200_000]
  • Through the plugin specification, where they apply to a single instance and take precedence over the application environment:

    {Oban.Met, reporter: [estimate_limit: 200_000]}

Options are namespaced by component: :cronitor, :examiner, :listener, :recorder, and :reporter. Most are internal and best left alone, but the sections below cover the options worth tuning.

Auto Start

Supervised Met instances start automatically along with Oban instances unless Oban is in testing mode. You can disable auto-starting globally with application configuration:

config :oban_met, auto_start: false

Then, start instances as a child directly within your Oban app's plugins:

plugins: [
  Oban.Met,
  ...
]

By default Met only starts when Oban's :testing mode is :disabled. To run Met under a specific testing mode, for example to inspect metrics during :manual tests, add the mode to :auto_testing_modes:

config :oban_met, auto_testing_modes: [:disabled, :manual]

Customizing Estimates

The estimate_limit determines when counts switch from an accurate count(*) query to a much more efficient, but less accurate, estimate function. The limit applies to each state's total across all queues: once a state reaches the limit, its count for every queue is estimated on the following checks. Estimates are only available on Postgres, and other databases always use exact counts.

The default limit is a conservative 50k, which may be too low for systems with insert spikes. This declares an override to set the limit to 200k:

{Oban.Met, reporter: [estimate_limit: 200_000]}

Customizing Check Interval

The reporter periodically counts jobs in each state/queue combination to provide the counts displayed in Oban Web. By default, counts are checked every 1 second. For systems where real-time counts aren't critical, or to reduce database load, you can increase the interval:

{Oban.Met, reporter: [check_interval: :timer.seconds(5)]}

The list of queues used for estimates is refreshed every 60 checks, so newly added queues may take longer to appear in estimated counts with a longer interval.

Explicit Migrations

Met will create the necessary estimate function automatically when possible. The migration isn't necessary under normal circumstances, but is provided to avoid permission issues or allow full control over database changes. If the database role Met connects with can't create or replace the function, counts fail on every check and the error is logged until the migration is used instead.

mix ecto.gen.migration add_oban_met

Open the generated migration and delegate the up/0 and down/0 functions to Oban.Met.Migration:

defmodule MyApp.Repo.Migrations.AddObanMet do
  use Ecto.Migration

  def up, do: Oban.Met.Migration.up()
  def down, do: Oban.Met.Migration.down()
end

Pass a :prefix to both functions, e.g. Oban.Met.Migration.up(prefix: "private"), when Oban runs in an alternate prefix.

Then configure the reporter not to auto-migrate:

config :oban_met, reporter: [auto_migrate: false]

Customizing the Estimate Function

By default the reporter installs and calls the built-in PostgreSQL oban_count_estimate function. On other Postgres-compatible engines that can't run that definition (e.g. CockroachDB) you can supply your own (prefix -> ddl) builder and keep auto_migrate enabled. The returned DDL must create a <prefix>.oban_count_estimate(state text, queue text) function returning an integer estimate:

{Oban.Met, reporter: [estimate_function: &MyApp.ObanEstimate.build/1]}

Compaction Periods

Recorded metrics are periodically compacted into coarser windows to bound memory use. Each period is a {step, duration} tuple in seconds, where step is the resolution and duration is how long values are retained at that resolution, after the periods before it. The defaults keep about three and a half hours of history:

{Oban.Met, recorder: [compact_periods: [{1, 120}, {5, 900}, {30, 2_000}, {60, 9_300}]]}

Web Charts

Oban Web's charts are rendered from these recorded metrics. Drastically shortening the periods reduces the history available to plot and may impact chart rendering.

Sketch Time Unit

Timing metrics (execution time, queue time) are stored in space-efficient quantile sketches. By default, values are recorded in :native time units (nanoseconds on most systems), which provides maximum precision but uses more space.

For reduced storage size (~20% smaller) and better bin consolidation, you can configure sketches to store timing in milliseconds:

config :oban_met, sketch_time_unit: :millisecond

This is a compile-time option that affects how timing values are binned in sketches, so changing it requires recompiling Met, e.g. mix deps.compile oban_met --force.

Cluster Consistency

All nodes in a cluster must use the same sketch_time_unit setting. Mixing units between nodes will produce incorrect aggregated metrics.

After changing this setting, existing metrics will be invalid until compaction ages them out (about three and a half hours with default compaction periods).

Summary

Functions

Retrieve stored producer checks.

Get a normalized, unified crontab from all connected nodes.

Get the unique values recently recorded for a label across all series.

Get the latest values for a series, summed and optionally grouped by a label.

Get all stored rows for a series without any filtering or aggregation.

List all recorded series along with their labels and value type.

Start a Met supervisor for an Oban instance.

Summarize a series into buckets of time, with values aggregated within each bucket.

Types

counts()

@type counts() :: %{optional(String.t()) => number()}

filter_value()

@type filter_value() :: label() | atom() | [label() | atom()]

label()

@type label() :: String.t()

labels_opts()

@type labels_opts() :: [lookback: pos_integer(), since: pos_integer()]

latest_opts()

@type latest_opts() :: [
  filters: keyword(filter_value()),
  group: nil | label() | atom(),
  lookback: pos_integer()
]

operation()

@type operation() :: :max | :sum | {:pct, float()}

series()

@type series() :: atom() | String.t()

series_detail()

@type series_detail() :: %{series: String.t(), labels: [label()], type: module()}

sub_counts()

@type sub_counts() :: %{optional(String.t()) => non_neg_integer() | counts()}

timeslice_opts()

@type timeslice_opts() :: [
  by: pos_integer(),
  filters: keyword(filter_value()),
  group: nil | label() | atom(),
  lookback: pos_integer(),
  operation: operation(),
  since: pos_integer()
]

ts()

@type ts() :: integer()

value()

@type value() :: Oban.Met.Value.t()

Functions

checks(oban \\ Oban)

@spec checks(Oban.name()) :: [map()]

Retrieve stored producer checks.

Checks are gathered from every local queue producer about once a second and broadcast to all connected nodes, so each node holds a replica of checks from the entire cluster. Checks that haven't been refreshed in 30 seconds are purged.

Output

Checks are the result of Oban.check_queue/1 after a round trip through JSON, so keys and timestamps are strings. The limit key is renamed to local_limit, and the exact contents depend on which Oban.Engine is in use. A Basic engine check looks similar to this:

%{
  "local_limit" => 10,
  "name" => "Oban",
  "node" => "worker.1",
  "paused" => false,
  "queue" => "default",
  "refresh_interval" => 60000,
  "running" => [100, 102],
  "shutdown_started_at" => nil,
  "started_at" => "2026-10-20T10:32:12.035202Z",
  "updated_at" => "2026-10-20T10:32:12.035204Z",
  "uuid" => "4e776a25-042e-432b-96fa-3a08f245e749"
}

Examples

Get all current checks:

Oban.Met.checks()

Get current checks for a non-standard Oban instance:

Oban.Met.checks(MyOban)

crontab(oban \\ Oban)

@spec crontab(Oban.name()) :: [{binary(), binary(), map()}]

Get a normalized, unified crontab from all connected nodes.

Each entry is a tuple of the cron expression, the worker name, and a map of the entry's options. Crontabs are shared between nodes as JSON, so option keys are strings. Duplicate entries across nodes are removed, and crontabs from nodes that haven't reported in 60 seconds are dropped.

Examples

Get a merged crontab:

Oban.Met.crontab()
[
  {"* * * * *", "MyApp.WorkerA", %{}},
  {"0 * * * *", "MyApp.WorkerB", %{"args" => %{"mode" => "foo"}}}
]

Get the crontab for a non-standard Oban instance:

Oban.Met.crontab(MyOban)

labels(oban \\ Oban, label, opts \\ [])

@spec labels(Oban.name(), label(), labels_opts()) :: [label()]

Get the unique values recently recorded for a label across all series.

Options

  • :lookback - how many seconds before :since to include, defaults to 120

  • :since - the unix time, in seconds, that the lookback is measured from, defaults to now

Examples

Get all known queues:

Oban.Met.labels("queue")
["alpha", "delta", "gamma"]

Get workers recorded within the last minute:

Oban.Met.labels("worker", lookback: 60)
["MyApp.OtherWorker", "MyApp.Worker"]

Get queues for a non-standard Oban instance:

Oban.Met.labels(MyOban, "queue")

latest(oban \\ Oban, series, opts \\ [])

@spec latest(Oban.name(), series(), latest_opts()) :: counts()

Get the latest values for a series, summed and optionally grouped by a label.

Each distinct combination of labels contributes its most recent value from within the lookback. Without a :group, all values are summed under the "all" key. Values that lack the group label are also summed under "all". Groups without any recent values are omitted.

Series

Latest values are intended for gauge series (as reported by series/1):

  • :full_count - jobs in the database, with node, queue, and state labels.

  • :exec_count - jobs that finished executing, with node, queue, state, and worker labels. The state is the job's state after execution, e.g. completed or retryable.

Sketch series such as :exec_time return approximate sums, which are rarely useful. Use timeslice/3 with a percentile for those instead.

Options

  • :filters - a keyword list of labels and values that recorded labels must match. A value may be a string, an atom, or a list of either to match any of them. Separate labels must all match. Defaults to [].

  • :group - a label to group values by, defaults to nil

  • :lookback - how many seconds back to include values, defaults to 2

Examples

Get the :full_count value without any grouping:

Oban.Met.latest(:full_count)
%{"all" => 99}

Group the :full_count value by state:

Oban.Met.latest(:full_count, group: "state")
%{"available" => 9, "completed" => 80, "executing" => 5, ...}

Group recent executions by queue:

Oban.Met.latest(:exec_count, group: "queue")
%{"alpha" => 9, "gamma" => 3}

Filter values by node:

Oban.Met.latest(:exec_count, filters: [node: "worker.1"])
%{"all" => 6}

Filter values by queue and any of several states:

Oban.Met.latest(:full_count, filters: [queue: "alpha", state: ["available", "scheduled"]])
%{"all" => 12}

Get values for a non-standard Oban instance:

Oban.Met.latest(MyOban, :full_count, group: "queue")

lookup(oban \\ Oban, series)

@spec lookup(Oban.name(), series()) :: [term()]

Get all stored rows for a series without any filtering or aggregation.

Rows are returned newest first in their internal storage format, which is primarily useful for debugging.

series(oban \\ Oban)

@spec series(Oban.name()) :: [series_detail()]

List all recorded series along with their labels and value type.

Examples

Oban.Met.series()
[
  %{series: "exec_count", labels: ["node", "queue", "state", "worker"], type: Gauge},
  %{series: "exec_time", labels: ["node", "queue", "state", "worker"], type: Sketch},
  %{series: "full_count", labels: ["node", "queue", "state"], type: Gauge},
  %{series: "wait_time", labels: ["node", "queue", "state", "worker"], type: Sketch}
]

start_link(opts)

@spec start_link(Keyword.t()) :: Supervisor.on_start()

Start a Met supervisor for an Oban instance.

Oban.Met typically starts supervisors automatically when Oban instances initialize. However, starting a supervisor manually can be used if auto_start is disabled.

The supervisor is registered under the Oban instance's name, so only one may run per instance.

Options

  • :conf - configuration for a running Oban instance, required

Example

Start a supervisor for the default Oban instance:

Oban.Met.start_link(conf: Oban.config())

timeslice(oban \\ Oban, series, opts \\ [])

@spec timeslice(Oban.name(), series(), timeslice_opts()) :: [
  {ts(), nil | number(), nil | label()}
]

Summarize a series into buckets of time, with values aggregated within each bucket.

Returns a list of {bucket, value, label} tuples, sorted by label and then from the oldest bucket to the newest. Buckets without any values are omitted.

Buckets

The bucket is an index counting backward from :since, not a timestamp. Bucket 0 holds the :by seconds immediately before :since, bucket 1 the :by seconds before that, and so on through the lookback. Bucket n covers from since - (n + 1) * by up to, but not including, since - n * by. Values recorded at or after :since fall into negative buckets.

Aggregation

Values in each bucket are combined by label, according to :group, and then reduced with the :operation:

  • :sum - the total of all values. Exact for gauges and approximate for sketches.

  • :max - the largest value. For gauges, that's the peak per-second total for the group.

  • {:pct, ntile} - the percentile, with ntile between 0.0 and 1.0. Empty sketches return nil.

Sketches, such as :exec_time and :wait_time, estimate values with a 2% relative error and store times in :native units unless the :sketch_time_unit is configured. The :exec_count gauge counts executions per second, so :sum gives the executions within each bucket. The :full_count gauge is a reading that repeats with each report, so use :max or a percentile rather than summing it.

Compaction

Older values are compacted into wider intervals to save space. By default, values keep one-second resolution for 2 minutes, then compact into 5 second intervals for 15 minutes, 30 second intervals for the next 33 minutes, and 60 second intervals for about 2.5 more hours, after which they're deleted. Compacted values land in a single bucket, so buckets narrower than the compaction interval are sparse for older data.

Options

  • :by - the width of each bucket in seconds, defaults to 1

  • :filters - a keyword list of labels and values that recorded labels must match, as in latest/3. Defaults to [].

  • :group - a label to group values by. Values without the label, or all values when nil, are combined under a nil label. Defaults to nil.

  • :lookback - how many seconds before :since to include, defaults to 60

  • :operation - how to reduce values within each bucket, one of :sum, :max, or {:pct, ntile}. Defaults to :sum.

  • :since - the unix time, in seconds, that buckets count back from, defaults to now

Examples

Retrieve the 95th percentile exec_time for each of the last three seconds:

Oban.Met.timeslice(:exec_time, lookback: 3, operation: {:pct, 0.95})
[
  {2, 16771374649.128689, nil},
  {1, 24040058779.3428, nil},
  {0, 22191534459.516357, nil}
]

Count executions in 5 second buckets over the last minute, grouped by queue:

Oban.Met.timeslice(:exec_count, by: 5, group: "queue")
[
  {11, 4, "analysis"},
  {10, 7, "analysis"},
  ...
  {1, 12, "events"},
  {0, 9, "events"}
]

Find the longest wait_time in a single queue:

Oban.Met.timeslice(:wait_time, filters: [queue: "default"], operation: :max)

Slice from a fixed point in time for a non-standard Oban instance:

Oban.Met.timeslice(MyOban, :exec_count, by: 10, lookback: 300, since: since)