Creating custom Prometheus metrics

To implement a custom metric, we will follow the same steps as we did previously: we will first configure our custom metric and then we will create a new Chronometer.defmeasured/2 macro that not only defines a new function, but also emits a histogram metric based on the function name and module.

This time, however, the module that exposes the setup/0 function will be more complex, since it needs to register the metrics and also expose the count/1, observe/2, and observe_duration/2 functions:

$ cat apps/elixir_drip/lib/elixir_drip/prometheus/instrumenter.exdefmodule ElixirDrip.Instrumenter do  use Prometheus  @histograms %{"storage_store" => "Time histogram for the Storage.store/  4 function"} @counters %{"cache_worker_hit" ...

Get Mastering Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.