From 32065ced6e8b08fff102de8a60342b0756511783 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Mon, 8 Sep 2014 08:18:39 -0700 Subject: [PATCH] Add peer count to HTTP server properties --- src/ripple/http/impl/Peer.cpp | 12 ++++++++++++ src/ripple/http/impl/Peer.h | 7 +++++++ src/ripple/http/impl/ServerImpl.cpp | 2 ++ 3 files changed, 21 insertions(+) diff --git a/src/ripple/http/impl/Peer.cpp b/src/ripple/http/impl/Peer.cpp index ec4197c07..06d326ebb 100644 --- a/src/ripple/http/impl/Peer.cpp +++ b/src/ripple/http/impl/Peer.cpp @@ -23,6 +23,14 @@ namespace ripple { namespace HTTP { +std::atomic Peer::s_count_; + +std::size_t +Peer::count() +{ + return s_count_.load(); +} + Peer::Peer (ServerImpl& server, Port const& port, beast::Journal journal) : journal_ (journal) , server_ (server) @@ -37,6 +45,8 @@ Peer::Peer (ServerImpl& server, Port const& port, beast::Journal journal) , bytes_in_ (0) , bytes_out_ (0) { + ++s_count_; + static std::atomic sid; id_ = std::string("#") + std::to_string(sid++); @@ -92,6 +102,8 @@ Peer::~Peer () if (journal_.trace) journal_.trace << id_ << " destroyed"; + + --s_count_; } //------------------------------------------------------------------------------ diff --git a/src/ripple/http/impl/Peer.h b/src/ripple/http/impl/Peer.h index 53559db9b..81132a010 100644 --- a/src/ripple/http/impl/Peer.h +++ b/src/ripple/http/impl/Peer.h @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -97,7 +98,13 @@ private: //-------------------------------------------------------------------------- + static std::atomic s_count_; + public: + static + std::size_t + count(); + Peer (ServerImpl& impl, Port const& port, beast::Journal journal); ~Peer (); diff --git a/src/ripple/http/impl/ServerImpl.cpp b/src/ripple/http/impl/ServerImpl.cpp index 8832f27bd..b71dacea1 100644 --- a/src/ripple/http/impl/ServerImpl.cpp +++ b/src/ripple/http/impl/ServerImpl.cpp @@ -153,6 +153,8 @@ ServerImpl::onWrite (beast::PropertyStream::Map& map) // VFALCO TODO Write the list of doors + map ["peers"] = Peer::count(); + { beast::PropertyStream::Set set ("sessions", map); for (auto const& stat : stats_)