Home

Awesome

Exometer InfluxDB reporter

This reporter pushes data to InfluxDB.

Build Status Hex pm

Usage

  1. Add exometer_influxdb to your list of dependencies in rebar.config:

    {deps, [
        {exometer_influxdb, "0.6.0"}
    ]}.
    
  2. Ensure exometer_influxdb is started before your application:

    {applications, [exometer_influxdb]}.
    
  3. Configure it:

    {exometer_core, [
        {report, [
            {reporters, [
                {exometer_report_influxdb, [{protocol, http},
                                            {host, <<"localhost">>},
                                            {port, 8086},
                                            {db, <<"exometer">>},
                                            {tags, [{region, ru}]}]}
            ]}
        ]}
    ]}.
    

Available options:

The following options can be set globally in the reporter config or locally in a specific subscription. The latter case overwrites the first.

Subscription examples:


{exometer_core, [
    {report, [
        {subscribers, [
            {exometer_report_influxdb, [erlang, memory], total, 5000, [{tags, {tag, value}}]}
         ]}
    ]}
]}.

By default the in InfluxDB visible name of the metric is derived from the exometer id: Here [erlang, memory] is translated to erlang_memory. It is possible to remove an item from this list by naming itself or its position with the from_name keyword. A removed element is then used as tag value:

exometer_report:subscribe(exometer_report_influxdb, [erlang, memory], total, 5000, [{tags, [{tag, {from_name, 2}}]}]).

This will result in a name erlang with the tag pair {tag, memory} (plus the default pair {host, Host}). To disable the removal of elements in the series name you can set:

{formatting, [{purge, [{all_from_name, false}]}]}

Further it might be handy to remove e.g. undefined tag keys or values. This can be done via:

{formatting, [{purge, [{tag_keys, undefined}, {tag_values, undefined}]}]}

Auto subscriptions:

There is capability for making a subscription automatically for each new entry. By default it is off. If you need to enable it in the reporter options and also provide a callback module which handles newly created entries.

{exometer_core, [
    {report, [
        {reporters, [
            {exometer_report_influxdb, [{autosubscribe, true},
                                        {subscriptions_module, exometer_influxdb_subscribe_mod},
                                        {protocol, http},
                                        {host, <<"localhost">>},
                                        {port, 8086},
                                        {db, <<"exometer">>},
                                        {tags, [{region, ru}]}]}
        ]}
    ]}
]}.

The callback module may look like:

-module(exometer_influxdb_subscribe_mod).
-export([subscribe/2]).

subscribe([metric, test], histogram) ->
    Tags = [{tags, [{type, {from_name, 2}}]}],
    [{[metric, test], min, 1000, Tags},
     {[metric, test], max, 1000, Tags},
     {[metric, test], median, 1000, Tags}];
subscribe([metric, test1], histogram) ->
    Tags = [{tags, [{type, {from_name, 2}}]}],
    [{[metric, test1], max, 1000, Tags},
     {[metric, test1], median, 1000, Tags}];
subscribe(_, _) -> [].

subscribe/2 calls for each new entry and it should return a list or just one subscription. Here a single subscription has the following layout:

{exometer_report:metric(), exometer_report:datapoint(), exometer_report:interval(), exometer_report:extra()}

TODO