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 ?

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 Like