diff options
author | João Barbosa <joao.paulo.barbosa@gmail.com> | 2018-12-14 15:53:59 +0000 |
---|---|---|
committer | João Barbosa <joao.paulo.barbosa@gmail.com> | 2019-01-02 12:47:32 +0000 |
commit | d0730f5ce475e5a84da7c61fe79bcd6ed24d693e (patch) | |
tree | f9cf2c8609beb214f7886eda3ae39c56efc601ee /src/rpc/server.cpp | |
parent | 068a8fc05f8dbec198bdc3fe46f955d8a5255303 (diff) |
rpc: Add getrpcinfo command
Diffstat (limited to 'src/rpc/server.cpp')
-rw-r--r-- | src/rpc/server.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 926fabe6af..9f03c1e134 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -283,11 +283,37 @@ static UniValue uptime(const JSONRPCRequest& jsonRequest) return GetTime() - GetStartupTime(); } +static UniValue getrpcinfo(const JSONRPCRequest& request) +{ + if (request.fHelp || request.params.size() > 0) { + throw std::runtime_error( + RPCHelpMan{"getrpcinfo", + "\nReturns details of the RPC server.\n", {}} + .ToString() + ); + } + + LOCK(g_rpc_server_info.mutex); + UniValue active_commands(UniValue::VARR); + for (const RPCCommandExecutionInfo& info : g_rpc_server_info.active_commands) { + UniValue entry(UniValue::VOBJ); + entry.pushKV("method", info.method); + entry.pushKV("duration", GetTimeMicros() - info.start); + active_commands.push_back(entry); + } + + UniValue result(UniValue::VOBJ); + result.pushKV("active_commands", active_commands); + + return result; +} + // clang-format off static const CRPCCommand vRPCCommands[] = { // category name actor (function) argNames // --------------------- ------------------------ ----------------------- ---------- /* Overall control/query calls */ + { "control", "getrpcinfo", &getrpcinfo, {} }, { "control", "help", &help, {"command"} }, { "control", "stop", &stop, {"wait"} }, { "control", "uptime", &uptime, {} }, |