logi_prometheus

Prometheus metrics collector for logi


Keywords
erlang, logger, prometheus
License
MIT

Documentation

logi_prometheus

hex.pm version Build Status Code Coverage License: MIT

Prometheus metrics collector for logi.

Documentation

logi_prometheus provides counters that count the number of log messages as follows:

logi_messages_total{logger="logger_name",severity="info",application="app_name",module="mod_name"} 1

It is useful for detecting anomalies of your application by using alerting rules.

Examples

Basic usage.

%% Installs `metrics_sink` to the default channel
> Sink = logi_prometheus_sink:new(metrics_sink, [{registry, example_registry}]).
> {ok, _} = logi_channel:install_sink(Sink, info).

%% Logs a message
> logi:info("foo").

%% Prints metrics
> io:format(prometheus_text_format:format(example_registry)).
# TYPE logi_messages_total counter
# HELP logi_messages_total Messages count
logi_messages_total{sink="metrics_sink",severity="info",application="stdlib",module="erl_eval"} 1

By using prometheus_httpd, you can easily expose metrics collected by logi_prometheus_sink.

%% Installs `metrics_sink` to the default channel
> Sink = logi_prometheus_sink:new(metrics_sink).
> {ok, _} = logi_channel:install_sink(Sink, info).

%% Starts metrics exporter (i.e., HTTP server)
> prometheus_httpd:start().

%% Retrieves current metrics
> httpc:request("http://localhost:8081/metrics").