fix: dashboard monitor bpapi
This commit is contained in:
parent
00b83121a4
commit
103df6f06b
|
@ -42,9 +42,11 @@
|
|||
-ifdef(TEST).
|
||||
%% for test
|
||||
-define(DEFAULT_SAMPLE_INTERVAL, 1).
|
||||
-define(RPC_TIMEOUT, 50).
|
||||
-else.
|
||||
%% dashboard monitor do sample interval, default 10s
|
||||
-define(DEFAULT_SAMPLE_INTERVAL, 10).
|
||||
-define(RPC_TIMEOUT, 5000).
|
||||
-endif.
|
||||
|
||||
-define(DELTA_SAMPLER_LIST,
|
||||
|
|
|
@ -51,12 +51,6 @@
|
|||
%% 7 days = 7 * 24 * 60 * 60 * 1000 milliseconds
|
||||
-define(RETENTION_TIME, 7 * 24 * 60 * 60 * 1000).
|
||||
|
||||
-ifdef(TEST).
|
||||
-define(RPC_TIMEOUT, 50).
|
||||
-else.
|
||||
-define(RPC_TIMEOUT, 5000).
|
||||
-endif.
|
||||
|
||||
-record(state, {
|
||||
last
|
||||
}).
|
||||
|
@ -140,7 +134,7 @@ current_rate(all) ->
|
|||
current_rate(Node) when Node == node() ->
|
||||
do_call(current_rate);
|
||||
current_rate(Node) ->
|
||||
case rpc:call(Node, ?MODULE, ?FUNCTION_NAME, [Node], ?RPC_TIMEOUT) of
|
||||
case emqx_dashboard_proto_v1:current_rate(Node) of
|
||||
{badrpc, Reason} ->
|
||||
{badrpc, {Node, Reason}};
|
||||
{ok, Rate} ->
|
||||
|
@ -201,7 +195,7 @@ do_sample(Node, Time) when Node == node() ->
|
|||
MS = match_spec(Time),
|
||||
internal_format(ets:select(?TAB, MS));
|
||||
do_sample(Node, Time) ->
|
||||
case rpc:call(Node, ?MODULE, ?FUNCTION_NAME, [Node, Time], ?RPC_TIMEOUT) of
|
||||
case emqx_dashboard_proto_v1:do_sample(Node, Time) of
|
||||
{badrpc, Reason} ->
|
||||
{badrpc, {Node, Reason}};
|
||||
Res ->
|
||||
|
|
|
@ -78,7 +78,8 @@ schema("/monitor_current/nodes/:node") ->
|
|||
description => <<"Node current status. Gauge and rate.">>,
|
||||
parameters => [parameter_node()],
|
||||
responses => #{
|
||||
200 => hoconsc:mk(hoconsc:ref(sampler_current), #{})
|
||||
200 => hoconsc:mk(hoconsc:ref(sampler_current), #{}),
|
||||
400 => emqx_dashboard_swagger:error_codes(['BAD_RPC'], <<"Bad RPC">>)
|
||||
}
|
||||
}
|
||||
}.
|
||||
|
@ -86,7 +87,7 @@ schema("/monitor_current/nodes/:node") ->
|
|||
parameter_latest() ->
|
||||
Info = #{
|
||||
in => query,
|
||||
nullable => true,
|
||||
required => false,
|
||||
example => 5 * 60,
|
||||
description => <<"The latest N seconds data. Like 300 for 5 min.">>
|
||||
},
|
||||
|
@ -95,7 +96,7 @@ parameter_latest() ->
|
|||
parameter_node() ->
|
||||
Info = #{
|
||||
in => path,
|
||||
nullable => false,
|
||||
required => true,
|
||||
example => node(),
|
||||
description => <<"EMQX node name.">>
|
||||
},
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
-behaviour(emqx_bpapi).
|
||||
|
||||
-export([ introduced_in/0
|
||||
, samplers/2
|
||||
, do_sample/2
|
||||
, current_rate/1
|
||||
]).
|
||||
|
||||
-include("emqx_dashboard.hrl").
|
||||
|
@ -28,6 +29,10 @@
|
|||
introduced_in() ->
|
||||
"5.0.0".
|
||||
|
||||
-spec samplers(node(), Latest:: pos_integer() | infinity) -> list(map()) | emqx_rpc:badrpc().
|
||||
samplers(Node, Latest) ->
|
||||
rpc:call(Node, emqx_dashboard_monitor, samplers, [Node, Latest]).
|
||||
-spec do_sample(node(), Latest:: pos_integer() | infinity) -> list(map()) | emqx_rpc:badrpc().
|
||||
do_sample(Node, Latest) ->
|
||||
rpc:call(Node, emqx_dashboard_monitor, do_sample, [Node, Latest], ?RPC_TIMEOUT).
|
||||
|
||||
-spec current_rate(node()) -> {ok, map()} | emqx_rpc:badrpc().
|
||||
current_rate(Node) ->
|
||||
rpc:call(Node, emqx_dashboard_monitor, current_rate, [Node], ?RPC_TIMEOUT).
|
||||
|
|
|
@ -131,8 +131,10 @@ do_request_api(Method, Request)->
|
|||
{error, socket_closed_remotely};
|
||||
{ok, {{"HTTP/1.1", Code, _}, _, Return} }
|
||||
when Code >= 200 andalso Code =< 299 ->
|
||||
ct:pal("Resp ~p ~p~n", [Code, Return]),
|
||||
{ok, emqx_json:decode(Return, [return_maps])};
|
||||
{ok, {{"HTTP/1.1", Code, _}, _, Return} } ->
|
||||
ct:pal("Resp ~p ~p~n", [Code, Return]),
|
||||
{error, {Code, emqx_json:decode(Return, [return_maps])}};
|
||||
{error, Reason} ->
|
||||
{error, Reason}
|
||||
|
|
Loading…
Reference in New Issue