Merge pull request #10044 from zmstone/0228-fix-node-info-format

fix(emqx_mgmt): format stoped nodes correctly
This commit is contained in:
Zaiming (Stone) Shi 2023-03-01 11:39:09 +01:00 committed by GitHub
commit fdc0ad6669
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 24 deletions

View File

@ -141,9 +141,28 @@ node_info() ->
uptime => proplists:get_value(uptime, BrokerInfo), uptime => proplists:get_value(uptime, BrokerInfo),
version => iolist_to_binary(proplists:get_value(version, BrokerInfo)), version => iolist_to_binary(proplists:get_value(version, BrokerInfo)),
edition => emqx_release:edition_longstr(), edition => emqx_release:edition_longstr(),
role => mria_rlog:role() role => mria_rlog:role(),
log_path => log_path(),
sys_path => iolist_to_binary(code:root_dir())
}. }.
log_path() ->
RootDir = code:root_dir(),
Configs = logger:get_handler_config(),
case get_log_path(Configs) of
undefined ->
<<"log.file_handler.default.enable is false, not logging to file.">>;
Path ->
iolist_to_binary(filename:join(RootDir, Path))
end.
get_log_path([#{config := #{file := Path}} | _LoggerConfigs]) ->
filename:dirname(Path);
get_log_path([_LoggerConfig | LoggerConfigs]) ->
get_log_path(LoggerConfigs);
get_log_path([]) ->
undefined.
get_sys_memory() -> get_sys_memory() ->
case os:type() of case os:type() of
{unix, linux} -> {unix, linux} ->

View File

@ -293,31 +293,12 @@ get_stats(Node) ->
%% internal function %% internal function
format(_Node, Info = #{memory_total := Total, memory_used := Used}) -> format(_Node, Info = #{memory_total := Total, memory_used := Used}) ->
RootDir = list_to_binary(code:root_dir()),
LogPath =
case log_path() of
undefined ->
<<"log.file_handler.default.enable is false,only log to console">>;
Path ->
filename:join(RootDir, Path)
end,
Info#{ Info#{
memory_total := emqx_mgmt_util:kmg(Total), memory_total := emqx_mgmt_util:kmg(Total),
memory_used := emqx_mgmt_util:kmg(Used), memory_used := emqx_mgmt_util:kmg(Used)
sys_path => RootDir, };
log_path => LogPath format(_Node, Info) when is_map(Info) ->
}. Info.
log_path() ->
Configs = logger:get_handler_config(),
get_log_path(Configs).
get_log_path([#{config := #{file := Path}} | _LoggerConfigs]) ->
filename:dirname(Path);
get_log_path([_LoggerConfig | LoggerConfigs]) ->
get_log_path(LoggerConfigs);
get_log_path([]) ->
undefined.
node_error() -> node_error() ->
emqx_dashboard_swagger:error_codes([?SOURCE_ERROR], <<"Node error">>). emqx_dashboard_swagger:error_codes([?SOURCE_ERROR], <<"Node error">>).

View File

@ -0,0 +1 @@
Fix node information formatter for stopped nodes in the cluster.

View File

@ -0,0 +1 @@
修复 v5.0.18 引入的一个节点信息序列化时发生的错误。