From e7574a70fbb956f5da4dd444784cc2b4084ab5cd Mon Sep 17 00:00:00 2001 From: JimMoen Date: Fri, 8 Mar 2024 18:11:49 +0800 Subject: [PATCH 1/3] feat(api): field `shared_subscriptions` in endpoint `/monitor_current` --- apps/emqx_dashboard/src/emqx_dashboard_monitor.erl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/emqx_dashboard/src/emqx_dashboard_monitor.erl b/apps/emqx_dashboard/src/emqx_dashboard_monitor.erl index f5798708e..cfbec3eb8 100644 --- a/apps/emqx_dashboard/src/emqx_dashboard_monitor.erl +++ b/apps/emqx_dashboard/src/emqx_dashboard_monitor.erl @@ -357,8 +357,8 @@ next_interval() -> sample(Time) -> Fun = - fun(Key, Res) -> - maps:put(Key, getstats(Key), Res) + fun(Key, Acc) -> + Acc#{Key => getstats(Key)} end, Data = lists:foldl(Fun, #{}, ?SAMPLER_LIST), #emqx_monit{time = Time, data = Data}. @@ -416,6 +416,8 @@ stats(live_connections) -> emqx_stats:getstat('live_connections.count'); stats(cluster_sessions) -> emqx_stats:getstat('cluster_sessions.count'); stats(topics) -> emqx_stats:getstat('topics.count'); stats(subscriptions) -> emqx_stats:getstat('subscriptions.count'); +stats(shared_subscriptions) -> emqx_stats:getstat('subscriptions.shared.count'); +stats(retained_msg_count) -> emqx_stats:getstat('retained.count'); stats(received) -> emqx_metrics:val('messages.received'); stats(received_bytes) -> emqx_metrics:val('bytes.received'); stats(sent) -> emqx_metrics:val('messages.sent'); @@ -428,7 +430,8 @@ stats(dropped) -> emqx_metrics:val('messages.dropped'). %% the non rate values should be same on all nodes non_rate_value() -> (license_quota())#{ - retained_msg_count => emqx_retainer:retained_count(), + retained_msg_count => stats(retained_msg_count), + shared_subscriptions => stats(shared_subscriptions), node_uptime => emqx_sys:uptime() }. From a82d4e1f7a468a549e671a1b542bf1635540aaf6 Mon Sep 17 00:00:00 2001 From: JimMoen Date: Fri, 8 Mar 2024 18:12:32 +0800 Subject: [PATCH 2/3] fix: `retained_msg_count` and `shared_subscriptions` api schema --- .../emqx_dashboard/include/emqx_dashboard.hrl | 14 ++++++ .../src/emqx_dashboard_monitor_api.erl | 49 +++++++++++-------- 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/apps/emqx_dashboard/include/emqx_dashboard.hrl b/apps/emqx_dashboard/include/emqx_dashboard.hrl index 683df6f3d..547ecca6b 100644 --- a/apps/emqx_dashboard/include/emqx_dashboard.hrl +++ b/apps/emqx_dashboard/include/emqx_dashboard.hrl @@ -85,3 +85,17 @@ sent => sent_msg_rate, dropped => dropped_msg_rate }). + +-define(CURRENT_SAMPLE_NON_RATE, + [ + node_uptime, + retained_msg_count, + shared_subscriptions + ] ++ ?LICENSE_QUOTA +). + +-if(?EMQX_RELEASE_EDITION == ee). +-define(LICENSE_QUOTA, [license_quota]). +-else. +-define(LICENSE_QUOTA, []). +-endif. diff --git a/apps/emqx_dashboard/src/emqx_dashboard_monitor_api.erl b/apps/emqx_dashboard/src/emqx_dashboard_monitor_api.erl index 97397056d..7dc1e919e 100644 --- a/apps/emqx_dashboard/src/emqx_dashboard_monitor_api.erl +++ b/apps/emqx_dashboard/src/emqx_dashboard_monitor_api.erl @@ -94,7 +94,7 @@ schema("/monitor_current/nodes/:node") -> description => ?DESC(current_stats_node), parameters => [parameter_node()], responses => #{ - 200 => hoconsc:mk(hoconsc:ref(sampler_current), #{}), + 200 => hoconsc:mk(hoconsc:ref(sampler_current_node), #{}), 404 => emqx_dashboard_swagger:error_codes(['NOT_FOUND'], <<"Node not found">>) } } @@ -125,8 +125,17 @@ fields(sampler) -> || SamplerName <- ?SAMPLER_LIST ], [{time_stamp, hoconsc:mk(non_neg_integer(), #{desc => <<"Timestamp">>})} | Samplers]; +fields(sampler_current_node) -> + fields_current(sample_names(sampler_current_node)); fields(sampler_current) -> - Names = maps:values(?DELTA_SAMPLER_RATE_MAP) ++ ?GAUGE_SAMPLER_LIST, + fields_current(sample_names(sampler_current)). + +sample_names(sampler_current_node) -> + maps:values(?DELTA_SAMPLER_RATE_MAP) ++ ?GAUGE_SAMPLER_LIST ++ ?CURRENT_SAMPLE_NON_RATE; +sample_names(sampler_current) -> + sample_names(sampler_current_node) -- [node_uptime]. + +fields_current(Names) -> [ {SamplerName, hoconsc:mk(integer(), #{desc => swagger_desc(SamplerName)})} || SamplerName <- Names @@ -167,6 +176,8 @@ current_rate(Node) -> %% ------------------------------------------------------------------------------------------------- %% Internal +-define(APPROXIMATE_DESC, " Can only represent an approximate state."). + swagger_desc(received) -> swagger_desc_format("Received messages "); swagger_desc(received_bytes) -> @@ -178,30 +189,18 @@ swagger_desc(sent_bytes) -> swagger_desc(dropped) -> swagger_desc_format("Dropped messages "); swagger_desc(subscriptions) -> - << - "Subscriptions at the time of sampling." - " Can only represent the approximate state" - >>; + <<"Subscriptions at the time of sampling.", ?APPROXIMATE_DESC>>; swagger_desc(topics) -> - << - "Count topics at the time of sampling." - " Can only represent the approximate state" - >>; + <<"Count topics at the time of sampling.", ?APPROXIMATE_DESC>>; swagger_desc(connections) -> - << - "Sessions at the time of sampling." - " Can only represent the approximate state" - >>; + <<"Sessions at the time of sampling.", ?APPROXIMATE_DESC>>; swagger_desc(live_connections) -> - << - "Connections at the time of sampling." - " Can only represent the approximate state" - >>; + <<"Connections at the time of sampling.", ?APPROXIMATE_DESC>>; swagger_desc(cluster_sessions) -> << "Total number of sessions in the cluster at the time of sampling. " - "It includes expired sessions when `broker.session_history_retain` is set to a duration greater than `0s`. " - "Can only represent the approximate state" + "It includes expired sessions when `broker.session_history_retain` is set to a duration greater than `0s`." + ?APPROXIMATE_DESC >>; swagger_desc(received_msg_rate) -> swagger_desc_format("Dropped messages ", per); @@ -210,7 +209,15 @@ swagger_desc(sent_msg_rate) -> swagger_desc_format("Sent messages ", per); %swagger_desc(sent_bytes_rate) -> swagger_desc_format("Sent bytes ", per); swagger_desc(dropped_msg_rate) -> - swagger_desc_format("Dropped messages ", per). + swagger_desc_format("Dropped messages ", per); +swagger_desc(retained_msg_count) -> + <<"Retained messages count at the time of sampling.", ?APPROXIMATE_DESC>>; +swagger_desc(shared_subscriptions) -> + <<"Shared subscriptions count at the time of sampling.", ?APPROXIMATE_DESC>>; +swagger_desc(node_uptime) -> + <<"Node up time in seconds. Only presented in endpoint: `/monitor_current/nodes/:node`.">>; +swagger_desc(license_quota) -> + <<"License quota. AKA: limited max_connections for cluster">>. swagger_desc_format(Format) -> swagger_desc_format(Format, last). From e5b818e1a26703590fbd100c805739a4176d6741 Mon Sep 17 00:00:00 2001 From: JimMoen Date: Fri, 8 Mar 2024 18:20:27 +0800 Subject: [PATCH 3/3] docs: add changelog for PR 12670 --- changes/ce/feat-12670.en.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/ce/feat-12670.en.md diff --git a/changes/ce/feat-12670.en.md b/changes/ce/feat-12670.en.md new file mode 100644 index 000000000..078e2718d --- /dev/null +++ b/changes/ce/feat-12670.en.md @@ -0,0 +1 @@ +Add field `shared_subscriptions` to endpoint `/monitor_current` and `/monitor_current/nodes/:node`.