-
Notifications
You must be signed in to change notification settings - Fork 786
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log node status periodically (#4676)
* Fix alignment * Log node status periodically * Log detailed peer and connections info * Logging consistency
- Loading branch information
1 parent
fd023dc
commit bc9bc82
Showing
15 changed files
with
250 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,7 @@ enum class name | |
port_mapping, | ||
stats, | ||
vote_router, | ||
monitor, | ||
}; | ||
|
||
std::string_view to_string (name); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
#include "nano/secure/ledger.hpp" | ||
|
||
#include <nano/lib/thread_roles.hpp> | ||
#include <nano/lib/utility.hpp> | ||
#include <nano/node/monitor.hpp> | ||
#include <nano/node/node.hpp> | ||
|
||
nano::monitor::monitor (nano::monitor_config const & config_a, nano::node & node_a) : | ||
config{ config_a }, | ||
node{ node_a }, | ||
logger{ node_a.logger } | ||
{ | ||
} | ||
|
||
nano::monitor::~monitor () | ||
{ | ||
debug_assert (!thread.joinable ()); | ||
} | ||
|
||
void nano::monitor::start () | ||
{ | ||
if (!config.enabled) | ||
{ | ||
return; | ||
} | ||
|
||
thread = std::thread ([this] () { | ||
nano::thread_role::set (nano::thread_role::name::monitor); | ||
run (); | ||
}); | ||
} | ||
|
||
void nano::monitor::stop () | ||
{ | ||
{ | ||
nano::lock_guard<nano::mutex> guard{ mutex }; | ||
stopped = true; | ||
} | ||
condition.notify_all (); | ||
if (thread.joinable ()) | ||
{ | ||
thread.join (); | ||
} | ||
} | ||
|
||
void nano::monitor::run () | ||
{ | ||
std::unique_lock<nano::mutex> lock{ mutex }; | ||
while (!stopped) | ||
{ | ||
run_one (); | ||
condition.wait_until (lock, std::chrono::steady_clock::now () + config.interval, [this] { return stopped; }); | ||
} | ||
} | ||
|
||
void nano::monitor::run_one () | ||
{ | ||
// Node status: | ||
// - blocks (confirmed, total) | ||
// - blocks rate (over last 5m, peak over last 5m) | ||
// - peers | ||
// - stake (online, peered, trended, quorum needed) | ||
// - elections active (normal, hinted, optimistic) | ||
// - election stats over last 5m (confirmed, dropped) | ||
|
||
auto const now = std::chrono::steady_clock::now (); | ||
auto blocks_cemented = node.ledger.cemented_count (); | ||
auto blocks_total = node.ledger.block_count (); | ||
|
||
// Wait for node to warm up before logging | ||
if (last_time != std::chrono::steady_clock::time_point{}) | ||
{ | ||
// TODO: Maybe emphasize somehow that confirmed doesn't need to be equal to total; backlog is OK | ||
logger.info (nano::log::type::monitor, "Blocks confirmed: {} | total: {}", | ||
blocks_cemented, | ||
blocks_total); | ||
|
||
// Calculate the rates | ||
auto elapsed_seconds = std::chrono::duration_cast<std::chrono::seconds> (now - last_time).count (); | ||
auto blocks_confirmed_rate = static_cast<double> (blocks_cemented - last_blocks_cemented) / elapsed_seconds; | ||
auto blocks_checked_rate = static_cast<double> (blocks_total - last_blocks_total) / elapsed_seconds; | ||
|
||
logger.info (nano::log::type::monitor, "Blocks rate (average over last {}s): confirmed {:.2f}/s | total {:.2f}/s", | ||
elapsed_seconds, | ||
blocks_confirmed_rate, | ||
blocks_checked_rate); | ||
|
||
logger.info (nano::log::type::monitor, "Peers: {} (realtime: {} | bootstrap: {} | inbound connections: {} | outbound connections: {})", | ||
node.network.size (), | ||
node.tcp_listener.realtime_count (), | ||
node.tcp_listener.bootstrap_count (), | ||
node.tcp_listener.connection_count (nano::transport::tcp_listener::connection_type::inbound), | ||
node.tcp_listener.connection_count (nano::transport::tcp_listener::connection_type::outbound)); | ||
|
||
logger.info (nano::log::type::monitor, "Quorum: {} (stake peered: {} | stake online: {})", | ||
nano::uint128_union{ node.online_reps.delta () }.format_balance (Mxrb_ratio, 1, true), | ||
nano::uint128_union{ node.rep_crawler.total_weight () }.format_balance (Mxrb_ratio, 1, true), | ||
nano::uint128_union{ node.online_reps.online () }.format_balance (Mxrb_ratio, 1, true)); | ||
|
||
logger.info (nano::log::type::monitor, "Elections active: {} (priority: {} | hinted: {} | optimistic: {})", | ||
node.active.size (), | ||
node.active.size (nano::election_behavior::priority), | ||
node.active.size (nano::election_behavior::hinted), | ||
node.active.size (nano::election_behavior::optimistic)); | ||
} | ||
|
||
last_time = now; | ||
last_blocks_cemented = blocks_cemented; | ||
last_blocks_total = blocks_total; | ||
} | ||
|
||
/* | ||
* monitor_config | ||
*/ | ||
|
||
nano::error nano::monitor_config::serialize (nano::tomlconfig & toml) const | ||
{ | ||
toml.put ("enable", enabled, "Enable or disable periodic node status logging\ntype:bool"); | ||
toml.put ("interval", interval.count (), "Interval between status logs\ntype:seconds"); | ||
|
||
return toml.get_error (); | ||
} | ||
|
||
nano::error nano::monitor_config::deserialize (nano::tomlconfig & toml) | ||
{ | ||
toml.get ("enabled", enabled); | ||
auto interval_l = interval.count (); | ||
toml.get ("interval", interval_l); | ||
interval = std::chrono::seconds{ interval_l }; | ||
|
||
return toml.get_error (); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#pragma once | ||
|
||
#include <nano/lib/locks.hpp> | ||
#include <nano/node/fwd.hpp> | ||
|
||
#include <chrono> | ||
#include <thread> | ||
|
||
using namespace std::chrono_literals; | ||
|
||
namespace nano | ||
{ | ||
class monitor_config final | ||
{ | ||
public: | ||
nano::error deserialize (nano::tomlconfig &); | ||
nano::error serialize (nano::tomlconfig &) const; | ||
|
||
public: | ||
bool enabled{ true }; | ||
std::chrono::seconds interval{ 60s }; | ||
}; | ||
|
||
class monitor final | ||
{ | ||
public: | ||
monitor (monitor_config const &, nano::node &); | ||
~monitor (); | ||
|
||
void start (); | ||
void stop (); | ||
|
||
private: // Dependencies | ||
monitor_config const & config; | ||
nano::node & node; | ||
nano::logger & logger; | ||
|
||
private: | ||
void run (); | ||
void run_one (); | ||
|
||
std::chrono::steady_clock::time_point last_time{}; | ||
|
||
size_t last_blocks_cemented{ 0 }; | ||
size_t last_blocks_total{ 0 }; | ||
|
||
bool stopped{ false }; | ||
nano::condition_variable condition; | ||
mutable nano::mutex mutex; | ||
std::thread thread; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.