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
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
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
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
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?
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex










