fix(telemetry): use required fields, rolling distro use PRETTY_NAME

This commit is contained in:
JimMoen 2021-12-20 16:44:51 +08:00
parent 2ee683d2f9
commit 5c29c20426
1 changed files with 17 additions and 21 deletions

View File

@ -82,7 +82,7 @@
timer = undefined :: undefined | reference() timer = undefined :: undefined | reference()
}). }).
%% The count of 100-nanosecond intervals between the UUID epoch %% The count of 100-nanosecond intervals between the UUID epoch
%% 1582-10-15 00:00:00 and the UNIX epoch 1970-01-01 00:00:00. %% 1582-10-15 00:00:00 and the UNIX epoch 1970-01-01 00:00:00.
-define(GREGORIAN_EPOCH_OFFSET, 16#01b21dd213814000). -define(GREGORIAN_EPOCH_OFFSET, 16#01b21dd213814000).
@ -253,29 +253,23 @@ os_info() ->
[{os_name, Name}, [{os_name, Name},
{os_version, Version}]; {os_version, Version}];
{unix, _} -> {unix, _} ->
case file:read_file_info("/etc/os-release") of case file:read_file("/etc/os-release") of
{error, _} -> {error, _} ->
[{os_name, "Unknown"}, [{os_name, "Unknown"},
{os_version, "Unknown"}]; {os_version, "Unknown"}];
{ok, FileInfo} -> {ok, FileContent} ->
case FileInfo#file_info.access of OSInfo = lists:foldl(fun(Line, Acc) ->
Access when Access =:= read orelse Access =:= read_write -> [Var, Value] = string:tokens(Line, "="),
OSInfo = lists:foldl(fun(Line, Acc) -> NValue = case Value of
[Var, Value] = string:tokens(Line, "="), _ when is_list(Value) ->
NValue = case Value of lists:nth(1, string:tokens(Value, "\""));
_ when is_list(Value) -> _ ->
lists:nth(1, string:tokens(Value, "\"")); Value
_ -> end,
Value [{Var, NValue} | Acc]
end, end, [], string:tokens(binary:bin_to_list(FileContent), "\n")),
[{Var, NValue} | Acc] [{os_name, get_value("NAME", OSInfo)},
end, [], string:tokens(os:cmd("cat /etc/os-release"), "\n")), {os_version, get_value("VERSION", OSInfo, get_value("VERSION_ID", OSInfo, get_value("PRETTY_NAME", OSInfo)))}]
[{os_name, get_value("NAME", OSInfo)},
{os_version, get_value("VERSION", OSInfo, get_value("VERSION_ID", OSInfo))}];
_ ->
[{os_name, "Unknown"},
{os_version, "Unknown"}]
end
end; end;
{win32, nt} -> {win32, nt} ->
Ver = os:cmd("ver"), Ver = os:cmd("ver"),
@ -429,5 +423,7 @@ module_attributes(Module) ->
bin(L) when is_list(L) -> bin(L) when is_list(L) ->
list_to_binary(L); list_to_binary(L);
bin(A) when is_atom(A) ->
atom_to_binary(A);
bin(B) when is_binary(B) -> bin(B) when is_binary(B) ->
B. B.