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
can someone please explain to me how Enum.reduce works with maps
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
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
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
As a follow up to my earlier question:
I have the code compiling and running but not getting a successful login from the rest server. ...
New
Hey guys.
I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
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
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project.
Baby step #1 is extracting the number ...
New
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
Sometimes I want to check if the input into a function is not a blank string.
My first approach:
defmodule Example do
def do_stuff(s...
New
Other popular topics
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
I have followed this StackOverflow post to install the specific version of Erlang.
And When I am running mix ecto.setup then getting fol...
New
Hi folks,
Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
New
What is most correct way to open, read and parse JSON file with poison?
For example if we have example.json file in root of some projec...
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
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
New








