rippled
Loading...
Searching...
No Matches
Groups.cpp
1#include <xrpl/beast/hash/uhash.h>
2#include <xrpl/beast/insight/Collector.h>
3#include <xrpl/beast/insight/Counter.h>
4#include <xrpl/beast/insight/Event.h>
5#include <xrpl/beast/insight/Gauge.h>
6#include <xrpl/beast/insight/Group.h>
7#include <xrpl/beast/insight/Groups.h>
8#include <xrpl/beast/insight/Hook.h>
9#include <xrpl/beast/insight/HookImpl.h>
10#include <xrpl/beast/insight/Meter.h>
11
12#include <memory>
13#include <string>
14#include <unordered_map>
15#include <utility>
16
17namespace beast {
18namespace insight {
19
20namespace detail {
21
22class GroupImp : public std::enable_shared_from_this<GroupImp>, public Group
23{
24public:
27
28 GroupImp(std::string const& name_, Collector::ptr const& collector) : m_name(name_), m_collector(collector)
29 {
30 }
31
32 ~GroupImp() = default;
33
34 std::string const&
35 name() const override
36 {
37 return m_name;
38 }
39
42 {
43 return m_name + "." + name;
44 }
45
46 Hook
47 make_hook(HookImpl::HandlerType const& handler) override
48 {
49 return m_collector->make_hook(handler);
50 }
51
53 make_counter(std::string const& name) override
54 {
55 return m_collector->make_counter(make_name(name));
56 }
57
58 Event
59 make_event(std::string const& name) override
60 {
61 return m_collector->make_event(make_name(name));
62 }
63
64 Gauge
65 make_gauge(std::string const& name) override
66 {
67 return m_collector->make_gauge(make_name(name));
68 }
69
70 Meter
71 make_meter(std::string const& name) override
72 {
73 return m_collector->make_meter(make_name(name));
74 }
75
76private:
79};
80
81//------------------------------------------------------------------------------
82
83class GroupsImp : public Groups
84{
85public:
87
90
91 explicit GroupsImp(Collector::ptr const& collector) : m_collector(collector)
92 {
93 }
94
95 ~GroupsImp() = default;
96
97 Group::ptr const&
98 get(std::string const& name) override
99 {
101 Group::ptr& group(result.first->second);
102 if (result.second)
104 return group;
105 }
106};
107
108} // namespace detail
109
110//------------------------------------------------------------------------------
111
112Groups::~Groups() = default;
113
116{
117 return std::make_unique<detail::GroupsImp>(collector);
118}
119
120} // namespace insight
121} // namespace beast
A metric for measuring an integral value.
Definition Counter.h:20
A metric for reporting event timing.
Definition Event.h:22
A metric for measuring an integral value.
Definition Gauge.h:21
A collector front-end that manages a group of metrics.
Definition Group.h:14
A container for managing a set of metric groups.
Definition Groups.h:15
A reference to a handler for performing polled collection.
Definition Hook.h:13
A metric for measuring an integral value.
Definition Meter.h:19
Meter make_meter(std::string const &name) override
Create a meter with the specified name.
Definition Groups.cpp:71
Hook make_hook(HookImpl::HandlerType const &handler) override
Definition Groups.cpp:47
std::string const & name() const override
Returns the name of this group, for diagnostics.
Definition Groups.cpp:35
GroupImp(std::string const &name_, Collector::ptr const &collector)
Definition Groups.cpp:28
GroupImp & operator=(GroupImp const &)
Gauge make_gauge(std::string const &name) override
Create a gauge with the specified name.
Definition Groups.cpp:65
std::string make_name(std::string const &name)
Definition Groups.cpp:41
Counter make_counter(std::string const &name) override
Create a counter with the specified name.
Definition Groups.cpp:53
Event make_event(std::string const &name) override
Create an event with the specified name.
Definition Groups.cpp:59
GroupsImp(Collector::ptr const &collector)
Definition Groups.cpp:91
Group::ptr const & get(std::string const &name) override
Find or create a new collector with a given name.
Definition Groups.cpp:98
T emplace(T... args)
T is_same_v
std::unique_ptr< Groups > make_Groups(Collector::ptr const &collector)
Create a group container that uses the specified collector.
Definition Groups.cpp:115