RiverFinancial / prometheus-plugs

Prometheus.erl Elixir Plugs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Prometheus.io Plugs Instrumenter/Exporter

Hex.pm Hex.pm Build Status Documentation

Elixir Plug integration for prometheus.ex

Quick introduction by @skosch: Monitoring Elixir apps in 2016: Prometheus/Grafana Step-by-Step Guide

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

Instrumentation

To instrument whole plug pipeline use Prometheus.PlugPipelineInstrumenter:

defmodule MyApp.Endpoint.PipelineInstrumenter do
  use Prometheus.PlugPipelineInstrumenter
end

To instrument just a single plug use Prometheus.PlugInstrumenter:

defmodule MyApp.CoolPlugInstrumenter do
  use Prometheus.PlugInstrumenter, [plug: Guardian.Plug.EnsureAuthenticated,
                                    counter: :guardian_ensure_authenticated_total,
                                    histogram: :guardian_ensure_authenticated_duration_microseconds,
                                    labels: [:authenticated]]
end

Both modules implement plug interface and Prometheus.PlugInstrumenter generates proxy for specified plug so you'll need to replace instrumented plug with your instrumenter in pipeline.

Instrumenters configured via :prometheus app environment. Please consult respective modules documentation on what options are available.

Exporting

To export metric we first have to create a plug that will serve scraping requests.

defmodule MyApp.MetricsExporter do
  use Prometheus.PlugExporter
end

Then we add exporter to MyApp pipeline:

plug MyApp.MetricsExporter

You can configure path, export format and Prometheus registry via :prometheus app environment. For more information please see Prometheus.PlugExporter module documentation.

Export endpoint can be secured using HTTP Basic Authentication:

  auth: {:basic, "username", "password"}

Integrations / Collectors / Instrumenters

Installation

The package can be installed as:

  1. Add prometheus_plug to your list of dependencies in mix.exs:
        def deps do
          [{:prometheus_plugs, "~> 1.1.1"}]
        end
  1. Ensure prometheus is started before your application:
        def application do
          [applications: [:prometheus_plugs]]
        end

License

MIT

About

Prometheus.erl Elixir Plugs


Languages

Language:Elixir 94.8%Language:Shell 5.2%