Merge pull request #12733 from zhongwencool/fix-otel-metrics-create-view-crash

fix: otel metrics create view crash
This commit is contained in:
JianBo He 2024-03-19 16:10:58 +08:00 committed by GitHub
commit 92b53f23da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{application, emqx_opentelemetry, [ {application, emqx_opentelemetry, [
{description, "OpenTelemetry for EMQX Broker"}, {description, "OpenTelemetry for EMQX Broker"},
{vsn, "0.2.3"}, {vsn, "0.2.4"},
{registered, []}, {registered, []},
{mod, {emqx_otel_app, []}}, {mod, {emqx_otel_app, []}},
{applications, [ {applications, [

View File

@ -104,7 +104,7 @@ safe_stop_default_metrics() ->
_ = opentelemetry_experimental:stop_default_metrics(), _ = opentelemetry_experimental:stop_default_metrics(),
ok ok
catch catch
%% noramal scenario, metrics supervisor is not started %% normal scenario, metrics supervisor is not started
exit:{noproc, _} -> ok exit:{noproc, _} -> ok
end. end.
@ -254,6 +254,18 @@ create_counter(Meter, Counters, CallBack) ->
Counters Counters
). ).
%% Note: list_to_existing_atom("cpu.use") will crash
%% so we make sure the atom is already existing here
normalize_name(cpu_use) ->
'cpu.use';
normalize_name(cpu_idle) ->
'cpu.idle';
normalize_name(run_queue) ->
'run.queue';
normalize_name(total_memory) ->
'total.memory';
normalize_name(used_memory) ->
'used.memory';
normalize_name(Name) -> normalize_name(Name) ->
list_to_existing_atom(lists:flatten(string:replace(atom_to_list(Name), "_", ".", all))). list_to_existing_atom(lists:flatten(string:replace(atom_to_list(Name), "_", ".", all))).