favetelinguis

favetelinguis

Instrumenting my business logic with Prometheus

I have what I thinks is a standar layout of a Phoenix project, in my lib folder I have two projects app_core and app_interface. In app_interface I have the dependency to phoenix and following this post I also have the dependency to

{:prometheus_ex, "~> 1.0"},
{:prometheus_plugs, "~> 1.0"}

Given this setup my Phoenix project will expose an metrics endpoint.

Now the problem I have is that I want to instrument the app_core project and have those metrics made available on the metrics endpoint in the app_interface project.

Is this even possible or how are you guys using metrics with the business logic side of a Phoneix project???

Marked As Solved

Phillipp

Phillipp

Do you mean 5 apps in an umbrella setup?

If you don’t have an umbrella setup and just one elixir app, there is nothing special to do.

If you have an umbrella setup with different apps, I would suggest that you create another app just for the metrics. That metrics app has the dependency to prometheus_ex and exposes functions for your other apps to add and update their metrics. That way, your other apps can have the metrics app as dependency and push their metrics to it. That metrics app also exposes Prometheus.Format.Text.format which is important for your web facing app to get the metrics for the endpoint. The point is that you have a central place for the metrics so you don’t end up having one metrics list per app which is not very practical in most cases.

Also Liked

Phillipp

Phillipp

The package provides everything you need.

So, given you use it in your code to declare and update metrics like this:

Prometheus.Metric.Boolean.declare([name: :my_metric, help: "My Metric", labels: [:label1, :label2], registry: :all])
Prometheus.Metric.Boolean.set([name: :my_metric, labels: ["foo", "bar"], registry: :all], true)

(I use registry: :all here because I don’t need the system metrics that are added by default by prometheus_ex)

You just need plug, or anything else that serves your metrics endpoint. The prometheus package gives you the metrics in the correct form. My code is simply this in a normal plug router.

  get "/metrics" do
    metrics = Prometheus.Format.Text.format(:all)
    send_resp(conn, 200, metrics)
  end

(Here I pass it the :all argument because I pushed my metrics to the :all registry)

Phillipp

Phillipp

That is only meant for things like queue workers where you want to send metrics of individual jobs.

That is what the prometheus_ex lib does.

Tuxified

Tuxified

Prometheus is an external tool, so you send events/metrics to prometheus. You can send metrics from different apps/projects, your metrics endpoint could retrieve data from prometheus to show it to a user? I think prometheus already has a UI/works with grafana so it might be better to just use those?

Where Next?

Popular in Questions Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
mgjohns61585
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
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
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
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
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
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
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New

We're in Beta

About us Mission Statement