Skip to content

prometheus-erl/prometheus.ex

Folders and files

NameName
Last commit message
Last commit date
Feb 19, 2021
Sep 1, 2018
Aug 21, 2016
Jul 20, 2020
Aug 2, 2022
Sep 27, 2016
Feb 19, 2021
Sep 4, 2017
Oct 22, 2016
Feb 27, 2018
Sep 4, 2017
Feb 19, 2021
Sep 3, 2016
Dec 29, 2020
Jan 24, 2019

Repository files navigation

Prometheus.ex

Build Status Hex.pm Coverage Status Hex.pm Documentation

Elixir Prometheus.io client based on Prometheus.erl.

Starting from v3.0.0 works with Elixir >=1.6 and Erlang >=20. For older versions, please use older tags.

@skosch dashboard

Dashboard from Monitoring Elixir apps in 2016: Prometheus and Grafana by @skosch.

  • IRC: #elixir-lang on Freenode;
  • Slack: #prometheus channel - Browser or App(slack://elixir-lang.slack.com/messages/prometheus).

Example

defmodule ExampleInstrumenter do
  use Prometheus.Metric

  def setup do    
    Histogram.new([name: :http_request_duration_milliseconds,
                   labels: [:method],
                   buckets: [100, 300, 500, 750, 1000],
                   help: "Http Request execution time"])
  end

  def instrument(%{time: time, method: method}) do
    Histogram.observe([name: :http_request_duration_milliseconds, labels: [method]], time)
  end
end

or

defmodule ExampleInstrumenter do
  use Prometheus.Metric

  @histogram [name: :http_request_duration_milliseconds,
              labels: [:method],
              buckets: [100, 300, 500, 750, 1000],
              help: "Http Request execution time"]

  def instrument(%{time: time, method: method}) do
    Histogram.observe([name: :http_request_duration_milliseconds, labels: [method]], time)
  end
end

Here histogram will be declared in auto-generated @on_load callback, i.e. you don't have to call setup manually.

Please read how to measure durations correctly with prometheus.ex.

Integrations / Collectors / Instrumenters

Dashboards

Installation

Available in Hex, the package can be installed as:

  1. Add prometheus_ex to your list of dependencies in mix.exs:

    def deps do
      [{:prometheus_ex, "~> 3.0"}]
    end
  2. Ensure prometheus_ex is started before your application:

    def application do
      [applications: [:prometheus_ex]]
    end