Просмотр исходного кода

Merge pull request #12464 from ieQu1/dev/feat-ds-cli

feat(ds): Add a CLI interface to inspect status of DS databases
ieQu1 2 лет назад
Родитель
Сommit
e0b5d9fae7

+ 13 - 4
apps/emqx_durable_storage/src/emqx_ds_replication_layer_meta.erl

@@ -127,15 +127,24 @@ print_status() ->
         end,
         eval_qlc(mnesia:table(?NODE_TAB))
     ),
-    io:format("~nSHARDS~n", []),
+    io:format(
+        "~nSHARDS:~nId                             Leader                            Status~n", []
+    ),
     lists:foreach(
         fun(#?SHARD_TAB{shard = {DB, Shard}, leader = Leader}) ->
+            ShardStr = string:pad(io_lib:format("~p/~s", [DB, Shard]), 30),
+            LeaderStr = string:pad(atom_to_list(Leader), 33),
             Status =
                 case lists:member(Leader, Nodes) of
-                    true -> up;
-                    false -> down
+                    true ->
+                        case node() of
+                            Leader -> "up *";
+                            _ -> "up"
+                        end;
+                    false ->
+                        "down"
                 end,
-            io:format("~p/~s    ~p    ~p~n", [DB, Shard, Leader, Status])
+            io:format("~s ~s ~s~n", [ShardStr, LeaderStr, Status])
         end,
         eval_qlc(mnesia:table(?SHARD_TAB))
     ).

+ 21 - 2
apps/emqx_management/src/emqx_mgmt_cli.erl

@@ -1,5 +1,5 @@
 %%--------------------------------------------------------------------
-%% Copyright (c) 2020-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.
@@ -43,7 +43,8 @@
     authz/1,
     pem_cache/1,
     olp/1,
-    data/1
+    data/1,
+    ds/1
 ]).
 
 -spec load() -> ok.
@@ -796,6 +797,24 @@ data(_) ->
         {"data export", "Export data"}
     ]).
 
+%%--------------------------------------------------------------------
+%% @doc Durable storage command
+
+ds(CMD) ->
+    case emqx_persistent_message:is_persistence_enabled() of
+        true ->
+            do_ds(CMD);
+        false ->
+            emqx_ctl:usage([{"ds", "Durable storage is disabled"}])
+    end.
+
+do_ds(["info"]) ->
+    emqx_ds_replication_layer_meta:print_status();
+do_ds(_) ->
+    emqx_ctl:usage([
+        {"ds info", "Show overview of the embedded durable storage state"}
+    ]).
+
 %%--------------------------------------------------------------------
 %% Dump ETS
 %%--------------------------------------------------------------------