From af3be67aeea50a8524f40d6483e58659e197291d Mon Sep 17 00:00:00 2001 From: cheniujh <41671101+cheniujh@users.noreply.github.com> Date: Fri, 17 May 2024 19:28:54 +0800 Subject: [PATCH] add repl metric "repl_connect_status" in the resp of info command (#2656) Co-authored-by: cjh <1271435567@qq.com> --- src/pika_admin.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/pika_admin.cc b/src/pika_admin.cc index 34a1a4d4f7..4223e76cc9 100644 --- a/src/pika_admin.cc +++ b/src/pika_admin.cc @@ -1080,7 +1080,7 @@ void InfoCmd::InfoReplication(std::string& info) { int host_role = g_pika_server->role(); std::stringstream tmp_stream; std::stringstream out_of_sync; - + std::stringstream repl_connect_status; bool all_db_sync = true; std::shared_lock db_rwl(g_pika_server->dbs_rw_); for (const auto& db_item : g_pika_server->GetDB()) { @@ -1090,27 +1090,39 @@ void InfoCmd::InfoReplication(std::string& info) { out_of_sync << "(" << db_item.first << ": InternalError)"; continue; } + repl_connect_status << db_item.first << ":"; if (slave_db->State() != ReplState::kConnected) { all_db_sync = false; out_of_sync << "(" << db_item.first << ":"; if (slave_db->State() == ReplState::kNoConnect) { out_of_sync << "NoConnect)"; + repl_connect_status << "no_connect"; } else if (slave_db->State() == ReplState::kWaitDBSync) { out_of_sync << "WaitDBSync)"; + repl_connect_status << "syncing_full"; } else if (slave_db->State() == ReplState::kError) { out_of_sync << "Error)"; + repl_connect_status << "error"; } else if (slave_db->State() == ReplState::kWaitReply) { out_of_sync << "kWaitReply)"; + repl_connect_status << "connecting"; } else if (slave_db->State() == ReplState::kTryConnect) { out_of_sync << "kTryConnect)"; + repl_connect_status << "try_to_incr_sync"; } else if (slave_db->State() == ReplState::kTryDBSync) { out_of_sync << "kTryDBSync)"; + repl_connect_status << "try_to_full_sync"; } else if (slave_db->State() == ReplState::kDBNoConnect) { out_of_sync << "kDBNoConnect)"; + repl_connect_status << "no_connect"; } else { out_of_sync << "Other)"; + repl_connect_status << "error"; } + } else { //slave_db->State() equal to kConnected + repl_connect_status << "connected"; } + repl_connect_status << "\r\n"; } tmp_stream << "# Replication("; @@ -1138,6 +1150,7 @@ void InfoCmd::InfoReplication(std::string& info) { tmp_stream << "master_link_status:" << (((g_pika_server->repl_state() == PIKA_REPL_META_SYNC_DONE) && all_db_sync) ? "up" : "down") << "\r\n"; + tmp_stream << "repl_connect_status:\r\n" << repl_connect_status.str(); tmp_stream << "slave_priority:" << g_pika_conf->slave_priority() << "\r\n"; tmp_stream << "slave_read_only:" << g_pika_conf->slave_read_only() << "\r\n"; if (!all_db_sync) { @@ -1150,6 +1163,7 @@ void InfoCmd::InfoReplication(std::string& info) { tmp_stream << "master_link_status:" << (((g_pika_server->repl_state() == PIKA_REPL_META_SYNC_DONE) && all_db_sync) ? "up" : "down") << "\r\n"; + tmp_stream << "repl_connect_status:\r\n" << repl_connect_status.str(); tmp_stream << "slave_read_only:" << g_pika_conf->slave_read_only() << "\r\n"; if (!all_db_sync) { tmp_stream << "db_repl_state:" << out_of_sync.str() << "\r\n";