Prometheus Plugs Hex.pm

Elixir plugs for prometheus.erl

TL;DRExample app

Plugs

Prometheus Plugs currently comes with two Plugs. One is for collecting http metrics while another provides endpoint for scraping by Prometheus daemon.

Plug.PrometheusCollector

Currently maintains two metrics.

All metrics support configurable labels:

Plug.PrometheusCollector.setup(labels: [:method, :host])
plug Plug.PrometheusCollector, [:method, :host]

Supported labels include:

In fact almost any Plug.Conn field value can be used as metric label. Just throw PR if something is needed.

Additionaly http_request_duration_microseconds supports configurable bucket bounds:

Plug.PrometheusCollector.setup([labels: [:method, :host],
                                 request_duration_bounds: [10, 100, 1_000, 10_000, 100_000, 300_000, 500_000, 750_000, 1_000_000, 1_500_000, 2_000_000, 3_000_000]])

plug Plug.PrometheusCollector, [:method, :host]

Bear in mind that bounds are microseconds (1s is 1_000_000us)

Plug.PrometheusExporter

Exports metrics in text format via configurable endpoint:

plug Plug.PrometheusExporter, [path: "/prom/metrics"]  # default is /metrics

Installation

The package can be installed as:

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

    def deps do

     [{:prometheus_plugs, "~> 0.3.0"}]

    end

  2. Ensure prometheus is started before your application:

    def application do

     [applications: [:prometheus]]

    end

License

MIT