extatus v0.2.5 Extatus.Metric View Source

This module defines several macros to be able to generate metrics for Prometheus i.e:

defmodule TestMetrics do
  use Extatus.Metric

  defmetrics do
    counter :counter_test do
      label :id
      label :something
      registry :default
      help "Counter test"
    end
  end
end

After that one can use the function TestMetrics.setup/0 to declare the metrics at runtime and the TestMetrics.gen_spec/2 to generate the specs of an actual obsevation i.e:

iex> require Extatus.Metric.Counter
Extatus.Metric.Counter
iex> TestMetrics.setup()
:ok
iex> Extatus.Metric.Counter.inc(:counter_test, something: "Test", id: 1)
:ok

The module Extatus.Process uses this module.

To change the default registry, just change the configuration i.e:

config :extatus,
  prometheus_registry: :default

Link to this section Summary

Functions

Adds the functions setup/0 and gen_spec/2 for metric declaration

Receives the name of the counter metric and the definition block. Accepts the label/1, registry/1 and the help/1 declarations i.e

Macro to define metrics in the current module i.e

Receives the name of the gauge metric and the definition block. Accepts the label/1, registry/1 and the help/1 declarations

Receives the name of the histogram metric and the definition block. Accepts the label/1, registry/1, buckets/1 and the help/1 declarations

Receives the name of the summary metric and the definition block. Accepts the label/1, registry/1 and the help/1 declarations

Link to this section Functions

Adds the functions setup/0 and gen_spec/2 for metric declaration.

Link to this macro counter(name, list) View Source (macro)

Receives the name of the counter metric and the definition block. Accepts the label/1, registry/1 and the help/1 declarations i.e.

defmetrics do
  counter :counter_test do
    label :label
    registry :default
    help "Counter test"
  end
end
Link to this macro defmetrics(list) View Source (macro)

Macro to define metrics in the current module i.e:

defmetrics do
  counter :counter_test do
    label :label
    registry :default
    help "Counter test"
  end
end

Every metric in a module should be declared inside this macro.

Link to this macro gauge(name, list) View Source (macro)

Receives the name of the gauge metric and the definition block. Accepts the label/1, registry/1 and the help/1 declarations.

defmetrics do
  gauge :gauge_test do
    label :label
    registry :default
    help "Gauge test"
  end
end
Link to this macro histogram(name, list) View Source (macro)

Receives the name of the histogram metric and the definition block. Accepts the label/1, registry/1, buckets/1 and the help/1 declarations.

defmetrics do
  counter :histogram_test do
    label :label
    registry :default
    help "Histogram test"
    buckets {:linear, 0, 1_000_000, 100_000}
  end
end

See Prometheus.Metric.Histogram for buckets definitions.

Link to this macro summary(name, list) View Source (macro)

Receives the name of the summary metric and the definition block. Accepts the label/1, registry/1 and the help/1 declarations.

defmetrics do
  summary :summary_test do
    label :label
    registry :default
    help "Summary test"
  end
end