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/Collector.h>
22#include <xrpl/beast/insight/Counter.h>
23#include <xrpl/beast/insight/Event.h>
24#include <xrpl/beast/insight/Gauge.h>
25#include <xrpl/beast/insight/Group.h>
26#include <xrpl/beast/insight/Groups.h>
27#include <xrpl/beast/insight/Hook.h>
28#include <xrpl/beast/insight/HookImpl.h>
29#include <xrpl/beast/insight/Meter.h>
30
31#include <memory>
32#include <string>
33#include <unordered_map>
34#include <utility>
35
36namespace beast {
37namespace insight {
38
39namespace detail {
40
41class GroupImp : public std::enable_shared_from_this<GroupImp>, public Group
42{
43public:
46
47 GroupImp(std::string const& name_, Collector::ptr const& collector)
48 : m_name(name_), m_collector(collector)
49 {
50 }
51
52 ~GroupImp() = default;
53
54 std::string const&
55 name() const override
56 {
57 return m_name;
58 }
59
62 {
63 return m_name + "." + name;
64 }
65
66 Hook
67 make_hook(HookImpl::HandlerType const& handler) override
68 {
69 return m_collector->make_hook(handler);
70 }
71
73 make_counter(std::string const& name) override
74 {
75 return m_collector->make_counter(make_name(name));
76 }
77
78 Event
79 make_event(std::string const& name) override
80 {
81 return m_collector->make_event(make_name(name));
82 }
83
84 Gauge
85 make_gauge(std::string const& name) override
86 {
87 return m_collector->make_gauge(make_name(name));
88 }
89
90 Meter
91 make_meter(std::string const& name) override
92 {
93 return m_collector->make_meter(make_name(name));
94 }
95
96private:
99};
100
101//------------------------------------------------------------------------------
102
103class GroupsImp : public Groups
104{
105public:
106 using Items =
108
111
112 explicit GroupsImp(Collector::ptr const& collector) : m_collector(collector)
113 {
114 }
115
116 ~GroupsImp() = default;
117
118 Group::ptr const&
119 get(std::string const& name) override
120 {
122 m_items.emplace(name, Group::ptr()));
123 Group::ptr& group(result.first->second);
124 if (result.second)
125 group = std::make_shared<GroupImp>(name, m_collector);
126 return group;
127 }
128};
129
130} // namespace detail
131
132//------------------------------------------------------------------------------
133
134Groups::~Groups() = default;
135
138{
139 return std::make_unique<detail::GroupsImp>(collector);
140}
141
142} // namespace insight
143} // 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:44
Meter make_meter(std::string const &name) override
Create a meter with the specified name.
Definition: Groups.cpp:91
Hook make_hook(HookImpl::HandlerType const &handler) override
Definition: Groups.cpp:67
std::string const & name() const override
Returns the name of this group, for diagnostics.
Definition: Groups.cpp:55
GroupImp(std::string const &name_, Collector::ptr const &collector)
Definition: Groups.cpp:47
GroupImp & operator=(GroupImp const &)
Gauge make_gauge(std::string const &name) override
Create a gauge with the specified name.
Definition: Groups.cpp:85
std::string make_name(std::string const &name)
Definition: Groups.cpp:61
Counter make_counter(std::string const &name) override
Create a counter with the specified name.
Definition: Groups.cpp:73
Event make_event(std::string const &name) override
Create an event with the specified name.
Definition: Groups.cpp:79
GroupsImp(Collector::ptr const &collector)
Definition: Groups.cpp:112
Group::ptr const & get(std::string const &name) override
Find or create a new collector with a given name.
Definition: Groups.cpp:119
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:137