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)
29 : m_name(name_), m_collector(collector)
30 {
31 }
32
33 ~GroupImp() = default;
34
35 std::string const&
36 name() const override
37 {
38 return m_name;
39 }
40
43 {
44 return m_name + "." + name;
45 }
46
47 Hook
48 make_hook(HookImpl::HandlerType const& handler) override
49 {
50 return m_collector->make_hook(handler);
51 }
52
54 make_counter(std::string const& name) override
55 {
56 return m_collector->make_counter(make_name(name));
57 }
58
59 Event
60 make_event(std::string const& name) override
61 {
62 return m_collector->make_event(make_name(name));
63 }
64
65 Gauge
66 make_gauge(std::string const& name) override
67 {
68 return m_collector->make_gauge(make_name(name));
69 }
70
71 Meter
72 make_meter(std::string const& name) override
73 {
74 return m_collector->make_meter(make_name(name));
75 }
76
77private:
80};
81
82//------------------------------------------------------------------------------
83
84class GroupsImp : public Groups
85{
86public:
87 using Items =
89
92
93 explicit GroupsImp(Collector::ptr const& collector) : m_collector(collector)
94 {
95 }
96
97 ~GroupsImp() = default;
98
99 Group::ptr const&
100 get(std::string const& name) override
101 {
103 m_items.emplace(name, Group::ptr()));
104 Group::ptr& group(result.first->second);
105 if (result.second)
107 return group;
108 }
109};
110
111} // namespace detail
112
113//------------------------------------------------------------------------------
114
115Groups::~Groups() = default;
116
119{
120 return std::make_unique<detail::GroupsImp>(collector);
121}
122
123} // namespace insight
124} // 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:72
Hook make_hook(HookImpl::HandlerType const &handler) override
Definition Groups.cpp:48
std::string const & name() const override
Returns the name of this group, for diagnostics.
Definition Groups.cpp:36
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:66
std::string make_name(std::string const &name)
Definition Groups.cpp:42
Counter make_counter(std::string const &name) override
Create a counter with the specified name.
Definition Groups.cpp:54
Event make_event(std::string const &name) override
Create an event with the specified name.
Definition Groups.cpp:60
GroupsImp(Collector::ptr const &collector)
Definition Groups.cpp:93
Group::ptr const & get(std::string const &name) override
Find or create a new collector with a given name.
Definition Groups.cpp:100
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:118