feat(dashboard): endpoint `/monitor_current` provides mor fields

- `retained_msg_count`
  Current retained_msg_count on each node and should be same on all nodes.

- `license_quota`
  Only for enterprise edition, provides the max limited connections num.
This commit is contained in:
JimMoen 2024-01-11 16:25:54 +08:00
parent a40a13b786
commit a35698009c
No known key found for this signature in database
3 changed files with 39 additions and 3 deletions

View File

@ -173,7 +173,9 @@ handle_call(current_rate, _From, State = #state{last = Last}) ->
NowTime = erlang:system_time(millisecond), NowTime = erlang:system_time(millisecond),
NowSamplers = sample(NowTime), NowSamplers = sample(NowTime),
Rate = cal_rate(NowSamplers, Last), Rate = cal_rate(NowSamplers, Last),
{reply, {ok, Rate}, State}; NonRateValue = non_rate_value(),
Samples = maps:merge(Rate, NonRateValue),
{reply, {ok, Samples}, State};
handle_call(_Request, _From, State = #state{}) -> handle_call(_Request, _From, State = #state{}) ->
{reply, ok, State}. {reply, ok, State}.
@ -409,3 +411,21 @@ stats(received_bytes) -> emqx_metrics:val('bytes.received');
stats(sent) -> emqx_metrics:val('messages.sent'); stats(sent) -> emqx_metrics:val('messages.sent');
stats(sent_bytes) -> emqx_metrics:val('bytes.sent'); stats(sent_bytes) -> emqx_metrics:val('bytes.sent');
stats(dropped) -> emqx_metrics:val('messages.dropped'). stats(dropped) -> emqx_metrics:val('messages.dropped').
%% -------------------------------------------------------------------------------------------------
%% Retained && License Quota
%% the non rate values should be same on all nodes
non_rate_value() ->
#{
retained_msg_count => emqx_retainer:retained_count(),
license_quota => license_quota()
}.
license_quota() ->
case emqx_license_checker:limits() of
{ok, #{max_connections := Quota}} ->
Quota;
{error, no_license} ->
0
end.

View File

@ -1,5 +1,17 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2019-2023 EMQ Technologies Co., Ltd. All Rights Reserved. %% Copyright (c) 2020-2024 EMQ Technologies Co., Ltd. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-module(emqx_dashboard_monitor_api). -module(emqx_dashboard_monitor_api).

View File

@ -44,7 +44,11 @@ api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}). emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).
paths() -> paths() ->
[?PREFIX, ?PREFIX ++ "/messages", ?PREFIX ++ "/message/:topic"]. [
?PREFIX,
?PREFIX ++ "/messages",
?PREFIX ++ "/message/:topic"
].
schema(?PREFIX) -> schema(?PREFIX) ->
#{ #{