View Source PromEx behaviour (PromEx v1.7.1)

PromEx is a plugin based library which can be used to capture telemetry events and report them out for consumption by Prometheus. The main purpose of this particular library is to provide the behaviour that all PromEx plugins leverage so that a consistent interface can be achieved and so that leveraging multiple plugins is effortless from the user's point of view.

To use PromEx you need to define a module that uses the PromEx library. This module will also need to have some application config set for it similarly to how Ecto does. For example, for a PromEx module defined like so:

defmodule MyApp.PromEx do
  use PromEx,  otp_app: :web_app

  ...
end

You would have an application configuration set like so:

config :my_app, MyApp.PromEx,
  manual_metrics_start_delay: :no_delay,
  drop_metrics_groups: [],
  grafana: [
    host: System.get_env("GRAFANA_HOST", "http://grafana:3000"),
    auth_token: System.get_env("GRAFANA_TOKEN", ""),
    upload_dashboards_on_start: true,
    folder_name: "My App Dashboards",
    annotate_app_lifecycle: true
  ]

The options that you can pass to PromEx macro are outlined in the following section. In order to tell PromEx what plugins you would like to use and what dashboards you would like PromEx to upload for you, implement the plugins/0 and dashboards/0 callbacks respectively. The dashboard_assigns/0 callback will be used when your EEx template Grafana dashboards are rendered so that the dashboards that are created for your application coincide with the PromEx configuration for the application. If your dashboards are not EEx templates, then the dashboard assigns are not passed through. Each plugin also has an accompanying Grafana dashboard that you can leverage to plot all of the plugin captured data.

In order to expose captured metrics, you can leverage the PromEx provided Plug PromEx.Plug. See the PromEx.Plug documentation modules for specifics on how to use it.

options

Options

  • :otp_app - This is a REQUIRED field and is used by PromEx to fetch the application configuration values for the various PromEx capture modules. Make sure that this value matches the :app value in project/0 from your mix.exs file. If you use the PromEx mix prom_ex.create mix task this will be done automatically for you.

promex-plugins

PromEx Plugins

All metrics collection will be delegated to plugins which can be found here:

Foundational metrics:

Library metrics:

Backlog Elixir library metrics:

Database cron based metrics:

Link to this section Summary

Functions

A simple pass-through to fetch all of the currently configured metrics. This is primarily used by the exporter plug to fetch all of the metrics so that they can be scraped.

Link to this section Types

Link to this type

dashboard_definition()

View Source

Specs

dashboard_definition() ::
  {atom(), String.t()} | {atom(), String.t(), keyword(String.t())}

Specs

measurements_mfa() :: {module(), atom(), list()}

Specs

plugin_definition() :: module() | {module(), keyword()}

Specs

Link to this section Callbacks

Specs

dashboard_assigns() :: keyword()

Specs

dashboards() :: [dashboard_definition()]

Specs

init_opts() :: PromEx.Config.t()

Specs

plugins() :: [plugin_definition()]

Link to this section Functions

Link to this function

get_metrics(prom_ex_module)

View Source

Specs

get_metrics(prom_ex_module :: module()) :: String.t() | :prom_ex_down

A simple pass-through to fetch all of the currently configured metrics. This is primarily used by the exporter plug to fetch all of the metrics so that they can be scraped.