20#include <xrpl/beast/core/List.h>
21#include <xrpl/beast/insight/CounterImpl.h>
22#include <xrpl/beast/insight/EventImpl.h>
23#include <xrpl/beast/insight/GaugeImpl.h>
24#include <xrpl/beast/insight/Hook.h>
25#include <xrpl/beast/insight/HookImpl.h>
26#include <xrpl/beast/insight/MeterImpl.h>
27#include <xrpl/beast/insight/StatsDCollector.h>
28#include <xrpl/beast/net/IPEndpoint.h>
29#include <xrpl/beast/utility/Journal.h>
30#include <xrpl/beast/utility/instrumentation.h>
32#include <boost/asio/basic_waitable_timer.hpp>
33#include <boost/asio/bind_executor.hpp>
34#include <boost/asio/buffer.hpp>
35#include <boost/asio/error.hpp>
36#include <boost/asio/executor_work_guard.hpp>
37#include <boost/asio/io_context.hpp>
38#include <boost/asio/ip/udp.hpp>
39#include <boost/asio/strand.hpp>
40#include <boost/system/detail/error_code.hpp>
56#ifndef BEAST_STATSDCOLLECTOR_TRACING_ENABLED
57#define BEAST_STATSDCOLLECTOR_TRACING_ENABLED 0
65class StatsDCollectorImp;
245 boost::asio::io_context::executor_type>>
247 boost::asio::strand<boost::asio::io_context::executor_type>
m_strand;
248 boost::asio::basic_waitable_timer<std::chrono::steady_clock>
m_timer;
257 static boost::asio::ip::udp::endpoint
260 return boost::asio::ip::udp::endpoint(ep.
address(), ep.
port());
285 catch (boost::system::system_error
const&)
347 boost::asio::io_context&
368 boost::asio::dispatch(
370 boost::asio::bind_executor(
375 std::move(buffer))));
383 boost::system::error_code ec,
386 if (ec == boost::asio::error::operation_aborted)
392 stream <<
"async_send failed: " << ec.message();
401#if BEAST_STATSDCOLLECTOR_TRACING_ENABLED
402 for (
auto const& buffer : buffers)
405 buffer.data(), boost::asio::buffer_size(buffer));
430 for (
auto const& s : *keepAlive)
435 "beast::insight::detail::StatsDCollectorImp::send_buffers : "
436 "non-empty payload");
446 std::placeholders::_1,
447 std::placeholders::_2));
456 if (!buffers.
empty())
465 std::placeholders::_1,
466 std::placeholders::_2));
473 using namespace std::chrono_literals;
482 if (ec == boost::asio::error::operation_aborted)
488 stream <<
"on_timer failed: " << ec.message();
505 boost::system::error_code ec;
510 stream <<
"Connect failed: " << ec.message();
518 m_socket.shutdown(boost::asio::ip::udp::socket::shutdown_send, ec);
531 : m_impl(impl), m_handler(handler)
552 : m_impl(impl), m_name(name), m_value(0), m_dirty(false)
565 boost::asio::dispatch(
605 : m_impl(impl), m_name(name)
612 boost::asio::dispatch(
634 : m_impl(impl), m_name(name), m_last_value(0), m_value(0), m_dirty(false)
647 boost::asio::dispatch(
658 boost::asio::dispatch(
709 value = (d >= value) ? 0 : value - d;
726 : m_impl(impl), m_name(name), m_value(0), m_dirty(false)
739 boost::asio::dispatch(
785 address, prefix, journal);
A version-independent IP address and port combination.
Address const & address() const
Returns the address portion of this endpoint.
Port port() const
Returns the port number on the endpoint.
A generic endpoint for log messages.
Intrusive doubly linked list.
A metric for measuring an integral value.
A metric for reporting event timing.
A metric for measuring an integral value.
A reference to a handler for performing polled collection.
A metric for measuring an integral value.
A Collector that reports metrics to a StatsD server.
static std::shared_ptr< StatsDCollector > New(IP::Endpoint const &address, std::string const &prefix, Journal journal)
Create a StatsD collector.
void remove(StatsDMetricBase &metric)
static boost::asio::ip::udp::endpoint to_endpoint(IP::Endpoint const &ep)
std::deque< std::string > m_data
void add(StatsDMetricBase &metric)
Counter make_counter(std::string const &name) override
Create a counter with the specified name.
void do_post_buffer(std::string const &buffer)
StatsDCollectorImp(IP::Endpoint const &address, std::string const &prefix, Journal journal)
std::optional< boost::asio::executor_work_guard< boost::asio::io_context::executor_type > > m_work
std::recursive_mutex metricsLock_
boost::asio::ip::udp::socket m_socket
Meter make_meter(std::string const &name) override
Create a meter with the specified name.
Event make_event(std::string const &name) override
Create an event with the specified name.
void on_timer(boost::system::error_code ec)
boost::asio::io_context & get_io_context()
std::string const & prefix() const
Hook make_hook(HookImpl::HandlerType const &handler) override
List< StatsDMetricBase > metrics_
~StatsDCollectorImp() override
boost::asio::basic_waitable_timer< std::chrono::steady_clock > m_timer
void log(std::vector< boost::asio::const_buffer > const &buffers)
boost::asio::io_context m_io_context
Gauge make_gauge(std::string const &name) override
Create a gauge with the specified name.
void post_buffer(std::string &&buffer)
void on_send(std::shared_ptr< std::deque< std::string > >, boost::system::error_code ec, std::size_t)
boost::asio::strand< boost::asio::io_context::executor_type > m_strand
void do_increment(CounterImpl::value_type amount)
StatsDCounterImpl & operator=(StatsDCounterImpl const &)
void increment(CounterImpl::value_type amount) override
void do_process() override
StatsDCounterImpl(std::string const &name, std::shared_ptr< StatsDCollectorImp > const &impl)
CounterImpl::value_type m_value
~StatsDCounterImpl() override
std::shared_ptr< StatsDCollectorImp > m_impl
void notify(EventImpl::value_type const &value) override
StatsDEventImpl & operator=(StatsDEventImpl const &)
std::shared_ptr< StatsDCollectorImp > m_impl
StatsDEventImpl(std::string const &name, std::shared_ptr< StatsDCollectorImp > const &impl)
void do_notify(EventImpl::value_type const &value)
~StatsDEventImpl()=default
void do_increment(GaugeImpl::difference_type amount)
GaugeImpl::value_type m_last_value
void increment(GaugeImpl::difference_type amount) override
~StatsDGaugeImpl() override
std::shared_ptr< StatsDCollectorImp > m_impl
void set(GaugeImpl::value_type value) override
void do_set(GaugeImpl::value_type value)
void do_process() override
StatsDGaugeImpl & operator=(StatsDGaugeImpl const &)
StatsDGaugeImpl(std::string const &name, std::shared_ptr< StatsDCollectorImp > const &impl)
GaugeImpl::value_type m_value
std::shared_ptr< StatsDCollectorImp > m_impl
StatsDHookImpl & operator=(StatsDHookImpl const &)
~StatsDHookImpl() override
StatsDHookImpl(HandlerType const &handler, std::shared_ptr< StatsDCollectorImp > const &impl)
void do_process() override
~StatsDMeterImpl() override
StatsDMeterImpl & operator=(StatsDMeterImpl const &)
void increment(MeterImpl::value_type amount) override
void do_process() override
void do_increment(MeterImpl::value_type amount)
StatsDMeterImpl(std::string const &name, std::shared_ptr< StatsDCollectorImp > const &impl)
std::shared_ptr< StatsDCollectorImp > m_impl
MeterImpl::value_type m_value
virtual ~StatsDMetricBase()=default
StatsDMetricBase & operator=(StatsDMetricBase const &)=delete
StatsDMetricBase()=default
StatsDMetricBase(StatsDMetricBase const &)=delete
virtual void do_process()=0
T emplace_back(T... args)
T shared_from_this(T... args)