Add peer count to HTTP server properties

This commit is contained in:
Vinnie Falco
2014-09-08 08:18:39 -07:00
parent b5224a2227
commit 32065ced6e
3 changed files with 21 additions and 0 deletions

View File

@@ -23,6 +23,14 @@
namespace ripple {
namespace HTTP {
std::atomic <std::size_t> 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 <int> sid;
id_ = std::string("#") + std::to_string(sid++);
@@ -92,6 +102,8 @@ Peer::~Peer ()
if (journal_.trace) journal_.trace <<
id_ << " destroyed";
--s_count_;
}
//------------------------------------------------------------------------------

View File

@@ -33,6 +33,7 @@
#include <beast/module/asio/http/HTTPRequestParser.h>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/streambuf.hpp>
#include <atomic>
#include <chrono>
#include <functional>
#include <memory>
@@ -97,7 +98,13 @@ private:
//--------------------------------------------------------------------------
static std::atomic <std::size_t> s_count_;
public:
static
std::size_t
count();
Peer (ServerImpl& impl, Port const& port, beast::Journal journal);
~Peer ();

View File

@@ -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_)