xrpld
Loading...
Searching...
No Matches
Groups.cpp
1#include <xrpl/beast/insight/Groups.h>
2
3#include <xrpl/beast/hash/uhash.h>
4#include <xrpl/beast/insight/Collector.h>
5#include <xrpl/beast/insight/Counter.h>
6#include <xrpl/beast/insight/Event.h>
7#include <xrpl/beast/insight/Gauge.h>
8#include <xrpl/beast/insight/Group.h>
9#include <xrpl/beast/insight/Hook.h>
10#include <xrpl/beast/insight/HookImpl.h>
11#include <xrpl/beast/insight/Meter.h>
12
13#include <memory>
14#include <string>
15#include <unordered_map>
16#include <utility>
17
18namespace beast::insight {
19
20namespace detail {
21
22class GroupImp : public std::enable_shared_from_this<GroupImp>, public Group
23{
26
27public:
29 : name_(std::move(name)), collector_(std::move(collector))
30 {
31 }
32
33 ~GroupImp() override = default;
34
35 std::string const&
36 name() const override
37 {
38 return name_;
39 }
40
43 {
44 return name_ + "." + name;
45 }
46
47 Hook
48 makeHook(HookImpl::HandlerType const& handler) override
49 {
50 return collector_->makeHook(handler);
51 }
52
54 makeCounter(std::string const& name) override
55 {
56 return collector_->makeCounter(makeName(name));
57 }
58
59 Event
60 makeEvent(std::string const& name) override
61 {
62 return collector_->makeEvent(makeName(name));
63 }
64
65 Gauge
66 makeGauge(std::string const& name) override
67 {
68 return collector_->makeGauge(makeName(name));
69 }
70
71 Meter
72 makeMeter(std::string const& name) override
73 {
74 return collector_->makeMeter(makeName(name));
75 }
76
78 operator=(GroupImp const&) = delete;
79};
80
81//------------------------------------------------------------------------------
82
83class GroupsImp : public Groups
84{
85public:
87
90
94
95 ~GroupsImp() override = default;
96
97 Group::ptr const&
98 get(std::string const& name) override
99 {
100 std::pair<Items::iterator, bool> const result(items.emplace(name, Group::ptr()));
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
115makeGroups(Collector::ptr const& collector)
116{
117 return std::make_unique<detail::GroupsImp>(collector);
118}
119
120} // namespace beast::insight
std::shared_ptr< Collector > ptr
Definition Collector.h:26
A metric for measuring an integral value.
Definition Counter.h:19
A metric for reporting event timing.
Definition Event.h:21
A metric for measuring an integral value.
Definition Gauge.h:20
A collector front-end that manages a group of metrics.
Definition Group.h:12
std::shared_ptr< Group > ptr
Definition Group.h:14
A container for managing a set of metric groups.
Definition Groups.h:13
std::function< void(void)> HandlerType
Definition HookImpl.h:11
A reference to a handler for performing polled collection.
Definition Hook.h:12
A metric for measuring an integral value.
Definition Meter.h:18
Hook makeHook(HookImpl::HandlerType const &handler) override
Definition Groups.cpp:48
GroupImp & operator=(GroupImp const &)=delete
std::string const & name() const override
Returns the name of this group, for diagnostics.
Definition Groups.cpp:36
Event makeEvent(std::string const &name) override
Create an event with the specified name.
Definition Groups.cpp:60
Meter makeMeter(std::string const &name) override
Create a meter with the specified name.
Definition Groups.cpp:72
Counter makeCounter(std::string const &name) override
Create a counter with the specified name.
Definition Groups.cpp:54
Gauge makeGauge(std::string const &name) override
Create a gauge with the specified name.
Definition Groups.cpp:66
std::string makeName(std::string const &name)
Definition Groups.cpp:42
GroupImp(std::string name, Collector::ptr collector)
Definition Groups.cpp:28
std::unordered_map< std::string, std::shared_ptr< Group >, Uhash<> > Items
Definition Groups.cpp:86
Group::ptr const & get(std::string const &name) override
Find or create a new collector with a given name.
Definition Groups.cpp:98
GroupsImp(Collector::ptr collector)
Definition Groups.cpp:91
T make_shared(T... args)
T make_unique(T... args)
std::unique_ptr< Groups > makeGroups(Collector::ptr const &collector)
Create a group container that uses the specified collector.
Definition Groups.cpp:115
STL namespace.