fix: cpu usage and idle use two decimal places

- prometheus
- opentelemetry
This commit is contained in:
JimMoen 2024-04-03 17:35:49 +08:00
parent 04ba2aaf8a
commit 282cbb18be
No known key found for this signature in database
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
%% return 0.0 when `emqx_cpu_sup_worker` is not started
{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}]
end;

View File

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

View File

@ -119,7 +119,9 @@ code_change(_OldVsn, State, _Extra) ->
refresh(#{interval := Interval} = State) ->
NState =
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' => 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.