Skip to content

Commit

Permalink
Add counters for tcp connect, read, write errors
Browse files Browse the repository at this point in the history
It seems like a good idea to have counters counting how many tcp errors
we get for tcp read, write and connect.
  • Loading branch information
dsiganos committed Jan 31, 2022
1 parent 44df506 commit 1cf9d35
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
9 changes: 9 additions & 0 deletions nano/lib/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,15 @@ std::string nano::stat::detail_to_string (uint32_t key)
case nano::stat::detail::tcp_io_timeout_drop:
res = "tcp_io_timeout_drop";
break;
case nano::stat::detail::tcp_connect_error:
res = "tcp_connect_error";
break;
case nano::stat::detail::tcp_read_error:
res = "tcp_read_error";
break;
case nano::stat::detail::tcp_write_error:
res = "tcp_write_error";
break;
case nano::stat::detail::unreachable_host:
res = "unreachable_host";
break;
Expand Down
3 changes: 3 additions & 0 deletions nano/lib/stats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ class stat final
tcp_max_per_subnetwork,
tcp_silent_connection_drop,
tcp_io_timeout_drop,
tcp_connect_error,
tcp_read_error,
tcp_write_error,

// ipc
invocations,
Expand Down
18 changes: 15 additions & 3 deletions nano/node/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ void nano::socket::async_connect (nano::tcp_endpoint const & endpoint_a, std::fu
this_l->tcp_socket.async_connect (endpoint_a,
boost::asio::bind_executor (this_l->strand,
[this_l, callback = std::move (callback_a), endpoint_a] (boost::system::error_code const & ec) {
if (!ec)
if (ec)
{
this_l->node.stats.inc (nano::stat::type::tcp, nano::stat::detail::tcp_connect_error, nano::stat::dir::in);
}
else
{
this_l->stop_timer ();
}
Expand All @@ -83,7 +87,11 @@ void nano::socket::async_read (std::shared_ptr<std::vector<uint8_t>> const & buf
boost::asio::async_read (this_l->tcp_socket, boost::asio::buffer (buffer_a->data (), size_a),
boost::asio::bind_executor (this_l->strand,
[this_l, buffer_a, cbk = std::move (callback)] (boost::system::error_code const & ec, std::size_t size_a) {
if (!ec)
if (ec)
{
this_l->node.stats.inc (nano::stat::type::tcp, nano::stat::detail::tcp_read_error, nano::stat::dir::in);
}
else
{
this_l->node.stats.add (nano::stat::type::traffic_tcp, nano::stat::dir::in, size_a);
this_l->stop_timer ();
Expand Down Expand Up @@ -115,7 +123,11 @@ void nano::socket::async_write (nano::shared_const_buffer const & buffer_a, std:
boost::asio::bind_executor (this_l->strand,
[buffer_a, cbk = std::move (callback), this_l] (boost::system::error_code ec, std::size_t size_a) {
--this_l->queue_size;
if (!ec)
if (ec)
{
this_l->node.stats.inc (nano::stat::type::tcp, nano::stat::detail::tcp_write_error, nano::stat::dir::in);
}
else
{
this_l->node.stats.add (nano::stat::type::traffic_tcp, nano::stat::dir::out, size_a);
this_l->stop_timer ();
Expand Down

0 comments on commit 1cf9d35

Please sign in to comment.