fix(os_mon): ensure float point number for ~f format
This commit is contained in:
parent
c355c40ea8
commit
5f3780a032
|
@ -123,33 +123,28 @@ handle_info({timeout, _Timer, mem_check}, #{sysmem_high_watermark := HWM} = Stat
|
||||||
handle_info({timeout, _Timer, cpu_check}, State) ->
|
handle_info({timeout, _Timer, cpu_check}, State) ->
|
||||||
CPUHighWatermark = emqx:get_config([sysmon, os, cpu_high_watermark]) * 100,
|
CPUHighWatermark = emqx:get_config([sysmon, os, cpu_high_watermark]) * 100,
|
||||||
CPULowWatermark = emqx:get_config([sysmon, os, cpu_low_watermark]) * 100,
|
CPULowWatermark = emqx:get_config([sysmon, os, cpu_low_watermark]) * 100,
|
||||||
%% TODO: should be improved?
|
|
||||||
case emqx_vm:cpu_util() of
|
case emqx_vm:cpu_util() of
|
||||||
0 ->
|
0 ->
|
||||||
ok;
|
ok;
|
||||||
Busy when Busy > CPUHighWatermark ->
|
Busy when Busy > CPUHighWatermark ->
|
||||||
Usage = list_to_binary(io_lib:format("~.2f%", [Busy])),
|
|
||||||
Message = <<Usage/binary, " cpu usage">>,
|
|
||||||
_ = emqx_alarm:activate(
|
_ = emqx_alarm:activate(
|
||||||
high_cpu_usage,
|
high_cpu_usage,
|
||||||
#{
|
#{
|
||||||
usage => Usage,
|
usage => Busy,
|
||||||
high_watermark => CPUHighWatermark,
|
high_watermark => CPUHighWatermark,
|
||||||
low_watermark => CPULowWatermark
|
low_watermark => CPULowWatermark
|
||||||
},
|
},
|
||||||
Message
|
usage_msg(Busy, cpu)
|
||||||
);
|
);
|
||||||
Busy when Busy < CPULowWatermark ->
|
Busy when Busy < CPULowWatermark ->
|
||||||
Usage = list_to_binary(io_lib:format("~.2f%", [Busy])),
|
|
||||||
Message = <<Usage/binary, " cpu usage">>,
|
|
||||||
ok = emqx_alarm:ensure_deactivated(
|
ok = emqx_alarm:ensure_deactivated(
|
||||||
high_cpu_usage,
|
high_cpu_usage,
|
||||||
#{
|
#{
|
||||||
usage => Usage,
|
usage => Busy,
|
||||||
high_watermark => CPUHighWatermark,
|
high_watermark => CPUHighWatermark,
|
||||||
low_watermark => CPULowWatermark
|
low_watermark => CPULowWatermark
|
||||||
},
|
},
|
||||||
Message
|
usage_msg(Busy, cpu)
|
||||||
);
|
);
|
||||||
_Busy ->
|
_Busy ->
|
||||||
ok
|
ok
|
||||||
|
@ -208,8 +203,6 @@ update_mem_alarm_stauts(HWM) when HWM > 1.0 orelse HWM < 0.0 ->
|
||||||
update_mem_alarm_stauts(HWM0) ->
|
update_mem_alarm_stauts(HWM0) ->
|
||||||
HWM = HWM0 * 100,
|
HWM = HWM0 * 100,
|
||||||
Usage = current_sysmem_percent(),
|
Usage = current_sysmem_percent(),
|
||||||
UsageStr = list_to_binary(io_lib:format("~.2f%", [Usage])),
|
|
||||||
Message = <<UsageStr/binary, " mem usage">>,
|
|
||||||
case Usage > HWM of
|
case Usage > HWM of
|
||||||
true ->
|
true ->
|
||||||
_ = emqx_alarm:activate(
|
_ = emqx_alarm:activate(
|
||||||
|
@ -218,7 +211,7 @@ update_mem_alarm_stauts(HWM0) ->
|
||||||
usage => Usage,
|
usage => Usage,
|
||||||
high_watermark => HWM
|
high_watermark => HWM
|
||||||
},
|
},
|
||||||
Message
|
usage_msg(Usage, mem)
|
||||||
);
|
);
|
||||||
_ ->
|
_ ->
|
||||||
ok = emqx_alarm:ensure_deactivated(
|
ok = emqx_alarm:ensure_deactivated(
|
||||||
|
@ -227,7 +220,11 @@ update_mem_alarm_stauts(HWM0) ->
|
||||||
usage => Usage,
|
usage => Usage,
|
||||||
high_watermark => HWM
|
high_watermark => HWM
|
||||||
},
|
},
|
||||||
Message
|
usage_msg(Usage, mem)
|
||||||
)
|
)
|
||||||
end,
|
end,
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
usage_msg(Usage, What) ->
|
||||||
|
%% devide by 1.0 to ensure float point number
|
||||||
|
iolist_to_binary(io_lib:format("~.2f% ~p usage", [Usage / 1.0, What])).
|
||||||
|
|
|
@ -233,8 +233,7 @@ mem_info() ->
|
||||||
[{total_memory, Total}, {used_memory, Total - Free}].
|
[{total_memory, Total}, {used_memory, Total - Free}].
|
||||||
|
|
||||||
ftos(F) ->
|
ftos(F) ->
|
||||||
S = io_lib:format("~.2f", [F]),
|
io_lib:format("~.2f", [F / 1.0]).
|
||||||
S.
|
|
||||||
|
|
||||||
%%%% erlang vm scheduler_usage fun copied from recon
|
%%%% erlang vm scheduler_usage fun copied from recon
|
||||||
scheduler_usage(Interval) when is_integer(Interval) ->
|
scheduler_usage(Interval) when is_integer(Interval) ->
|
||||||
|
|
Loading…
Reference in New Issue