Fl4m3Ph03n1x
Prometheus.InvalidMetricArityError with PrometheusEx
Background
I have a basic app with that need to keep count of errors. To do that, I am using prometheus.ex.
Problem
The problem is that even though I am declaring the counters as expected, I can’t even get a basic app running:
defmodule MyApp.Metrics.Prometheus do
use Prometheus.Metric
alias Prometheus.Metric.Counter
def setup(_args) do
Counter.declare(
name: :dead_worker,
help: "Error description.",
labels: [:my_app]
)
:ok
end
def inc(key), do: Counter.inc([name: key], 1)
def add(key, quantity), do: Counter.inc([name: key], quantity)
def get(key), do: Counter.value(name: key)
end
When I launch this in IEX, this is what I do:
iex(1)> MyApp.Metrics.Prometheus.setup(nil)
:ok
iex(2)> MyApp.Metrics.Prometheus.get(:dead_worker)
** (Prometheus.InvalidMetricArityError) Invalid metric arity: got 0, expected 1.
(prometheus) src/prometheus_metric.erl:149: :prometheus_metric.check_mf_exists/4
(prometheus) src/metrics/prometheus_counter.erl:277: :prometheus_counter.value/3
(prometheus_ex) lib/prometheus/metric/counter.ex:214: Prometheus.Metric.Counter.value/1
iex(2)>
What am I doing wrong? Why are the values mismatched ?
Marked As Solved
Phillipp
You have to pass the labels too.
From my code:
def report_http_error(tracker, http_call) do
Prometheus.Metric.Counter.inc([name: :http_errors_total, labels: [tracker, http_call], registry: :all])
end
The registry: :all is not needed, I just used a different “bucket” for my metrics because I don’t need the system metrics that are collected automatically.
1
Popular in Questions
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
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
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
Hi all,
Trying to get some more clarity over utc_datetime and naive_datetime for Ecto:
The documentation above suggests that while ...
New
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
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
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
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
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
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
If I have a post route which an argument:
post /my_post_route/:my_param1, MyController.my_post_handler
How would get the post params ...
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
Hi All,
I set a environment variables in dev.exs , like below code.
when i start server, how can i set the ${enable} value?
thanks.
d...
New
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
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
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
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
I would like to know what is the best IDE for elixir development?
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
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









