|
|
@@ -19,15 +19,15 @@
|
|
|
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
|
|
|
|
|
init([]) ->
|
|
|
- {ok, { {one_for_one, 10, 100}, []} }.
|
|
|
+ {ok, {{one_for_one, 10, 100}, []}}.
|
|
|
|
|
|
start_statsd() ->
|
|
|
{ok, Pid} = supervisor:start_child(?MODULE, estatsd_child_spec()),
|
|
|
{ok, _Pid1} = supervisor:start_child(?MODULE, emqx_statsd_child_spec(Pid)).
|
|
|
|
|
|
stop_statsd() ->
|
|
|
- supervisor:terminate_child(emqx_statsd_sup, emqx_statsd),
|
|
|
- supervisor:terminate_child(emqx_statsd_sup, estatsd).
|
|
|
+ ok = supervisor:terminate_child(?MODULE, emqx_statsd),
|
|
|
+ ok = supervisor:terminate_child(?MODULE, estatsd).
|
|
|
%%==============================================================================================
|
|
|
%% internal
|
|
|
estatsd_child_spec() ->
|
|
|
@@ -39,22 +39,36 @@ estatsd_child_spec() ->
|
|
|
, modules => [estatsd]}.
|
|
|
|
|
|
estatsd_options() ->
|
|
|
- Host = application:get_env(?APP, host, ?DEFAULT_HOST),
|
|
|
- Port = application:get_env(?APP, port, ?DEFAULT_PORT),
|
|
|
- Prefix = application:get_env(?APP, prefix, ?DEFAULT_PREFIX),
|
|
|
- Tags = application:get_env(?APP, tags, ?DEFAULT_TAGS),
|
|
|
- BatchSize = application:get_env(?APP, batch_size, ?DEFAULT_BATCH_SIZE),
|
|
|
+ Server = get_conf(server, {?DEFAULT_HOST, ?DEFAULT_PORT}),
|
|
|
+ {Host, Port} = host_port(Server),
|
|
|
+ Prefix = get_conf(prefix, ?DEFAULT_PREFIX),
|
|
|
+ Tags = tags(get_conf(tags, ?DEFAULT_TAGS)),
|
|
|
+ BatchSize = get_conf(batch_size, ?DEFAULT_BATCH_SIZE),
|
|
|
[{host, Host}, {port, Port}, {prefix, Prefix}, {tags, Tags}, {batch_size, BatchSize}].
|
|
|
|
|
|
+host_port({Host, Port}) -> {Host, Port};
|
|
|
+host_port(Server) ->
|
|
|
+ case string:tokens(Server, ":") of
|
|
|
+ [Domain] -> {Domain, ?DEFAULT_PORT};
|
|
|
+ [Domain, Port] -> {Domain, list_to_integer(Port)}
|
|
|
+ end.
|
|
|
+
|
|
|
+tags(Map) ->
|
|
|
+ Tags = maps:to_list(Map),
|
|
|
+ [{atom_to_binary(Key, utf8), Value} || {Key, Value} <- Tags].
|
|
|
+
|
|
|
emqx_statsd_child_spec(Pid) ->
|
|
|
#{id => emqx_statsd
|
|
|
- , start => {emqx_statsd, start_link, [emqx_statsd_options(Pid)]}
|
|
|
+ , start => {emqx_statsd, start_link, [[{estatsd_pid, Pid} | emqx_statsd_options()]]}
|
|
|
, restart => permanent
|
|
|
, shutdown => 5000
|
|
|
, type => worker
|
|
|
, modules => [emqx_statsd]}.
|
|
|
|
|
|
-emqx_statsd_options(Pid) ->
|
|
|
- SampleTimeInterval = application:get_env(?APP, sample_time_interval, ?DEFAULT_SAMPLE_TIME_INTERVAL),
|
|
|
- FlushTimeInterval = application:get_env(?APP, flush_time_interval, ?DEFAULT_FLUSH_TIME_INTERVAL),
|
|
|
- [{estatsd_pid, Pid}, {sample_time_interval, SampleTimeInterval}, {flush_time_interval, FlushTimeInterval}].
|
|
|
+emqx_statsd_options() ->
|
|
|
+ SampleTimeInterval = get_conf(sample_time_interval, ?DEFAULT_SAMPLE_TIME_INTERVAL),
|
|
|
+ FlushTimeInterval = get_conf(flush_time_interval, ?DEFAULT_FLUSH_TIME_INTERVAL),
|
|
|
+ [{sample_time_interval, SampleTimeInterval}, {flush_time_interval, FlushTimeInterval}].
|
|
|
+
|
|
|
+get_conf(Key, Default) ->
|
|
|
+ emqx_config:get([?APP, Key], Default).
|