Minor mtp_metric optimizations

parent e66778ed
...@@ -45,11 +45,30 @@ rt(Name, Fun, Extra) -> ...@@ -45,11 +45,30 @@ rt(Name, Fun, Extra) ->
notify(Type, Name, Value, Extra) -> notify(Type, Name, Value, Extra) ->
case application:get_env(?APP, metric_backend) of case get_backend() of
{ok, Mod} -> undefined ->
Mod:notify(Type, Name, Value, Extra); false;
_ -> Mod ->
false Mod:notify(Type, Name, Value, Extra)
end.
get_backend() ->
%% Cache resutl of application:get_env in process dict because it's on the hot path
case erlang:get(metric_backend) of
undefined ->
case application:get_env(?APP, metric_backend) of
{ok, Mod} when Mod =/= false;
Mod =/= undefined ->
erlang:put(metric_backend, Mod),
Mod;
_ ->
erlang:put(metric_backend, false),
undefined
end;
false ->
undefined;
Mod ->
Mod
end. end.
-spec passive_metrics() -> [{metric_type(), metric_name(), metric_doc(), -spec passive_metrics() -> [{metric_type(), metric_name(), metric_doc(),
...@@ -80,8 +99,7 @@ passive_metrics() -> ...@@ -80,8 +99,7 @@ passive_metrics() ->
[{gauge, [?APP, connections, count], [{gauge, [?APP, connections, count],
"Count of ranch connections", "Count of ranch connections",
[{#{listener => H}, proplists:get_value(all_connections, P)} [{#{listener => H}, proplists:get_value(all_connections, P)}
|| {H, P} <- ranch:info(), || {H, P} <- mtproto_proxy_app:mtp_listeners()]}] ].
proplists:get_value(protocol, P) == mtp_handler]}] ].
-spec active_metrics() -> [{metric_type(), metric_name(), metric_doc(), Opts}] -spec active_metrics() -> [{metric_type(), metric_name(), metric_doc(), Opts}]
when when
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment