20 #include <ripple/beast/net/IPAddressConversion.h>
21 #include <ripple/beast/insight/HookImpl.h>
22 #include <ripple/beast/insight/CounterImpl.h>
23 #include <ripple/beast/insight/EventImpl.h>
24 #include <ripple/beast/insight/GaugeImpl.h>
25 #include <ripple/beast/insight/MeterImpl.h>
26 #include <ripple/beast/insight/StatsDCollector.h>
27 #include <ripple/beast/core/List.h>
28 #include <boost/asio/ip/tcp.hpp>
29 #include <boost/optional.hpp>
39 #ifndef BEAST_STATSDCOLLECTOR_TRACING_ENABLED
40 #define BEAST_STATSDCOLLECTOR_TRACING_ENABLED 0
48 class StatsDCollectorImp;
208 boost::optional <boost::asio::io_service::work>
m_work;
210 boost::asio::basic_waitable_timer<std::chrono::steady_clock>
m_timer;
222 return boost::asio::ip::udp::endpoint (ep.
address(), ep.
port());
243 boost::system::error_code ec;
252 return Hook (std::make_shared <detail::StatsDHookImpl> (
258 return Counter (std::make_shared <detail::StatsDCounterImpl> (
264 return Event (std::make_shared <detail::StatsDEventImpl> (
270 return Gauge (std::make_shared <detail::StatsDGaugeImpl> (
276 return Meter (std::make_shared <detail::StatsDMeterImpl> (
315 std::move (buffer))));
323 if (ec == boost::asio::error::operation_aborted)
329 stream <<
"async_send failed: " << ec.message();
337 #if BEAST_STATSDCOLLECTOR_TRACING_ENABLED
338 for (
auto const& buffer : buffers)
340 std::string const s (boost::asio::buffer_cast <char const*> (buffer),
341 boost::asio::buffer_size (buffer));
362 std::make_shared<std::deque<std::string>>(std::move (
m_data));
365 for (
auto const& s : *keepAlive)
368 assert (! s.empty ());
374 std::placeholders::_1,
375 std::placeholders::_2));
384 if (! buffers.
empty ())
389 std::placeholders::_1,
390 std::placeholders::_2));
396 using namespace std::chrono_literals;
400 std::placeholders::_1));
405 if (ec == boost::asio::error::operation_aborted)
411 stream <<
"on_timer failed: " << ec.message();
427 boost::system::error_code ec;
432 stream <<
"Connect failed: " << ec.message();
441 boost::asio::ip::udp::socket::shutdown_send, ec);
454 , m_handler (handler)
490 std::static_pointer_cast <StatsDCounterImpl> (
501 m_impl->prefix() <<
"." <<
534 std::static_pointer_cast <StatsDEventImpl> (
542 m_impl->prefix() <<
"." <<
544 value.
count() <<
"|ms" <<
571 std::static_pointer_cast <StatsDGaugeImpl> (
579 std::static_pointer_cast <StatsDGaugeImpl> (
590 m_impl->prefix() <<
"." <<
626 value = (d >= value) ? 0 : value - d;
658 std::static_pointer_cast <StatsDMeterImpl> (
669 m_impl->prefix() <<
"." <<
696 return std::make_shared <detail::StatsDCollectorImp> (
697 address, prefix, journal);
boost::asio::io_service & get_io_service()
void do_notify(EventImpl::value_type const &value)
void do_set(GaugeImpl::value_type value)
void do_process() override
A metric for measuring an integral value.
void set(GaugeImpl::value_type value) override
A metric for measuring an integral value.
std::shared_ptr< StatsDCollectorImp > m_impl
Event make_event(std::string const &name) override
Create an event with the specified name.
StatsDGaugeImpl(std::string const &name, std::shared_ptr< StatsDCollectorImp > const &impl)
~StatsDCounterImpl() override
boost::asio::io_service::strand m_strand
void do_process() override
void on_send(std::shared_ptr< std::deque< std::string >>, boost::system::error_code ec, std::size_t)
std::shared_ptr< StatsDCollectorImp > m_impl
Address const & address() const
Returns the address portion of this endpoint.
StatsDMetricBase & operator=(StatsDMetricBase const &)=delete
std::recursive_mutex metricsLock_
StatsDMetricBase()=default
StatsDCounterImpl & operator=(StatsDCounterImpl const &)
Gauge make_gauge(std::string const &name) override
Create a gauge with the specified name.
boost::asio::ip::udp::socket m_socket
CounterImpl::value_type m_value
static boost::asio::ip::udp::endpoint to_endpoint(IP::Endpoint const &ep)
void increment(GaugeImpl::difference_type amount) override
StatsDEventImpl(std::string const &name, std::shared_ptr< StatsDCollectorImp > const &impl)
Hook make_hook(HookImpl::HandlerType const &handler) override
boost::asio::basic_waitable_timer< std::chrono::steady_clock > m_timer
void add(StatsDMetricBase &metric)
void remove(StatsDMetricBase &metric)
void do_increment(MeterImpl::value_type amount)
void log(std::vector< boost::asio::const_buffer > const &buffers)
T shared_from_this(T... args)
GaugeImpl::value_type m_last_value
std::shared_ptr< StatsDCollectorImp > m_impl
void do_post_buffer(std::string const &buffer)
void increment(MeterImpl::value_type amount) override
MeterImpl::value_type m_value
StatsDCounterImpl(std::string const &name, std::shared_ptr< StatsDCollectorImp > const &impl)
StatsDMeterImpl(std::string const &name, std::shared_ptr< StatsDCollectorImp > const &impl)
std::function< void(void)> HandlerType
virtual ~StatsDMetricBase()=default
void do_increment(GaugeImpl::difference_type amount)
List< StatsDMetricBase > metrics_
static std::shared_ptr< StatsDCollector > New(IP::Endpoint const &address, std::string const &prefix, Journal journal)
Create a StatsD collector.
~StatsDEventImpl()=default
A metric for reporting event timing.
StatsDHookImpl(HandlerType const &handler, std::shared_ptr< StatsDCollectorImp > const &impl)
Port port() const
Returns the port number on the endpoint.
A Collector that reports metrics to a StatsD server.
Meter make_meter(std::string const &name) override
Create a meter with the specified name.
A generic endpoint for log messages.
void do_process() override
A metric for measuring an integral value.
~StatsDHookImpl() override
T emplace_back(T... args)
std::shared_ptr< StatsDCollectorImp > m_impl
~StatsDMeterImpl() override
std::deque< std::string > m_data
std::string const & prefix() const
void on_timer(boost::system::error_code ec)
boost::optional< boost::asio::io_service::work > m_work
void notify(EventImpl::value_type const &value) override
~StatsDCollectorImp() override
Counter make_counter(std::string const &name) override
Create a counter with the specified name.
void increment(CounterImpl::value_type amount) override
StatsDHookImpl & operator=(StatsDHookImpl const &)
StatsDCollectorImp(IP::Endpoint const &address, std::string const &prefix, Journal journal)
A version-independent IP address and port combination.
StatsDMeterImpl & operator=(StatsDMeterImpl const &)
void post_buffer(std::string &&buffer)
void do_process() override
boost::asio::io_service m_io_service
void do_increment(CounterImpl::value_type amount)
A reference to a handler for performing polled collection.
~StatsDGaugeImpl() override
std::shared_ptr< StatsDCollectorImp > m_impl
Intrusive doubly linked list.
virtual void do_process()=0
StatsDEventImpl & operator=(StatsDEventImpl const &)
StatsDGaugeImpl & operator=(StatsDGaugeImpl const &)
GaugeImpl::value_type m_value