Fl4m3Ph03n1x

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

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.

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

Darmani72
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
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
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
sen
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
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
vonH
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
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
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
JorisKok
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

We're in Beta

About us Mission Statement