Skip to content

Commit

Permalink
Added support for statsD Traffic Counts reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurbhandary authored and manojsdoshi committed Feb 12, 2020
1 parent 172ead8 commit b784988
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/ripple/app/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ bool ApplicationImp::setup()
// if (!config_.standalone())
m_overlay = make_Overlay (*this, setup_Overlay(*config_), *m_jobQueue,
*serverHandler_, *m_resourceManager, *m_resolver, get_io_service(),
*config_);
*config_, m_collectorManager->collector ());
add (*m_overlay); // add to PropertyStream

if (!config_->standalone())
Expand Down
25 changes: 21 additions & 4 deletions src/ripple/overlay/impl/OverlayImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ OverlayImpl::OverlayImpl (
Resource::Manager& resourceManager,
Resolver& resolver,
boost::asio::io_service& io_service,
BasicConfig const& config)
BasicConfig const& config,
beast::insight::Collector::ptr const& collector)
: Overlay (parent)
, app_ (app)
, io_service_ (io_service)
Expand All @@ -155,10 +156,25 @@ OverlayImpl::OverlayImpl (
, serverHandler_(serverHandler)
, m_resourceManager (resourceManager)
, m_peerFinder (PeerFinder::make_Manager (*this, io_service,
stopwatch(), app_.journal("PeerFinder"), config))
stopwatch(), app_.journal("PeerFinder"), config, collector))
, m_resolver (resolver)
, next_id_(1)
, timer_count_(0)
, m_stats (
std::bind(&OverlayImpl::collect_metrics, this),
collector,
[counts = m_traffic.getCounts(), collector]()
{
std::vector<TrafficGauges> ret;
ret.reserve(counts.size());

for (size_t i = 0; i < counts.size(); ++i)
{
ret.push_back(TrafficGauges(counts[i].name, collector));
}

return ret;
}())
{
beast::PropertyStream::Source::add (m_peerFinder.get());
}
Expand Down Expand Up @@ -1353,10 +1369,11 @@ make_Overlay (
Resource::Manager& resourceManager,
Resolver& resolver,
boost::asio::io_service& io_service,
BasicConfig const& config)
BasicConfig const& config,
beast::insight::Collector::ptr const& collector)
{
return std::make_unique<OverlayImpl>(app, setup, parent, serverHandler,
resourceManager, resolver, io_service, config);
resourceManager, resolver, io_service, config, collector);
}

}
58 changes: 57 additions & 1 deletion src/ripple/overlay/impl/OverlayImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class OverlayImpl : public Overlay
OverlayImpl (Application& app, Setup const& setup, Stoppable& parent,
ServerHandler& serverHandler, Resource::Manager& resourceManager,
Resolver& resolver, boost::asio::io_service& io_service,
BasicConfig const& config);
BasicConfig const& config, beast::insight::Collector::ptr const& collector);

~OverlayImpl();

Expand Down Expand Up @@ -458,6 +458,62 @@ class OverlayImpl : public Overlay

void
sendEndpoints();

private:

struct TrafficGauges{
TrafficGauges (char const* name, beast::insight::Collector::ptr const& collector)
: bytesIn(collector->make_gauge(name,"Bytes_In"))
, bytesOut(collector->make_gauge(name,"Bytes_Out"))
, messagesIn(collector->make_gauge(name,"Messages_In"))
, messagesOut(collector->make_gauge(name,"Messages_Out"))
{
}
beast::insight::Gauge bytesIn;
beast::insight::Gauge bytesOut;
beast::insight::Gauge messagesIn;
beast::insight::Gauge messagesOut;
};


struct Stats
{

template <class Handler>
Stats (
Handler const& handler,
beast::insight::Collector::ptr const& collector,
std::vector<TrafficGauges>&& trafficGauges_)
: peerDisconnects (collector->make_gauge("Overlay","Peer_Disconnects"))
, trafficGauges (std::move(trafficGauges_))
, hook (collector->make_hook (handler))
{
}

beast::insight::Gauge peerDisconnects;
std::vector<TrafficGauges> trafficGauges;
beast::insight::Hook hook;
};

Stats m_stats;
std::mutex m_statsMutex;

private:
void collect_metrics()
{
auto counts = m_traffic.getCounts();
std::lock_guard lock (m_statsMutex);
assert(counts.size() == m_stats.trafficGauges.size());

for (std::size_t i = 0; i < counts.size(); ++i)
{
m_stats.trafficGauges[i].bytesIn = counts[i].bytesIn;
m_stats.trafficGauges[i].bytesOut = counts[i].bytesOut;
m_stats.trafficGauges[i].messagesIn = counts[i].messagesIn;
m_stats.trafficGauges[i].messagesOut = counts[i].messagesOut;
}
m_stats.peerDisconnects = getPeerDisconnect();
}
};

} // ripple
Expand Down
91 changes: 46 additions & 45 deletions src/ripple/overlay/impl/TrafficCount.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TrafficCount
class TrafficStats
{
public:
std::string const name;
char const* name;

std::atomic<std::uint64_t> bytesIn {0};
std::atomic<std::uint64_t> bytesOut {0};
Expand Down Expand Up @@ -63,8 +63,8 @@ class TrafficCount
};

// If you add entries to this enum, you need to update the initialization
// of the array at the bottom of this file which maps array numbers to
// human-readable names.
// of the arrays at the bottom of this file which map array numbers to
// human-readable, monitoring-tool friendly names.
enum category : std::size_t
{
base, // basic peer overhead, must be first
Expand Down Expand Up @@ -172,56 +172,57 @@ class TrafficCount
@return an object which satisfies the requirements of Container
*/
auto
auto const&
getCounts () const
{
return counts_;
}


protected:
std::array<TrafficStats, category::unknown + 1> counts_
{{
{ "overhead" }, // category::base
{ "overhead: cluster" }, // category::cluster
{ "overhead: overlay" }, // category::overlay
{ "overhead: manifest" }, // category::manifests
{ "transactions" }, // category::transaction
{ "proposals" }, // category::proposal
{ "validations" }, // category::validation
{ "shards" }, // category::shards
{ "set (get)" }, // category::get_set
{ "set (share)" }, // category::share_set
{ "ledger data: Transaction Set candidate (get)" }, // category::ld_tsc_get
{ "ledger data: Transaction Set candidate (share)" }, // category::ld_tsc_share
{ "ledger data: Transaction Node (get)" }, // category::ld_txn_get
{ "ledger data: Transaction Node (share)" }, // category::ld_txn_share
{ "ledger data: Account State Node (get)" }, // category::ld_asn_get
{ "ledger data: Account State Node (share)" }, // category::ld_asn_share
{ "ledger data (get)" }, // category::ld_get
{ "ledger data (share)" }, // category::ld_share
{ "ledger: Transaction Set candidate (share)" }, // category::gl_tsc_share
{ "ledger: Transaction Set candidate (get)" }, // category::gl_tsc_get
{ "ledger: Transaction node (share)" }, // category::gl_txn_share
{ "ledger: Transaction node (get)" }, // category::gl_txn_get
{ "ledger: Account State node (share)" }, // category::gl_asn_share
{ "ledger: Account State node (get)" }, // category::gl_asn_get
{ "ledger (share)" }, // category::gl_share
{ "ledger (get)" }, // category::gl_get
{ "getobject: Ledger (share)" }, // category::share_hash_ledger
{ "getobject: Ledger (get)" }, // category::get_hash_ledger
{ "getobject: Transaction (share)" }, // category::share_hash_tx
{ "getobject: Transaction (get)" }, // category::get_hash_tx
{ "getobject: Transaction node (share)" }, // category::share_hash_txnode
{ "getobject: Transaction node (get)" }, // category::get_hash_txnode
{ "getobject: Account State node (share)" }, // category::share_hash_asnode
{ "getobject: Account State node (get)" }, // category::get_hash_asnode
{ "getobject: CAS (share)" }, // category::share_cas_object
{ "getobject: CAS (get)" }, // category::get_cas_object
{ "getobject: Fetch Pack (share)" }, // category::share_fetch_pack
{ "getobject: Fetch Pack (get)" }, // category::get_fetch_pack
{ "getobject (share)" }, // category::share_hash
{ "getobject (get)" }, // category::get_hash
{ "unknown" } // category::unknown
{"overhead"}, // category::base
{"overhead_cluster"}, // category::cluster
{"overhead_overlay"}, // category::overlay
{"overhead_manifest"}, // category::manifests
{"transactions"}, // category::transaction
{"proposals"}, // category::proposal
{"validations"}, // category::validation
{"shards"}, // category::shards
{"set_get"}, // category::get_set
{"set_share"}, // category::share_set
{"ledger_data_Transaction_Set_candidate_get"}, // category::ld_tsc_get
{"ledger_data_Transaction_Set_candidate_share"}, // category::ld_tsc_share
{"ledger_data_Transaction_Node_get"}, // category::ld_txn_get
{"ledger_data_Transaction_Node_share"}, // category::ld_txn_share
{"ledger_data_Account_State_Node_get"}, // category::ld_asn_get
{"ledger_data_Account_State_Node_share"}, // category::ld_asn_share
{"ledger_data_get"}, // category::ld_get
{"ledger_data_share"}, // category::ld_share
{"ledger_Transaction_Set_candidate_share"}, // category::gl_tsc_share
{"ledger_Transaction_Set_candidate_get"}, // category::gl_tsc_get
{"ledger_Transaction_node_share"}, // category::gl_txn_share
{"ledger_Transaction_node_get"}, // category::gl_txn_get
{"ledger_Account_State_node_share"}, // category::gl_asn_share
{"ledger_Account_State_node_get"}, // category::gl_asn_get
{"ledger_share"}, // category::gl_share
{"ledger_get"}, // category::gl_get
{"getobject_Ledger_share"}, // category::share_hash_ledger
{"getobject_Ledger_get"}, // category::get_hash_ledger
{"getobject_Transaction_share"}, // category::share_hash_tx
{"getobject_Transaction_get"}, // category::get_hash_tx
{"getobject_Transaction_node_share"}, // category::share_hash_txnode
{"getobject_Transaction_node_get"}, // category::get_hash_txnode
{"getobject_Account_State_node_share"}, // category::share_hash_asnode
{"getobject_Account_State_node_get"}, // category::get_hash_asnode
{"getobject_CAS_share"}, // category::share_cas_object
{"getobject_CAS_get"}, // category::get_cas_object
{"getobject_Fetch_Pack_share"}, // category::share_fetch_pack
{"getobject_Fetch Pack_get"}, // category::get_fetch_pack
{"getobject_share"}, // category::share_hash
{"getobject_get"}, // category::get_hash
{"unknown"} // category::unknown
}};
};

Expand Down
3 changes: 2 additions & 1 deletion src/ripple/overlay/make_Overlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ make_Overlay (
Resource::Manager& resourceManager,
Resolver& resolver,
boost::asio::io_service& io_service,
BasicConfig const& config);
BasicConfig const& config,
beast::insight::Collector::ptr const& collector);

} // ripple

Expand Down
36 changes: 33 additions & 3 deletions src/ripple/peerfinder/impl/PeerfinderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class ManagerImp
boost::asio::io_service& io_service,
clock_type& clock,
beast::Journal journal,
BasicConfig const& config)
BasicConfig const& config,
beast::insight::Collector::ptr const& collector)
: Manager (stoppable)
, io_service_(io_service)
, work_(boost::in_place(std::ref(io_service_)))
Expand All @@ -62,6 +63,7 @@ class ManagerImp
, checker_ (io_service_)
, m_logic (clock, m_store, checker_, journal)
, m_sociConfig (config, "peerfinder")
, m_stats(std::bind(&ManagerImp::collect_metrics, this),collector)
{
}

Expand Down Expand Up @@ -239,6 +241,34 @@ class ManagerImp
{
m_logic.onWrite (map);
}

private:
struct Stats
{

template <class Handler>
Stats (
Handler const& handler,
beast::insight::Collector::ptr const& collector)
: hook (collector->make_hook (handler))
, activeInboundPeers(collector->make_gauge("Peer_Finder","Active_Inbound_Peers"))
, activeOutboundPeers(collector->make_gauge("Peer_Finder","Active_Outbound_Peers"))
{
}

beast::insight::Hook hook;
beast::insight::Gauge activeInboundPeers;
beast::insight::Gauge activeOutboundPeers;
};

std::mutex m_statsMutex;
Stats m_stats;

void collect_metrics(){
std::lock_guard lock (m_statsMutex);
m_stats.activeInboundPeers = m_logic.counts_.inboundActive();
m_stats.activeOutboundPeers = m_logic.counts_.out_active();
}
};

//------------------------------------------------------------------------------
Expand All @@ -251,10 +281,10 @@ Manager::Manager (Stoppable& parent)

std::unique_ptr<Manager>
make_Manager (Stoppable& parent, boost::asio::io_service& io_service,
clock_type& clock, beast::Journal journal, BasicConfig const& config)
clock_type& clock, beast::Journal journal, BasicConfig const& config, beast::insight::Collector::ptr const& collector)
{
return std::make_unique<ManagerImp> (
parent, io_service, clock, journal, config);
parent, io_service, clock, journal, config, collector);
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/peerfinder/make_Manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace PeerFinder {
/** Create a new Manager. */
std::unique_ptr<Manager>
make_Manager (Stoppable& parent, boost::asio::io_service& io_service,
clock_type& clock, beast::Journal journal, BasicConfig const& config);
clock_type& clock, beast::Journal journal, BasicConfig const& config, beast::insight::Collector::ptr const& collector);

}
}
Expand Down

0 comments on commit b784988

Please sign in to comment.