Merge pull request #7265 from DDDHuang/monitor_api_fix
fix: monitor api query string param latest: legal & default value inf…
This commit is contained in:
commit
63b2501a1c
|
@ -75,14 +75,7 @@ samplers() ->
|
||||||
format(do_sample(all, infinity)).
|
format(do_sample(all, infinity)).
|
||||||
|
|
||||||
samplers(NodeOrCluster, Latest) ->
|
samplers(NodeOrCluster, Latest) ->
|
||||||
Time =
|
Time = latest2time(Latest),
|
||||||
case Latest of
|
|
||||||
infinity ->
|
|
||||||
infinity;
|
|
||||||
Latest when is_integer(Latest) ->
|
|
||||||
Now = erlang:system_time(millisecond),
|
|
||||||
Now - (Latest * 1000)
|
|
||||||
end,
|
|
||||||
case format(do_sample(NodeOrCluster, Time)) of
|
case format(do_sample(NodeOrCluster, Time)) of
|
||||||
{badrpc, Reason} ->
|
{badrpc, Reason} ->
|
||||||
{badrpc, Reason};
|
{badrpc, Reason};
|
||||||
|
@ -90,6 +83,9 @@ samplers(NodeOrCluster, Latest) ->
|
||||||
granularity_adapter(List)
|
granularity_adapter(List)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
latest2time(infinity) -> infinity;
|
||||||
|
latest2time(Latest) -> erlang:system_time(millisecond) - (Latest * 1000).
|
||||||
|
|
||||||
%% When the number of samples exceeds 1000, it affects the rendering speed of dashboard UI.
|
%% When the number of samples exceeds 1000, it affects the rendering speed of dashboard UI.
|
||||||
%% granularity_adapter is an oversampling of the samples.
|
%% granularity_adapter is an oversampling of the samples.
|
||||||
%% Use more granular data and reduce data density.
|
%% Use more granular data and reduce data density.
|
||||||
|
|
|
@ -91,7 +91,7 @@ parameter_latest() ->
|
||||||
example => 5 * 60,
|
example => 5 * 60,
|
||||||
description => <<"The latest N seconds data. Like 300 for 5 min.">>
|
description => <<"The latest N seconds data. Like 300 for 5 min.">>
|
||||||
},
|
},
|
||||||
{latest, hoconsc:mk(integer(), Info)}.
|
{latest, hoconsc:mk(range(1, inf), Info)}.
|
||||||
|
|
||||||
parameter_node() ->
|
parameter_node() ->
|
||||||
Info = #{
|
Info = #{
|
||||||
|
@ -117,7 +117,7 @@ fields(sampler_current) ->
|
||||||
%% API
|
%% API
|
||||||
|
|
||||||
monitor(get, #{query_string := QS, bindings := Bindings}) ->
|
monitor(get, #{query_string := QS, bindings := Bindings}) ->
|
||||||
Latest = maps:get(<<"latest">>, QS, 1000),
|
Latest = maps:get(<<"latest">>, QS, infinity),
|
||||||
Node = binary_to_atom(maps:get(node, Bindings, <<"all">>)),
|
Node = binary_to_atom(maps:get(node, Bindings, <<"all">>)),
|
||||||
case emqx_dashboard_monitor:samplers(Node, Latest) of
|
case emqx_dashboard_monitor:samplers(Node, Latest) of
|
||||||
{badrpc, {Node, Reason}} ->
|
{badrpc, {Node, Reason}} ->
|
||||||
|
|
|
@ -107,6 +107,10 @@ t_monitor_api_error(_) ->
|
||||||
request(["monitor", "nodes", 'emqx@127.0.0.2']),
|
request(["monitor", "nodes", 'emqx@127.0.0.2']),
|
||||||
{error, {400, #{<<"code">> := <<"BAD_RPC">>}}} =
|
{error, {400, #{<<"code">> := <<"BAD_RPC">>}}} =
|
||||||
request(["monitor_current", "nodes", 'emqx@127.0.0.2']),
|
request(["monitor_current", "nodes", 'emqx@127.0.0.2']),
|
||||||
|
{error, {400, #{<<"code">> := <<"BAD_REQUEST">>}}} =
|
||||||
|
request(["monitor"], "latest=0"),
|
||||||
|
{error, {400, #{<<"code">> := <<"BAD_REQUEST">>}}} =
|
||||||
|
request(["monitor"], "latest=-1"),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
request(Path) ->
|
request(Path) ->
|
||||||
|
|
Loading…
Reference in New Issue