xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
beast
insight
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
18
namespace
beast::insight
{
19
20
namespace
detail
{
21
22
class
GroupImp
:
public
std::enable_shared_from_this
<GroupImp>,
public
Group
23
{
24
std::string
const
name_
;
25
Collector::Ptr
collector_
;
26
27
public
:
28
GroupImp
(
std::string
name
,
Collector::Ptr
collector)
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
41
std::string
42
makeName
(
std::string
const
&
name
)
43
{
44
return
name_
+
"."
+
name
;
45
}
46
47
Hook
48
makeHook
(
HookImpl::HandlerType
const
& handler)
override
49
{
50
return
collector_
->makeHook(handler);
51
}
52
53
Counter
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
77
GroupImp
&
78
operator=
(
GroupImp
const
&) =
delete
;
79
};
80
81
//------------------------------------------------------------------------------
82
83
class
GroupsImp
:
public
Groups
84
{
85
public
:
86
using
Items
=
std::unordered_map<std::string, std::shared_ptr<Group>
,
Uhash<>
>;
87
88
Collector::Ptr
collector
;
89
Items
items
;
90
91
explicit
GroupsImp
(
Collector::Ptr
collector
) :
collector
(
std
::move(
collector
))
92
{
93
}
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
)
103
group =
std::make_shared<GroupImp>
(name,
collector
);
104
return
group;
105
}
106
};
107
108
}
// namespace detail
109
110
//------------------------------------------------------------------------------
111
112
Groups::~Groups
() =
default
;
113
114
std::unique_ptr<Groups>
115
makeGroups
(
Collector::Ptr
const
& collector)
116
{
117
return
std::make_unique<detail::GroupsImp>
(collector);
118
}
119
120
}
// namespace beast::insight
std::string
beast::insight::Collector::Ptr
std::shared_ptr< Collector > Ptr
Definition
Collector.h:29
beast::insight::Counter
A metric for measuring an integral value.
Definition
Counter.h:20
beast::insight::Event
A metric for reporting event timing.
Definition
Event.h:22
beast::insight::Gauge
A metric for measuring an integral value.
Definition
Gauge.h:21
beast::insight::Group
A collector front-end that manages a group of metrics.
Definition
Group.h:14
beast::insight::Group::Ptr
std::shared_ptr< Group > Ptr
Definition
Group.h:16
beast::insight::Groups
A container for managing a set of metric groups.
Definition
Groups.h:15
beast::insight::Groups::~Groups
virtual ~Groups()=0
beast::insight::HookImpl::HandlerType
std::function< void(void)> HandlerType
Definition
HookImpl.h:11
beast::insight::Hook
A reference to a handler for performing polled collection.
Definition
Hook.h:14
beast::insight::Meter
A metric for measuring an integral value.
Definition
Meter.h:19
beast::insight::detail::GroupImp
Definition
Groups.cpp:23
beast::insight::detail::GroupImp::makeHook
Hook makeHook(HookImpl::HandlerType const &handler) override
Definition
Groups.cpp:48
beast::insight::detail::GroupImp::operator=
GroupImp & operator=(GroupImp const &)=delete
beast::insight::detail::GroupImp::name
std::string const & name() const override
Returns the name of this group, for diagnostics.
Definition
Groups.cpp:36
beast::insight::detail::GroupImp::makeEvent
Event makeEvent(std::string const &name) override
Create an event with the specified name.
Definition
Groups.cpp:60
beast::insight::detail::GroupImp::collector_
Collector::Ptr collector_
Definition
Groups.cpp:25
beast::insight::detail::GroupImp::makeMeter
Meter makeMeter(std::string const &name) override
Create a meter with the specified name.
Definition
Groups.cpp:72
beast::insight::detail::GroupImp::~GroupImp
~GroupImp() override=default
beast::insight::detail::GroupImp::makeCounter
Counter makeCounter(std::string const &name) override
Create a counter with the specified name.
Definition
Groups.cpp:54
beast::insight::detail::GroupImp::name_
std::string const name_
Definition
Groups.cpp:24
beast::insight::detail::GroupImp::makeGauge
Gauge makeGauge(std::string const &name) override
Create a gauge with the specified name.
Definition
Groups.cpp:66
beast::insight::detail::GroupImp::GroupImp
GroupImp(std::string name, Collector::Ptr collector)
Definition
Groups.cpp:28
beast::insight::detail::GroupImp::makeName
std::string makeName(std::string const &name)
Definition
Groups.cpp:42
beast::insight::detail::GroupsImp::collector
Collector::Ptr collector
Definition
Groups.cpp:88
beast::insight::detail::GroupsImp::Items
std::unordered_map< std::string, std::shared_ptr< Group >, Uhash<> > Items
Definition
Groups.cpp:86
beast::insight::detail::GroupsImp::items
Items items
Definition
Groups.cpp:89
beast::insight::detail::GroupsImp::~GroupsImp
~GroupsImp() override=default
beast::insight::detail::GroupsImp::get
Group::Ptr const & get(std::string const &name) override
Find or create a new collector with a given name.
Definition
Groups.cpp:98
beast::insight::detail::GroupsImp::GroupsImp
GroupsImp(Collector::Ptr collector)
Definition
Groups.cpp:91
std::enable_shared_from_this
std::make_shared
T make_shared(T... args)
std::make_unique
T make_unique(T... args)
memory
beast::insight::detail
Definition
Groups.cpp:20
beast::insight
Definition
Collector.h:13
beast::insight::makeGroups
std::unique_ptr< Groups > makeGroups(Collector::Ptr const &collector)
Create a group container that uses the specified collector.
Definition
Groups.cpp:115
std
STL namespace.
std::pair
string
beast::Uhash
Definition
uhash.h:11
std::unique_ptr
unordered_map
utility
Generated by
1.17.0