Prometheus.InvalidMetricArityError with PrometheusEx


I have a basic app with that need to keep count of errors. To do that, I am using prometheus.ex.


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

      name: :dead_worker,
      help: "Error description.",
      labels: [:my_app]


  def inc(key), do:[name: key], 1)

  def add(key, quantity), do:[name: key], quantity)

  def get(key), do: Counter.value(name: key)

When I launch this in IEX, this is what I do:

iex(1)> MyApp.Metrics.Prometheus.setup(nil)
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

What am I doing wrong? Why are the values mismatched ?

You have to pass the labels too.

From my code:

  def report_http_error(tracker, http_call) do[name: :http_errors_total, labels: [tracker, http_call], registry: :all])

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 Like