diff --git a/lib/prom_ex/plugins/oban.ex b/lib/prom_ex/plugins/oban.ex index 78a64ed..b5682a8 100644 --- a/lib/prom_ex/plugins/oban.ex +++ b/lib/prom_ex/plugins/oban.ex @@ -438,7 +438,8 @@ if Code.ensure_loaded?(Oban) do config |> Oban.Repo.all(query) - |> Enum.each(fn {queue, state, count} -> + |> include_zeros_for_missing_queue_states() + |> Enum.each(fn {{queue, state}, count} -> measurements = %{count: count} metadata = %{name: normalize_module_name(oban_supervisor), queue: queue, state: state} @@ -446,6 +447,16 @@ if Code.ensure_loaded?(Oban) do end) end + defp include_zeros_for_missing_queue_states(query_result) do + all_queues = Keyword.keys(Oban.config().queues) + all_states = Oban.Job.states() + + zeros = for queue <- all_queues, state <- all_states, into: %{}, do: {{to_string(queue), to_string(state)}, 0} + counts = for {queue, state, count} <- query_result, into: %{}, do: {{queue, state}, count} + + Map.merge(zeros, counts) + end + defp get_oban_supervisors(opts) do opts |> Keyword.get(:oban_supervisors, [Oban])