rippled
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 <ripple/beast/hash/uhash.h>
21 #include <ripple/beast/insight/Group.h>
22 #include <ripple/beast/insight/Groups.h>
23 #include <memory>
24 #include <unordered_map>
25 
26 namespace beast {
27 namespace insight {
28 
29 namespace detail {
30 
31 class GroupImp : public std::enable_shared_from_this<GroupImp>, public Group
32 {
33 public:
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 
62  Counter
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 
86 private:
87  GroupImp&
88  operator=(GroupImp const&);
89 };
90 
91 //------------------------------------------------------------------------------
92 
93 class GroupsImp : public Groups
94 {
95 public:
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 
124 Groups::~Groups() = default;
125 
127 make_Groups(Collector::ptr const& collector)
128 {
129  return std::make_unique<detail::GroupsImp>(collector);
130 }
131 
132 } // namespace insight
133 } // namespace beast
beast::insight::detail::GroupImp
Definition: Groups.cpp:31
std::string
STL class.
std::shared_ptr< Collector >
beast::insight::Meter
A metric for measuring an integral value.
Definition: Meter.h:37
beast::insight::Counter
A metric for measuring an integral value.
Definition: Counter.h:38
beast::insight::detail::GroupImp::make_meter
Meter make_meter(std::string const &name) override
Create a meter with the specified name.
Definition: Groups.cpp:81
beast::insight::detail::GroupImp::make_counter
Counter make_counter(std::string const &name) override
Create a counter with the specified name.
Definition: Groups.cpp:63
std::pair
beast::insight::detail::GroupsImp
Definition: Groups.cpp:93
beast::insight::detail::GroupImp::name
std::string const & name() const override
Returns the name of this group, for diagnostics.
Definition: Groups.cpp:45
beast::insight::detail::GroupImp::make_event
Event make_event(std::string const &name) override
Create an event with the specified name.
Definition: Groups.cpp:69
beast::insight::detail::GroupImp::make_hook
Hook make_hook(HookImpl::HandlerType const &handler) override
Definition: Groups.cpp:57
std::unordered_map::emplace
T emplace(T... args)
beast::insight::Groups
A container for managing a set of metric groups.
Definition: Groups.h:33
std::function< void(void)>
beast::insight::detail::GroupImp::GroupImp
GroupImp(std::string const &name_, Collector::ptr const &collector)
Definition: Groups.cpp:37
beast::insight::detail::GroupImp::m_name
const std::string m_name
Definition: Groups.cpp:34
beast::insight::detail::GroupImp::operator=
GroupImp & operator=(GroupImp const &)
beast::insight::detail::GroupsImp::m_items
Items m_items
Definition: Groups.cpp:100
beast::insight::detail::GroupImp::make_gauge
Gauge make_gauge(std::string const &name) override
Create a gauge with the specified name.
Definition: Groups.cpp:75
beast::insight::detail::GroupImp::m_collector
Collector::ptr m_collector
Definition: Groups.cpp:35
beast::insight::Groups::~Groups
virtual ~Groups()=0
std::enable_shared_from_this
beast::insight::Event
A metric for reporting event timing.
Definition: Event.h:40
beast::insight::detail::GroupsImp::~GroupsImp
~GroupsImp()=default
beast::insight::make_Groups
std::unique_ptr< Groups > make_Groups(Collector::ptr const &collector)
Create a group container that uses the specified collector.
Definition: Groups.cpp:127
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:109
memory
beast::insight::Gauge
A metric for measuring an integral value.
Definition: Gauge.h:39
beast::insight::detail::GroupsImp::GroupsImp
GroupsImp(Collector::ptr const &collector)
Definition: Groups.cpp:102
beast::insight::detail::GroupImp::make_name
std::string make_name(std::string const &name)
Definition: Groups.cpp:51
beast::insight::Group
A collector front-end that manages a group of metrics.
Definition: Group.h:32
beast::uhash<>
std::unique_ptr
STL class.
unordered_map
beast::insight::Hook
A reference to a handler for performing polled collection.
Definition: Hook.h:31
beast::insight::detail::GroupsImp::m_collector
Collector::ptr m_collector
Definition: Groups.cpp:99
beast::insight::detail::GroupImp::~GroupImp
~GroupImp()=default
beast
Definition: base_uint.h:641