Skip to content

Commit

Permalink
Allow configuration of the node name
Browse files Browse the repository at this point in the history
  • Loading branch information
Phu Lien committed Mar 29, 2024
1 parent 1978c2b commit 4e81f05
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/system_monitor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
, stop_top/0
, fmt_mfa/1
, fmt_stack/1
, node_name/0
]).

%% gen_server callbacks
Expand Down Expand Up @@ -245,8 +246,8 @@ report_full_status() ->
_ ->
<<>>
end,
system_monitor_callback:produce(node_role,
[{node_role, node(), TS, iolist_to_binary(NodeReport)}]).
system_monitor_callback:produce(
node_role, [{node_role, node_name(), TS, iolist_to_binary(NodeReport)}]).

%%------------------------------------------------------------------------------
%% @doc Calculate reductions per application.
Expand All @@ -272,15 +273,17 @@ report_app_top(TS) ->
present_results(Record, Tag, Values, TS) ->
{ok, Thresholds} = application:get_env(?APP, top_significance_threshold),
Threshold = maps:get(Tag, Thresholds, 0),
Node = node(),
L = lists:filtermap(fun ({Key, Val}) when Val > Threshold ->
{true, {Record, Node, TS, Key, Tag, Val}};
{true, {Record, node_name(), TS, Key, Tag, Val}};
(_) ->
false
end,
Values),
system_monitor_callback:produce(Record, L).

node_name() ->
application:get_env(?APP, node_name, node()).

%%--------------------------------------------------------------------
%% @doc logs "the interesting parts" of erl_top
%%--------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions src/system_monitor_top.erl
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ finalize_proc_info(#pid_info{pid = Pid, initial_call = InitialCall,
[{CurrModule, CurrFun, CurrArity, _} | _] ->
{CurrModule, CurrFun, CurrArity}
end,
#erl_top{node = node(),
#erl_top{node = system_monitor:node_name(),
ts = Now,
pid = pid_to_list(ProcInfo#pid_info.pid),
group_leader = pid_to_list(GL),
Expand All @@ -424,7 +424,7 @@ finalize_proc_info(#pid_info{pid = Pid, initial_call = InitialCall,
current_stacktrace = Stacktrace,
current_function = CurrentFunction};
undefined ->
#erl_top{node = node(),
#erl_top{node = system_monitor:node_name(),
ts = Now,
pid = pid_to_list(ProcInfo#pid_info.pid),
group_leader = pid_to_list(GL),
Expand Down Expand Up @@ -616,7 +616,7 @@ do_get_app_top(FieldId) ->

-spec fake_erl_top_msg(integer()) -> #erl_top{}.
fake_erl_top_msg(Now) ->
#erl_top{ node = node()
#erl_top{ node = system_monitor:node_name()
, ts = Now
, pid = "<42.42.42>"
, group_leader = "<42.42.42>"
Expand Down

0 comments on commit 4e81f05

Please sign in to comment.