[RPC] Add an uptime command that displays the amount of time that bitcoind has been running

This commit is contained in:
Ricardo Velhote
2017-05-14 19:18:26 +01:00
committed by lateminer
parent 5a5d74b07c
commit 32f0591954
6 changed files with 64 additions and 3 deletions

View File

@@ -24,7 +24,6 @@
class CBlockIndex;
static const int64_t nClientStartupTime = GetTime();
static int64_t nLastHeaderTipUpdateNotification = 0;
static int64_t nLastBlockTipUpdateNotification = 0;
@@ -182,7 +181,7 @@ bool ClientModel::isReleaseVersion() const
QString ClientModel::formatClientStartupTime() const
{
return QDateTime::fromTime_t(nClientStartupTime).toString();
return QDateTime::fromTime_t(GetStartupTime()).toString();
}
QString ClientModel::dataDir() const

View File

@@ -273,6 +273,22 @@ UniValue stop(const UniValue& params, bool fHelp)
return "Blackcoin server stopping";
}
UniValue uptime(const JSONRPCRequest& jsonRequest)
{
if (jsonRequest.fHelp || jsonRequest.params.size() > 1)
throw std::runtime_error(
"uptime\n"
"\nReturns the total uptime of the server.\n"
"\nResult:\n"
"ttt (numeric) The number of seconds that the server has been running\n"
"\nExamples:\n"
+ HelpExampleCli("uptime", "")
+ HelpExampleRpc("uptime", "")
);
return GetTime() - GetStartupTime();
}
/**
* Call Table
*/
@@ -282,6 +298,7 @@ static const CRPCCommand vRPCCommands[] =
/* Overall control/query calls */
{ "control", "help", &help, true },
{ "control", "stop", &stop, true },
{ "control", "uptime", &uptime, true, },
};
CRPCTable::CRPCTable()

View File

@@ -97,6 +97,9 @@ namespace boost {
} // namespace boost
// Application startup time (used for uptime calculation)
const int64_t nStartupTime = GetTime();
using namespace std;
const char * const BITCOIN_CONF_FILENAME = "blackmore.conf";
@@ -836,3 +839,9 @@ int GetNumCores()
#endif
}
// Obtain the application startup time (used for uptime calculation)
int64_t GetStartupTime()
{
return nStartupTime;
}

View File

@@ -5,7 +5,7 @@
/**
* Server/client environment: argument handling, config file parsing,
* logging, thread wrappers
* logging, thread wrappers, startup time
*/
#ifndef BITCOIN_UTIL_H
#define BITCOIN_UTIL_H
@@ -28,6 +28,9 @@
#include <boost/signals2/signal.hpp>
#include <boost/thread/exceptions.hpp>
// Application startup time (used for uptime calculation)
int64_t GetStartupTime();
static const bool DEFAULT_LOGTIMEMICROS = false;
static const bool DEFAULT_LOGIPS = false;
static const bool DEFAULT_LOGTIMESTAMPS = true;