favetelinguis

favetelinguis

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???

Showing Posts 1 to 10

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?

Phillipp

Phillipp

I am using the prometheus package without a phoenix installation.

The package lets you define, set, update and delete metrics.

It’s useful to look at the docs for the specific metrics types to see how you can use them. E.g. prometheus.ex/lib/prometheus/metric/gauge.ex at master · prometheus-erl/prometheus.ex · GitHub

favetelinguis

favetelinguis OP

Not sure we have the same view of Prometheus, you dont send data. Prometheus is polling the metrics endpoint wich contains data from instrumented parts of your app.

Tuxified

Tuxified

Maybe I don’t understand correctly how Prometheus works, but I got from this overview you can send your metrics to a push gateway from which prometheus will pull info? If so, that might make it easier to use? Otherwise you’d have to gather the metrics yourself, store/remember them before prometheus pull that info from your metrics endpoint?

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

I came across a project that might function as an example: GitHub - oestrich/ex_venture: Text based MMORPG engine written in Elixir · GitHubExventure - . Hope that helps :slight_smile:

favetelinguis

favetelinguis OP

Ok interesting, my understanding was that prometheus.ex is only used for instrumenting your code, it does not provide an exporter, that is the metrics endpoint will not be provided by it. For that you have to use som other package that provides the endpoint?

Do you have any github projects where you have this setup?

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)

favetelinguis

favetelinguis OP

So lets say in my lib folder I have 5 projects that all depend on each other, would I need to provide 5 /metrics endpoints on 5 web servers on 5 different ports or could I use one metrics endpoints for all 5 projects? This is sort of my original question.

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.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews