Format sources

This commit is contained in:
Sergey Yelin 2021-07-20 12:23:02 +03:00
parent b9af9a70e8
commit 68a78e0977
No known key found for this signature in database
GPG Key ID: 0B653F3417EAEC54
11 changed files with 73 additions and 58 deletions

View File

@ -24,5 +24,9 @@ distclean:
run:
$(REBAR) as run shell
#test:
# $(REBAR) ct
check_format:
$(REBAR) fmt -c
format:
$(REBAR) fmt -w

View File

@ -1,6 +1,5 @@
% Common project erlang options.
{erl_opts, [
% mandatory
debug_info,
warnings_as_errors,
@ -23,13 +22,12 @@
% bin_opt_info
% no_auto_import
% warn_missing_spec_all
]}.
% Common project dependencies.
{deps, [
{folsom , {git, "https://github.com/folsom-project/folsom.git" , {branch, "master"}}},
{cg_mon , {git, "https://github.com/rbkmoney/cg_mon.git" , {branch, "master"}}}
{folsom, {git, "https://github.com/folsom-project/folsom.git", {branch, "master"}}},
{cg_mon, {git, "https://github.com/rbkmoney/cg_mon.git", {branch, "master"}}}
]}.
{xref_checks, [
@ -53,7 +51,7 @@
]}
]}.
{shell, [{apps,[how_are_you]}]}.
{shell, [{apps, [how_are_you]}]}.
{profiles, [
{test, [
@ -67,3 +65,12 @@
]}
]}
]}.
{plugins, [
{erlfmt, "0.15.1"}
]}.
{erlfmt, [
{print_width, 120},
{files, ["src/*.{app.src,erl}", "rebar.config"]}
]}.

View File

@ -71,5 +71,5 @@ gather_metrics(Metrics, KeyPrefix) ->
Data = [{Key, Fun()} || {Key, Fun} <- Metrics],
[
hay_metrics:construct(gauge, [KeyPrefix, Key], Value)
|| {Key, Value} <- Data, Value =/= undefined
|| {Key, Value} <- Data, Value =/= undefined
].

View File

@ -11,16 +11,16 @@
-export([fold/2]).
-record(metric, {
type :: metric_type(),
key :: metric_key(),
value :: metric_value()
type :: metric_type(),
key :: metric_key(),
value :: metric_value()
}).
-opaque metric() :: #metric{}.
-type metric_type() :: counter | gauge.
-type metric_key() :: binary().
-type metric_raw_key() ::
atom()
atom()
| integer()
| binary()
| maybe_improper_list(metric_raw_key(), metric_raw_key()).
@ -45,9 +45,9 @@
-spec construct(metric_type(), metric_raw_key(), metric_value()) -> metric().
construct(Type, Key, Val) ->
#metric{
type = Type,
key = construct_key(Key),
value = Val
type = Type,
key = construct_key(Key),
value = Val
}.
-spec type(metric()) -> metric_type().

View File

@ -81,7 +81,6 @@ handle_info({timeout, TRef, update}, State0 = #state{timer = TRef}) ->
#state{handler = Handler, handler_state = HandlerState} = State = restart_timer(State0),
ok = push_metrics(Handler:gather_metrics(HandlerState)),
{noreply, State, hibernate};
handle_info(_Msg, State) ->
{noreply, State, hibernate}.
@ -112,7 +111,6 @@ push_metrics(Metrics) ->
restart_timer(State = #state{timer = undefined}) ->
start_timer(State);
restart_timer(State = #state{timer = TimerRef}) ->
_ = erlang:cancel_timer(TimerRef),
start_timer(State#state{timer = undefined}).

View File

@ -87,7 +87,6 @@ handle_info({timeout, TRef, publish}, State0 = #state{timer = TRef}) ->
#state{handler = Handler, handler_state = HandlerState} = State = restart_timer(State0),
{ok, NewHandlerState} = Handler:publish_metrics(fun hay_metrics:fold/2, HandlerState),
{noreply, State#state{handler_state = NewHandlerState}, hibernate};
handle_info(_Msg, State) ->
{noreply, State, hibernate}.
@ -101,7 +100,6 @@ terminate(_Reason, _State) ->
restart_timer(State = #state{timer = undefined}) ->
start_timer(State);
restart_timer(State = #state{timer = TimerRef}) ->
_ = erlang:cancel_timer(TimerRef),
start_timer(State#state{timer = undefined}).

View File

@ -84,4 +84,4 @@ detect_ip_family(Host) ->
inet;
{error, _Details} ->
inet6
end.
end.

View File

@ -19,14 +19,14 @@
socket_opts => [gen_udp:option()]
}.
-type socket_opt() ::
gen_udp:option() |
{ip, inet:socket_address()} |
{fd, non_neg_integer()} |
{ifaddr, inet:socket_address()} |
inet:address_family() |
{port, inet:port_number()} |
{netns, file:filename_all()} |
{bind_to_device, binary()}.
gen_udp:option()
| {ip, inet:socket_address()}
| {fd, non_neg_integer()}
| {ifaddr, inet:socket_address()}
| inet:address_family()
| {port, inet:port_number()}
| {netns, file:filename_all()}
| {bind_to_device, binary()}.
-export_type([host/0]).
-export_type([port_number/0]).
@ -70,12 +70,13 @@ get_interval(#state{interval = Interval}) ->
-spec publish_metrics(metric_fold(), state()) -> {ok, state()} | {error, Reason :: term()}.
publish_metrics(Fold, State0) ->
State = resolve(ensure_socket_exists(State0)),
ok = case Fold(fun process_metrics/2, {State, [], 0}) of
{State, Packet, Size} when Size > 0 ->
ok = send_packet(Packet, State);
{State, [], 0} ->
ok
end,
ok =
case Fold(fun process_metrics/2, {State, [], 0}) of
{State, Packet, Size} when Size > 0 ->
ok = send_packet(Packet, State);
{State, [], 0} ->
ok
end,
{ok, State}.
%% Internals

View File

@ -61,7 +61,7 @@ gather_vm_memory() ->
% ]
[
hay_metrics:construct(gauge, [<<"vm">>, <<"memory">>, Key], Val)
|| {Key, Val} <- erlang:memory()
|| {Key, Val} <- erlang:memory()
].
gather_io_stat() ->
@ -69,10 +69,9 @@ gather_io_stat() ->
{Input, Output} = erlang:statistics(io),
[
hay_metrics:construct(gauge, [<<"vm">>, <<"io">>, Key], Val)
|| {Key, Val} <- [Input, Output]
|| {Key, Val} <- [Input, Output]
].
%% TODO do we need this?
%% Probably not cuz it can be monitored through standart tools
gather_system_memory() ->
@ -88,26 +87,27 @@ gather_system_memory() ->
% ]
[
hay_metrics:construct(gauge, [<<"system">>, <<"memory">>, Key], Val)
|| {Key, Val} <- memsup:get_system_memory_data()
|| {Key, Val} <- memsup:get_system_memory_data()
].
gather_load_stats() ->
Names = gather_load_stat_keys(),
[
hay_metrics:construct(gauge, [<<"vm">>, <<"load">>, Name], get_statistics_counter(Name))
|| Name <- Names
|| Name <- Names
].
gather_vm_info() ->
[
hay_metrics:construct(gauge, [<<"vm">>, <<"info">>, Name], erlang:system_info(Name))
|| Name <- get_vm_info_keys()
|| Name <- get_vm_info_keys()
].
gather_load_stat_keys() ->
[
total_run_queue_lengths,
total_run_queue_lengths_all, %% With dirty schedulers
%% With dirty schedulers
total_run_queue_lengths_all,
total_active_tasks,
context_switches,
reductions,
@ -116,11 +116,16 @@ gather_load_stat_keys() ->
].
get_vm_info_keys() ->
[
atom_count, atom_limit,
ets_count, ets_limit,
port_count, port_limit,
process_count, process_limit,
schedulers, schedulers_online,
atom_count,
atom_limit,
ets_count,
ets_limit,
port_count,
port_limit,
process_count,
process_limit,
schedulers,
schedulers_online,
dirty_cpu_schedulers_online,
dirty_io_schedulers
].
@ -144,4 +149,5 @@ gather_scheduler_utilization() ->
]
end,
[],
NewSwt).
NewSwt
).

View File

@ -12,15 +12,18 @@
-spec handle_event(Event, RpcId, Meta, Opts) -> ok when
Event :: woody_event_handler:event(),
RpcId :: woody:rpc_id() | undefined,
Meta :: woody_event_handler:event_meta(),
Opts :: woody:options().
Meta :: woody_event_handler:event_meta(),
Opts :: woody:options().
handle_event(
'invoke service handler', _RpcId,
'invoke service handler',
_RpcId,
#{function := Function, service_schema := {Handler, Service}},
_Opts) ->
Key = [<<"woody">>, <<"rpc">>, <<"server">>, Handler, Service, Function],
how_are_you:metric_push(
how_are_you:metric_construct(counter, Key, 1)),
_Opts
) ->
Key = [<<"woody">>, <<"rpc">>, <<"server">>, Handler, Service, Function],
how_are_you:metric_push(
how_are_you:metric_construct(counter, Key, 1)
),
ok;
handle_event(_Event, _RpcId, _Meta, _Opts) ->
ok.
ok.

View File

@ -1,7 +1,5 @@
{application, how_are_you, [
{description,
"Simple app for collecting and reporting metrics to somewere (statsd for ex.)"
},
{description, "Simple app for collecting and reporting metrics to somewere (statsd for ex.)"},
{vsn, "0.1"},
{registered, []},
{mod, {how_are_you, []}},