Packages
prometheus
1.7.0
6.1.3
6.1.2
6.1.1
6.1.0
6.0.3
6.0.2
6.0.1
6.0.0
5.1.1
5.1.0
5.0.0
4.13.0
retired
4.12.0
4.11.0
4.10.0
4.9.1
4.9.0
4.8.2
4.8.1
4.8.0
4.6.0
4.5.0
4.4.1
4.4.0
4.3.0
4.2.2
4.2.0
4.1.0
4.0.1
4.0.0
3.5.1
3.5.0
3.4.6
3.4.5
3.4.4
3.4.3
3.4.2
3.4.1
3.4.0
3.3.2
3.3.1
3.3.0
3.2.3
3.2.2
3.2.1
3.1.1
3.1.0
3.0.1
3.0.0
3.0.0-rc1
3.0.0-alpha9
3.0.0-alpha8
3.0.0-alpha7
3.0.0-alpha6
3.0.0-alpha5
3.0.0-alpha4
3.0.0-alpha3
3.0.0-alpha2
3.0.0-alpha10
3.0.0-alpha1
2.2.0
2.1.0
2.0.0
1.7.0
1.6.0
1.5.0
1.0.2
1.0.1
1.0.0
0.2.0
0.1.3
0.1.2
0.1.1
0.1.0
Prometheus.io client in Erlang
Current section
Files
Jump to
Current section
Files
src/prometheus_sup.erl
%%%-------------------------------------------------------------------
%% @doc prometheus top level supervisor.
%% @end
%%%-------------------------------------------------------------------
-module(prometheus_sup).
-behaviour(supervisor).
%% API
-export([start_link/0]).
%% Supervisor callbacks
-export([init/1]).
-include("prometheus.hrl").
-define(SERVER, ?MODULE).
%%====================================================================
%% API functions
%%====================================================================
start_link() ->
supervisor:start_link({local, ?SERVER}, ?MODULE, []).
%%====================================================================
%% Supervisor callbacks
%%====================================================================
%% Child :: {Id,StartFunc,Restart,Shutdown,Type,Modules}
init([]) ->
create_tables(),
register_collectors(),
register_metrics(),
{ok, {{one_for_one, 5, 1}, [{prometheus_counter,
{prometheus_counter, start_link, []},
permanent,
5000,
worker,
[prometheus_counter]},
{prometheus_summary,
{prometheus_summary, start_link, []},
permanent,
5000,
worker,
[prometheus_summary]},
{prometheus_histogram,
{prometheus_histogram, start_link, []},
permanent,
5000,
worker,
[prometheus_histogram]}]}}.
%%====================================================================
%% Internal functions
%%====================================================================
create_tables() ->
Tables = [
{?PROMETHEUS_REGISTRY_TABLE, {bag, read_concurrency}},
{?PROMETHEUS_COUNTER_TABLE, write_concurrency},
{?PROMETHEUS_GAUGE_TABLE, write_concurrency},
{?PROMETHEUS_SUMMARY_TABLE, write_concurrency},
{?PROMETHEUS_HISTOGRAM_TABLE, write_concurrency}
],
[maybe_create_table(Name, Concurrency) || {Name, Concurrency} <- Tables],
ok.
register_collectors() ->
[Collector:register() || Collector <- enabled_collectors()].
register_metrics() ->
[Metric:register(Spec, Registry) || {Registry, Metric, Spec} <- default_metrics()].
enabled_collectors() ->
case application:get_env(prometheus, default_collectors) of
undefined -> all_known_collectors();
Collectors -> Collectors
end.
all_known_collectors() ->
prometheus_misc:behaviour_modules(prometheus_collector).
default_metrics() ->
application:get_env(prometheus, default_metrics, []).
maybe_create_table(Name, {Type, Concurrency}) ->
case ets:info(Name) of
undefined ->
ets:new(Name, [Type, named_table, public, {Concurrency, true}]);
_ ->
ok
end;
maybe_create_table(Name, Concurrency) ->
maybe_create_table(Name, {set, Concurrency}).