Monitoring Erlang Applications with Prometheus
Professional
You can instrument your Erlang application with deadtrickster/prometheus.erl and let the Glouton agent scrape its /metrics endpoint.
Install the client library
Section titled “Install the client library”Add the dependencies to your rebar.config:
{deps, [ {prometheus, "4.11.0"}, {prometheus_httpd, "2.1.12"}]}.Minimal example
Section titled “Minimal example”The snippet below defines a counter and exposes it on http://localhost:8081/metrics using the bundled HTTP exporter:
-module(myapp).-export([start/0]).
start() -> {ok, _} = application:ensure_all_started(prometheus), {ok, _} = application:ensure_all_started(prometheus_httpd),
prometheus_counter:declare([ {name, myapp_requests_total}, {help, "Total number of processed requests."} ]), prometheus_counter:inc(myapp_requests_total),
prometheus_httpd:start([{port, 8081}]).Scrape with Glouton
Section titled “Scrape with Glouton”Configure Glouton to scrape your application by adding the following to /etc/glouton/conf.d/50-prometheus-metrics.conf:
metric: prometheus: targets: - url: "http://localhost:8081/metrics" name: "my_erlang_application" allow_metrics: - "myapp_requests_total"Restart the agent to apply the configuration. See Prometheus Monitoring for the full list of options, including Docker label auto-discovery and Kubernetes annotations.