mirror of
https://github.com/valitydev/how_are_you.git
synced 2024-11-06 02:35:16 +00:00
Merge pull request #20 from rbkmoney/ft/ED-204/fix-hay
This commit is contained in:
commit
2fd8013420
11
Makefile
11
Makefile
@ -20,8 +20,13 @@ clean:
|
||||
$(REBAR) clean
|
||||
|
||||
distclean:
|
||||
$(REBAR) clean -a
|
||||
rm -rf _build
|
||||
|
||||
#test:
|
||||
# $(REBAR) ct
|
||||
run:
|
||||
$(REBAR) as run shell
|
||||
|
||||
check_format:
|
||||
$(REBAR) fmt -c
|
||||
|
||||
format:
|
||||
$(REBAR) fmt -w
|
||||
|
16
rebar.config
16
rebar.config
@ -1,6 +1,5 @@
|
||||
% Common project erlang options.
|
||||
{erl_opts, [
|
||||
|
||||
% mandatory
|
||||
debug_info,
|
||||
warnings_as_errors,
|
||||
@ -23,7 +22,6 @@
|
||||
% bin_opt_info
|
||||
% no_auto_import
|
||||
% warn_missing_spec_all
|
||||
|
||||
]}.
|
||||
|
||||
% Common project dependencies.
|
||||
@ -60,5 +58,19 @@
|
||||
{deps, [
|
||||
{woody, {git, "git@github.com:rbkmoney/woody_erlang.git", {branch, "master"}}}
|
||||
]}
|
||||
]},
|
||||
{run, [
|
||||
{deps, [
|
||||
recon
|
||||
]}
|
||||
]}
|
||||
]}.
|
||||
|
||||
{plugins, [
|
||||
{erlfmt, "0.15.1"}
|
||||
]}.
|
||||
|
||||
{erlfmt, [
|
||||
{print_width, 120},
|
||||
{files, ["src/*.{app.src,erl}", "rebar.config"]}
|
||||
]}.
|
||||
|
10
rebar.lock
10
rebar.lock
@ -1,14 +1,16 @@
|
||||
{"1.1.0",
|
||||
[{<<"bear">>,{pkg,<<"bear">>,<<"0.8.7">>},1},
|
||||
{"1.2.0",
|
||||
[{<<"bear">>,{pkg,<<"bear">>,<<"0.9.0">>},1},
|
||||
{<<"cg_mon">>,
|
||||
{git,"https://github.com/rbkmoney/cg_mon.git",
|
||||
{ref,"5a87a37694e42b6592d3b4164ae54e0e87e24e18"}},
|
||||
0},
|
||||
{<<"folsom">>,
|
||||
{git,"https://github.com/folsom-project/folsom.git",
|
||||
{ref,"eeb1cc467eb64bd94075b95b8963e80d8b4df3df"}},
|
||||
{ref,"62fd0714e6f0b4e7833880afe371a9c882ea0fc2"}},
|
||||
0}]}.
|
||||
[
|
||||
{pkg_hash,[
|
||||
{<<"bear">>, <<"16264309AE5D005D03718A5C82641FCC259C9E8F09ADEB6FD79CA4271168656F">>}]}
|
||||
{<<"bear">>, <<"A31CCF5361791DD5E708F4789D67E2FEF496C4F05935FC59ADC11622F834D128">>}]},
|
||||
{pkg_hash_ext,[
|
||||
{<<"bear">>, <<"47F71F098F2E3CD05E124A896C5EC2F155967A2B6FF6731E0D627312CCAB7E28">>}]}
|
||||
].
|
||||
|
@ -16,7 +16,6 @@
|
||||
-export([handle_cast/2]).
|
||||
-export([handle_info/2]).
|
||||
-export([terminate/2]).
|
||||
-export([code_change/3]).
|
||||
|
||||
-define(SERVER, ?MODULE).
|
||||
-define(DEFAULT_INTERVAL, 5000).
|
||||
@ -57,43 +56,38 @@ start_link({Handler, Options}) ->
|
||||
|
||||
%%
|
||||
|
||||
-spec init({handler(), handler_options()}) -> {ok, state()}.
|
||||
-spec init({handler(), handler_options()}) -> {ok, state(), hibernate}.
|
||||
|
||||
init({Handler, Options}) ->
|
||||
{ok, HandlerState} = Handler:init(Options),
|
||||
ok = init_metrics(Handler:gather_metrics(HandlerState)),
|
||||
{ok, start_timer(#state{handler = Handler, handler_state = HandlerState})}.
|
||||
{ok, start_timer(#state{handler = Handler, handler_state = HandlerState}), hibernate}.
|
||||
|
||||
-spec handle_call(term(), {pid(), term()}, state()) -> {noreply, state()}.
|
||||
-spec handle_call(term(), {pid(), term()}, state()) -> {noreply, state(), hibernate}.
|
||||
|
||||
handle_call(_Msg, _From, State) ->
|
||||
{noreply, State}.
|
||||
{noreply, State, hibernate}.
|
||||
|
||||
-spec handle_cast(term(), state()) -> {noreply, state()}.
|
||||
-spec handle_cast(term(), state()) -> {noreply, state(), hibernate}.
|
||||
|
||||
handle_cast(_Msg, State) ->
|
||||
{noreply, State}.
|
||||
{noreply, State, hibernate}.
|
||||
|
||||
-spec handle_info(term(), state()) -> {noreply, state()}.
|
||||
-spec handle_info(term(), state()) -> {noreply, state(), hibernate}.
|
||||
|
||||
handle_info(timeout, State0) ->
|
||||
handle_info({timeout, TRef, update}, State0 = #state{timer = TRef}) ->
|
||||
%% TODO add some sort of monitoring
|
||||
%% to prevent metrics overloading entire system
|
||||
#state{handler = Handler, handler_state = HandlerState} = State = restart_timer(State0),
|
||||
ok = push_metrics(Handler:gather_metrics(HandlerState)),
|
||||
{noreply, State};
|
||||
|
||||
{noreply, State, hibernate};
|
||||
handle_info(_Msg, State) ->
|
||||
{noreply, State}.
|
||||
{noreply, State, hibernate}.
|
||||
|
||||
-spec terminate(term(), state()) -> ok.
|
||||
terminate(_Reason, _State) ->
|
||||
ok.
|
||||
|
||||
-spec code_change(term(), state(), term()) -> {error, noimpl}.
|
||||
code_change(_OldVsn, _State, _Extra) ->
|
||||
{error, noimpl}.
|
||||
|
||||
%% internal
|
||||
|
||||
init_metrics(Metrics) ->
|
||||
@ -117,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}).
|
||||
@ -126,4 +119,4 @@ restart_timer(State = #state{timer = TimerRef}) ->
|
||||
|
||||
start_timer(State = #state{timer = undefined, handler = Handler, handler_state = HandlerState}) ->
|
||||
Interval = Handler:get_interval(HandlerState),
|
||||
State#state{timer = erlang:send_after(Interval, self(), timeout)}.
|
||||
State#state{timer = erlang:start_timer(Interval, self(), update)}.
|
||||
|
@ -17,7 +17,6 @@
|
||||
-export([handle_cast/2]).
|
||||
-export([handle_info/2]).
|
||||
-export([terminate/2]).
|
||||
-export([code_change/3]).
|
||||
|
||||
-define(SERVER, ?MODULE).
|
||||
-define(DEFAULT_INTERVAL, 5000).
|
||||
@ -64,49 +63,43 @@ start_link({Handler, Options}) ->
|
||||
|
||||
%%
|
||||
|
||||
-spec init({handler(), handler_options()}) -> {ok, state()}.
|
||||
-spec init({handler(), handler_options()}) -> {ok, state(), hibernate}.
|
||||
|
||||
init({Handler, Options}) ->
|
||||
{ok, HandlerState} = Handler:init(Options),
|
||||
{ok, start_timer(#state{handler = Handler, handler_state = HandlerState})}.
|
||||
{ok, start_timer(#state{handler = Handler, handler_state = HandlerState}), hibernate}.
|
||||
|
||||
-spec handle_call(term(), {pid(), term()}, state()) -> {noreply, state()}.
|
||||
-spec handle_call(term(), {pid(), term()}, state()) -> {noreply, state(), hibernate}.
|
||||
|
||||
handle_call(_Msg, _From, State) ->
|
||||
{noreply, State}.
|
||||
{noreply, State, hibernate}.
|
||||
|
||||
-spec handle_cast(term(), state()) -> {noreply, state()}.
|
||||
-spec handle_cast(term(), state()) -> {noreply, state(), hibernate}.
|
||||
|
||||
handle_cast(_Msg, State) ->
|
||||
{noreply, State}.
|
||||
{noreply, State, hibernate}.
|
||||
|
||||
-spec handle_info(term(), state()) -> {noreply, state()}.
|
||||
-spec handle_info(term(), state()) -> {noreply, state(), hibernate}.
|
||||
|
||||
handle_info(timeout, State0) ->
|
||||
handle_info({timeout, TRef, publish}, State0 = #state{timer = TRef}) ->
|
||||
%% TODO add some sort of monitoring
|
||||
%% to prevent metrics overloading entire system
|
||||
#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}};
|
||||
|
||||
{noreply, State#state{handler_state = NewHandlerState}, hibernate};
|
||||
handle_info(_Msg, State) ->
|
||||
{noreply, State}.
|
||||
{noreply, State, hibernate}.
|
||||
|
||||
-spec terminate(term(), state()) -> ok.
|
||||
terminate(_Reason, _State) ->
|
||||
ok.
|
||||
|
||||
-spec code_change(term(), state(), term()) -> {error, noimpl}.
|
||||
code_change(_OldVsn, _State, _Extra) ->
|
||||
{error, noimpl}.
|
||||
|
||||
%% internal
|
||||
|
||||
-spec restart_timer(state()) -> 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}).
|
||||
@ -115,4 +108,4 @@ restart_timer(State = #state{timer = TimerRef}) ->
|
||||
|
||||
start_timer(State = #state{timer = undefined, handler = Handler, handler_state = HandlerState}) ->
|
||||
Interval = Handler:get_interval(HandlerState),
|
||||
State#state{timer = erlang:send_after(Interval, self(), timeout)}.
|
||||
State#state{timer = erlang:start_timer(Interval, self(), publish)}.
|
||||
|
@ -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,7 +70,8 @@ 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
|
||||
ok =
|
||||
case Fold(fun process_metrics/2, {State, [], 0}) of
|
||||
{State, Packet, Size} when Size > 0 ->
|
||||
ok = send_packet(Packet, State);
|
||||
{State, [], 0} ->
|
||||
|
@ -72,7 +72,6 @@ gather_io_stat() ->
|
||||
|| {Key, Val} <- [Input, Output]
|
||||
].
|
||||
|
||||
|
||||
%% TODO do we need this?
|
||||
%% Probably not cuz it can be monitored through standart tools
|
||||
gather_system_memory() ->
|
||||
@ -104,12 +103,11 @@ gather_vm_info() ->
|
||||
|| Name <- get_vm_info_keys()
|
||||
].
|
||||
|
||||
-ifdef(OTP_RELEASE).
|
||||
-if(?OTP_RELEASE >= 21).
|
||||
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,
|
||||
@ -118,32 +116,19 @@ 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
|
||||
].
|
||||
-endif.
|
||||
-else.
|
||||
gather_load_stat_keys() ->
|
||||
[
|
||||
total_run_queue_lengths,
|
||||
total_active_tasks,
|
||||
context_switches,
|
||||
reductions,
|
||||
wall_clock,
|
||||
runtime
|
||||
].
|
||||
get_vm_info_keys() ->
|
||||
[
|
||||
port_count, port_limit,
|
||||
process_count, process_limit,
|
||||
schedulers, schedulers_online
|
||||
].
|
||||
-endif.
|
||||
|
||||
get_statistics_counter(Key) ->
|
||||
case erlang:statistics(Key) of
|
||||
@ -164,4 +149,5 @@ gather_scheduler_utilization() ->
|
||||
]
|
||||
end,
|
||||
[],
|
||||
NewSwt).
|
||||
NewSwt
|
||||
).
|
||||
|
@ -15,12 +15,15 @@
|
||||
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) ->
|
||||
_Opts
|
||||
) ->
|
||||
Key = [<<"woody">>, <<"rpc">>, <<"server">>, Handler, Service, Function],
|
||||
how_are_you:metric_push(
|
||||
how_are_you:metric_construct(counter, Key, 1)),
|
||||
how_are_you:metric_construct(counter, Key, 1)
|
||||
),
|
||||
ok;
|
||||
handle_event(_Event, _RpcId, _Meta, _Opts) ->
|
||||
ok.
|
@ -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, []}},
|
||||
|
Loading…
Reference in New Issue
Block a user