prometheus_phoenix v1.0.0-rc1 Prometheus.PhoenixInstrumenter

Phoenix instrumenter generator for Prometheus. Implemented as Phoenix instrumenter.

Usage

  1. Define your instrumenter:
defmodule MyApp.Endpoint.Instrumenter do
  use Prometheus.PhoenixInstrumenter
end
  1. Call MyApp.Endpoint.Instrumenter.setup/0 when application starts (e.g. supervisor setup):
MyApp.Endpoint.Instrumenter.setup()
  1. Add MyApp.Endpoint.Instrumenter to Phoenix endpoint instrumenters list:
config :myapp, MyApp.Endpoint,
  ...
  instrumenters: [MyApp.Endpoint.Instrumenter]
  ...

Metrics

Currently only one controllercall event is instrumented and exposed via `phoenix_controller_call_duration` histogram. Render_view is coming soon (awaits phoenix release).

Default labels:

  • controller - controller module name;
  • action - action name;
  • method - http method;
  • host - requested host;
  • port - requested port;
  • scheme - request scheme (like http or https).

Configuration

Instrumenter configured via :prometheus application environment MyApp.Endpoint.Instrumenter key (i.e. app env key is the name of the instrumenter).

Default configuration:

config :prometheus, MyApp.Endpoint.Instrumenter,
  controller_call_labels: [:controller, :action],
  duration_buckets: :prometheus_http.microseconds_duration_buckets(),
  registry: :default,
  duration_unit: :microseconds

Available duration units:

  • microseconds;
  • milliseconds;
  • seconds;
  • minutes;
  • hours;
  • days.

Bear in mind that buckets are so if you are not using default unit you also have to override buckets.

Custom Labels

Custom labels can be defined by implementing label_value/2 function in instrumenter directly or by calling exported function from other module.

  controller_call_labels: [:controller,
                           :my_private_label,
                           {:label_from_other_module, Module}, # eqv to {Module, label_value}
                           {:non_default_label_value, {Module, custom_fun}}]


defmodule MyApp.Endpoint.Instrumenter do
  use Prometheus.PhoenixInstrumenter

  label_value(:my_private_label, conn) do
    ...
  end
end