-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathelli_prometheus_config.erl
50 lines (38 loc) · 1.67 KB
/
elli_prometheus_config.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
%% @doc elli_prometheus config helpers.
%% @author Ilya Khaprov
%% @version 0.2.0
%% @see elli_prometheus
%% @copyright 2016-2020 elli-lib team
-module(elli_prometheus_config).
-author("Ilya Khaprov").
%% API.
-export([path/0,
format/0,
allowed_formats/0,
duration_buckets/0,
labels/0]).
%% Macros.
-define(DEFAULT_PATH, <<"/metrics">>).
-define(DEFAULT_FORMAT, auto).
-define(DEFAULT_DURATION_BUCKETS, [10, 100, 1000, 10000, 100000, 300000, 500000,
750000, 1000000, 1500000, 2000000, 3000000]).
-define(DEFAULT_LABELS, [method, handler, status_class]).
-define(DEFAULT_CONFIG, [{path, ?DEFAULT_PATH},
{format, ?DEFAULT_FORMAT},
{duration_buckets, ?DEFAULT_DURATION_BUCKETS},
{labels, ?DEFAULT_LABELS}]).
%%%===================================================================
%%% API
%%%===================================================================
path() -> get_value(path, ?DEFAULT_PATH).
format() -> get_value(format, ?DEFAULT_FORMAT).
allowed_formats() ->
[{prometheus_text_format:content_type(), prometheus_text_format},
{prometheus_protobuf_format:content_type(), prometheus_protobuf_format}].
duration_buckets() -> get_value(duration_buckets, ?DEFAULT_DURATION_BUCKETS).
labels() -> get_value(labels, ?DEFAULT_LABELS).
%%%===================================================================
%%% Private functions
%%%===================================================================
get_value(Key, Default) -> proplists:get_value(Key, config(), Default).
config() -> application:get_env(prometheus, elli_exporter, ?DEFAULT_CONFIG).