RPC uptime (#1616)
* Add RPC uptime * Change to seconds only, monotonic * Use steady_clock
This commit is contained in:
parent
228fba35ea
commit
54c872c535
5 changed files with 32 additions and 1 deletions
|
@ -4135,3 +4135,21 @@ TEST (rpc, node_id_delete)
|
|||
nano::keypair node_id (system.nodes[0]->store.get_node_id (transaction));
|
||||
ASSERT_NE (node_id.pub.to_string (), system.nodes[0]->node_id.pub.to_string ());
|
||||
}
|
||||
|
||||
TEST (rpc, uptime)
|
||||
{
|
||||
nano::system system (24000, 1);
|
||||
nano::rpc rpc (system.io_ctx, *system.nodes[0], nano::rpc_config (true));
|
||||
rpc.start ();
|
||||
boost::property_tree::ptree request;
|
||||
request.put ("action", "uptime");
|
||||
std::this_thread::sleep_for (std::chrono::seconds (1));
|
||||
test_response response (request, rpc, system.io_ctx);
|
||||
system.deadline_set (5s);
|
||||
while (response.status == 0)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_EQ (200, response.status);
|
||||
ASSERT_LE (1, response.json.get<int> ("seconds"));
|
||||
}
|
||||
|
|
|
@ -1648,7 +1648,8 @@ block_processor_thread ([this]() {
|
|||
}),
|
||||
online_reps (*this),
|
||||
stats (config.stat_config),
|
||||
vote_uniquer (block_uniquer)
|
||||
vote_uniquer (block_uniquer),
|
||||
startup_time (std::chrono::steady_clock::now ())
|
||||
{
|
||||
wallets.observer = [this](bool active) {
|
||||
observers.wallet.notify (active);
|
||||
|
|
|
@ -534,6 +534,7 @@ public:
|
|||
nano::keypair node_id;
|
||||
nano::block_uniquer block_uniquer;
|
||||
nano::vote_uniquer vote_uniquer;
|
||||
const std::chrono::steady_clock::time_point startup_time;
|
||||
static double constexpr price_max = 16.0;
|
||||
static double constexpr free_cutoff = 1024.0;
|
||||
static std::chrono::seconds constexpr period = std::chrono::seconds (60);
|
||||
|
|
|
@ -3083,6 +3083,12 @@ void nano::rpc_handler::unchecked_keys ()
|
|||
response_errors ();
|
||||
}
|
||||
|
||||
void nano::rpc_handler::uptime ()
|
||||
{
|
||||
response_l.put ("seconds", std::chrono::duration_cast<std::chrono::seconds> (std::chrono::steady_clock::now () - node.startup_time).count ());
|
||||
response_errors ();
|
||||
}
|
||||
|
||||
void nano::rpc_handler::version ()
|
||||
{
|
||||
response_l.put ("rpc_version", "1");
|
||||
|
@ -4265,6 +4271,10 @@ void nano::rpc_handler::process_request ()
|
|||
{
|
||||
unchecked_keys ();
|
||||
}
|
||||
else if (action == "uptime")
|
||||
{
|
||||
uptime ();
|
||||
}
|
||||
else if (action == "validate_account_number")
|
||||
{
|
||||
validate_account_number ();
|
||||
|
|
|
@ -195,6 +195,7 @@ public:
|
|||
void unchecked_clear ();
|
||||
void unchecked_get ();
|
||||
void unchecked_keys ();
|
||||
void uptime ();
|
||||
void validate_account_number ();
|
||||
void version ();
|
||||
void wallet_add ();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue