Merge pull request #12844 from JimMoen/EMQX-12012/cpu-use-idle-two-decimal-places

fix: cpu usage and idle use two decimal places
This commit is contained in:
JimMoen 2024-04-09 10:11:15 +08:00 committed by GitHub
commit 6cb00cc8c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 8 additions and 3 deletions

View File

@ -221,7 +221,9 @@ vm_stats('cpu') ->
case emqx_vm:cpu_util([CpuUtilArg]) of case emqx_vm:cpu_util([CpuUtilArg]) of
%% return 0.0 when `emqx_cpu_sup_worker` is not started %% return 0.0 when `emqx_cpu_sup_worker` is not started
{all, Use, Idle, _} -> {all, Use, Idle, _} ->
[{cpu_use, Use}, {cpu_idle, Idle}]; NUse = floor(Use * 100) / 100,
NIdle = ceil(Idle * 100) / 100,
[{cpu_use, NUse}, {cpu_idle, NIdle}];
_ -> _ ->
[{cpu_use, 0}, {cpu_idle, 0}] [{cpu_use, 0}, {cpu_idle, 0}]
end; end;

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.4"}, {vsn, "0.2.5"},
{registered, []}, {registered, []},
{mod, {emqx_otel_app, []}}, {mod, {emqx_otel_app, []}},
{applications, [ {applications, [

View File

@ -119,7 +119,9 @@ code_change(_OldVsn, State, _Extra) ->
refresh(#{interval := Interval} = State) -> refresh(#{interval := Interval} = State) ->
NState = NState =
case cpu_sup:util([]) of case cpu_sup:util([]) of
{all, U, I, _} -> {all, Use, Idle, _} ->
U = floor(Use * 100) / 100,
I = ceil(Idle * 100) / 100,
State#{'cpu.use' => U, 'cpu.idle' => I}; State#{'cpu.use' => U, 'cpu.idle' => I};
_ -> _ ->
State#{'cpu.use' => 0, 'cpu.idle' => 0} State#{'cpu.use' => 0, 'cpu.idle' => 0}

1
changes/fix-12844.en.md Normal file
View File

@ -0,0 +1 @@
CPU usage/idle statistics values are only retained with 2 decimal precision. This affects Prometheus statistical metrics and OpenTelemetry governance metrics.