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