20 #include <ripple/beast/core/List.h>
21 #include <ripple/beast/insight/CounterImpl.h>
22 #include <ripple/beast/insight/EventImpl.h>
23 #include <ripple/beast/insight/GaugeImpl.h>
24 #include <ripple/beast/insight/HookImpl.h>
25 #include <ripple/beast/insight/MeterImpl.h>
26 #include <ripple/beast/insight/StatsDCollector.h>
27 #include <ripple/beast/net/IPAddressConversion.h>
28 #include <boost/asio/ip/tcp.hpp>
39 #ifndef BEAST_STATSDCOLLECTOR_TRACING_ENABLED
40 #define BEAST_STATSDCOLLECTOR_TRACING_ENABLED 0
48 class 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)
413 std::placeholders::_1,
414 std::placeholders::_2));
423 if (!buffers.
empty())
432 std::placeholders::_1,
433 std::placeholders::_2));
440 using namespace std::chrono_literals;
449 if (ec == boost::asio::error::operation_aborted)
455 stream <<
"on_timer failed: " << ec.message();
472 boost::system::error_code ec;
477 stream <<
"Connect failed: " << ec.message();
485 m_socket.shutdown(boost::asio::ip::udp::socket::shutdown_send, ec);
498 : m_impl(impl), m_handler(handler)
519 : m_impl(impl), m_name(name), m_value(0), m_dirty(false)
570 : m_impl(impl), m_name(name)
597 : m_impl(impl), m_name(name), m_last_value(0), m_value(0), m_dirty(false)
668 value = (d >= value) ? 0 : value - d;
685 : m_impl(impl), m_name(name), m_value(0), m_dirty(false)
741 return std::make_shared<detail::StatsDCollectorImp>(
742 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
std::optional< boost::asio::io_service::work > m_work
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)
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)
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