fedme

fedme

Sharing some ideas for a PromEx plugin that could be useful to Oban Pro users

Hi!

Just wanted to share some code that might be useful to Oban Pro users, it’s a simple PromEx custom plugin that exposes Oban.Met metrics to Prometheus.

PromEx already includes an Oban plugin but that one queries the database instead of requesting metrics from Oban.Met (which I believe it’s a Pro feature).

To reduce DB load I have experimented with some code to request metrics from Oban.Met rather than computing them again from the DB.

@sorenone @sorentwo any plans to release an official Oban Pro PromEx plugin? :smile:

defmodule ObanMetPromExPlugin do
  @moduledoc """
  Simple PromEx plugin that exposes `Oban.Met` stats to Prometheus.

  Right now it exposes a single metric called `oban_met_job_count` that
  counts jobs labelled with their queue and state.
  """

  use PromEx.Plugin

  @default_poll_rate 5_000
  @count_event_name [:oban, :met, :job, :count]

  @impl true
  def polling_metrics(opts) do
    poll_rate = Keyword.get(opts, :poll_rate, @default_poll_rate)

    Polling.build(
      :oban_met_job_count_metrics,
      poll_rate,
      {__MODULE__, :execute_queue_metrics, []},
      [
        last_value(
          [:oban, :met, :job, :count],
          event_name: @count_event_name,
          measurement: :count,
          description: "Oban.Met job count",
          tags: [:queue, :state]
        )
      ]
    )
  end

  def execute_queue_metrics() do
    queues =
      Oban.Met.checks(Oban)
      |> Enum.map(& &1["queue"])
      |> Enum.uniq()

    states = Enum.map(Oban.Job.states(), &Atom.to_string/1)

    for queue <- queues do
      states_counts =
        states
        |> Enum.into(%{}, fn state -> {state, 0} end)
        |> Map.merge(Oban.Met.latest(Oban, :full_count, group: "state", filters: [queue: queue]))

      for {state, count} <- states_counts do
        :telemetry.execute(@count_event_name, %{count: count}, %{queue: queue, state: state})
      end
    end
  end
end

First Post!

sorentwo

sorentwo

Oban Core Team

Thanks for sharing this, I hope some other people can make use of it as well.

The Oban.Met package is available with either Web or Pro.

There are some notes about it, but our backlog is deep :sunglasses:

Where Next?

Popular in Questions Top

chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&amp;query=perfume&amp;page=2, I would like to get: ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: &lt;h1&gt;Create Post&lt;/h1&gt; &lt;%= ...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement