rippled
Loading...
Searching...
No Matches
Groups.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of Beast: https://github.com/vinniefalco/Beast
4 Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpl/beast/hash/uhash.h>
21#include <xrpl/beast/insight/Group.h>
22#include <xrpl/beast/insight/Groups.h>
23#include <memory>
24#include <unordered_map>
25
26namespace beast {
27namespace insight {
28
29namespace detail {
30
31class GroupImp : public std::enable_shared_from_this<GroupImp>, public Group
32{
33public:
36
37 GroupImp(std::string const& name_, Collector::ptr const& collector)
38 : m_name(name_), m_collector(collector)
39 {
40 }
41
42 ~GroupImp() = default;
43
44 std::string const&
45 name() const override
46 {
47 return m_name;
48 }
49
52 {
53 return m_name + "." + name;
54 }
55
56 Hook
57 make_hook(HookImpl::HandlerType const& handler) override
58 {
59 return m_collector->make_hook(handler);
60 }
61
63 make_counter(std::string const& name) override
64 {
65 return m_collector->make_counter(make_name(name));
66 }
67
68 Event
69 make_event(std::string const& name) override
70 {
71 return m_collector->make_event(make_name(name));
72 }
73
74 Gauge
75 make_gauge(std::string const& name) override
76 {
77 return m_collector->make_gauge(make_name(name));
78 }
79
80 Meter
81 make_meter(std::string const& name) override
82 {
83 return m_collector->make_meter(make_name(name));
84 }
85
86private:
89};
90
91//------------------------------------------------------------------------------
92
93class GroupsImp : public Groups
94{
95public:
96 using Items =
98
101
102 explicit GroupsImp(Collector::ptr const& collector) : m_collector(collector)
103 {
104 }
105
106 ~GroupsImp() = default;
107
108 Group::ptr const&
109 get(std::string const& name) override
110 {
112 m_items.emplace(name, Group::ptr()));
113 Group::ptr& group(result.first->second);
114 if (result.second)
115 group = std::make_shared<GroupImp>(name, m_collector);
116 return group;
117 }
118};
119
120} // namespace detail
121
122//------------------------------------------------------------------------------
123
124Groups::~Groups() = default;
125
128{
129 return std::make_unique<detail::GroupsImp>(collector);
130}
131
132} // namespace insight
133} // namespace beast
A metric for measuring an integral value.
Definition: Counter.h:39
A metric for reporting event timing.
Definition: Event.h:41
A metric for measuring an integral value.
Definition: Gauge.h:40
A collector front-end that manages a group of metrics.
Definition: Group.h:33
A container for managing a set of metric groups.
Definition: Groups.h:34
A reference to a handler for performing polled collection.
Definition: Hook.h:32
A metric for measuring an integral value.
Definition: Meter.h:38
std::string const m_name
Definition: Groups.cpp:34
Meter make_meter(std::string const &name) override
Create a meter with the specified name.
Definition: Groups.cpp:81
Hook make_hook(HookImpl::HandlerType const &handler) override
Definition: Groups.cpp:57
std::string const & name() const override
Returns the name of this group, for diagnostics.
Definition: Groups.cpp:45
GroupImp(std::string const &name_, Collector::ptr const &collector)
Definition: Groups.cpp:37
GroupImp & operator=(GroupImp const &)
Gauge make_gauge(std::string const &name) override
Create a gauge with the specified name.
Definition: Groups.cpp:75
std::string make_name(std::string const &name)
Definition: Groups.cpp:51
Counter make_counter(std::string const &name) override
Create a counter with the specified name.
Definition: Groups.cpp:63
Event make_event(std::string const &name) override
Create an event with the specified name.
Definition: Groups.cpp:69
GroupsImp(Collector::ptr const &collector)
Definition: Groups.cpp:102
Group::ptr const & get(std::string const &name) override
Find or create a new collector with a given name.
Definition: Groups.cpp:109
T emplace(T... args)
std::unique_ptr< Groups > make_Groups(Collector::ptr const &collector)
Create a group container that uses the specified collector.
Definition: Groups.cpp:127