prometheus_plugs v0.5.1 Plug.PrometheusCollector

Plug for collecting http metrics.

To use it, plug it into the desired module. You also want to call setup/0,1 before using plug, for example on application start!

plug Plug.PrometheusCollector

Currently maintains two metrics.

  • http_requests_total - Total nubmer of HTTP requests made. This one is a counter.
  • http_request_duration_microseconds - The HTTP request latencies in microseconds. This one is a histogram.

All metrics support configurable labels:

# on app startup (e.g. supervisor setup)
Plug.PrometheusCollector.setup([:method, :host])

# in your plugs pipeline
plug Plug.PrometheusCollector, [:method, :host]

Supported labels include:

  • code - http code
  • method - http method
  • host - requested host
  • port - requested port
  • scheme - request scheme (like http or https)

In fact almost any Plug.Conn field value can be used as metric label. Just throw PR if something is needed.

Additionaly http_request_duration_microseconds supports configurable bucket bounds:

Plug.PrometheusCollector.setup([labels: [:method, :host],
                               request_duration_bounds: [10, 100, 1_000, 10_000, 100_000, 300_000, 500_000, 750_000, 1_000_000, 1_500_000, 2_000_000, 3_000_000]])

plug Plug.PrometheusCollector, [:method, :host]

Bear in mind that bounds are microseconds (1s is 1_000_000us)

Summary

Functions

Callback implementation for c:Plug.call/2

Callback implementation for c:Plug.init/1

Functions

call(conn, labels)

Callback implementation for c:Plug.call/2.

init(labels)

Callback implementation for c:Plug.init/1.

setup(opts \\ [])