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/HookImpl.h>
25#include <xrpl/beast/insight/MeterImpl.h>
26#include <xrpl/beast/insight/StatsDCollector.h>
27#include <xrpl/beast/net/IPAddressConversion.h>
28#include <xrpl/beast/utility/instrumentation.h>
29#include <boost/asio/ip/tcp.hpp>
39#ifndef BEAST_STATSDCOLLECTOR_TRACING_ENABLED
40#define BEAST_STATSDCOLLECTOR_TRACING_ENABLED 0
48class StatsDCollectorImp;
229 boost::asio::basic_waitable_timer<std::chrono::steady_clock>
m_timer;
238 static boost::asio::ip::udp::endpoint
241 return boost::asio::ip::udp::endpoint(ep.
address(), ep.
port());
262 boost::system::error_code ec;
272 return Hook(std::make_shared<detail::StatsDHookImpl>(
279 return Counter(std::make_shared<detail::StatsDCounterImpl>(
286 return Event(std::make_shared<detail::StatsDEventImpl>(
293 return Gauge(std::make_shared<detail::StatsDGaugeImpl>(
300 return Meter(std::make_shared<detail::StatsDMeterImpl>(
322 boost::asio::io_service&
352 boost::system::error_code ec,
355 if (ec == boost::asio::error::operation_aborted)
361 stream <<
"async_send failed: " << ec.message();
370#if BEAST_STATSDCOLLECTOR_TRACING_ENABLED
371 for (
auto const& buffer : buffers)
374 boost::asio::buffer_cast<char const*>(buffer),
375 boost::asio::buffer_size(buffer));
397 std::make_shared<std::deque<std::string>>(std::move(
m_data));
400 for (
auto const& s : *keepAlive)
405 "beast::insight::detail::StatsDCollectorImp::send_buffers : "
406 "non-empty payload");
416 std::placeholders::_1,
417 std::placeholders::_2));
426 if (!buffers.
empty())
435 std::placeholders::_1,
436 std::placeholders::_2));
443 using namespace std::chrono_literals;
452 if (ec == boost::asio::error::operation_aborted)
458 stream <<
"on_timer failed: " << ec.message();
475 boost::system::error_code ec;
480 stream <<
"Connect failed: " << ec.message();
488 m_socket.shutdown(boost::asio::ip::udp::socket::shutdown_send, ec);
501 : m_impl(impl), m_handler(handler)
522 : m_impl(impl), m_name(name), m_value(0), m_dirty(false)
573 : m_impl(impl), m_name(name)
600 : m_impl(impl), m_name(name), m_last_value(0), m_value(0), m_dirty(false)
671 value = (d >= value) ? 0 : value - d;
688 : m_impl(impl), m_name(name), m_value(0), m_dirty(false)
744 return std::make_shared<detail::StatsDCollectorImp>(
745 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)
std::optional< boost::asio::io_service::work > m_work
StatsDCollectorImp(IP::Endpoint const &address, std::string const &prefix, Journal journal)
std::recursive_mutex metricsLock_
boost::asio::ip::udp::socket m_socket
boost::asio::io_service & get_io_service()
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)
std::string const & prefix() const
Hook make_hook(HookImpl::HandlerType const &handler) override
List< StatsDMetricBase > metrics_
~StatsDCollectorImp() override
boost::asio::io_service m_io_service
boost::asio::basic_waitable_timer< std::chrono::steady_clock > m_timer
void log(std::vector< boost::asio::const_buffer > const &buffers)
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::io_service::strand 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)