prometheus_phoenix v1.1.0 Prometheus.PhoenixInstrumenter View Source

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 controllercall and controller_render events are instrumented and exposed via `phoenix_controller_call_durationandphoenixcontroller_render_duration` histograms. Channel metrics are coming soon.

Default phoenix_controller_call labels:

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

Default phoenix_controller_render labels:

  • view - name of the view;
  • template - name of the template;
  • format - name of the format of the template.

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