]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/include/seastar/core/metrics_registration.hh
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / seastar / include / seastar / core / metrics_registration.hh
1 /*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18 /*
19 * Copyright (C) 2016 ScyllaDB.
20 */
21
22 #pragma once
23
24 /*!
25 * \file metrics_registration.hh
26 * \brief holds the metric_groups definition needed by class that reports metrics
27 *
28 * If class A needs to report metrics,
29 * typically you include metrics_registration.hh, in A header file and add to A:
30 * * metric_groups _metrics as a member
31 * * set_metrics() method that would be called in the constructor.
32 * \code
33 * class A {
34 * metric_groups _metrics
35 *
36 * void setup_metrics();
37 *
38 * };
39 * \endcode
40 * To define the metrics, include in your source file metircs.hh
41 * @see metrics.hh for the definition for adding a metric.
42 */
43
44 namespace seastar {
45
46 namespace metrics {
47
48 namespace impl {
49 class metric_groups_def;
50 struct metric_definition_impl;
51 class metric_groups_impl;
52 }
53
54 using group_name_type = sstring; /*!< A group of logically related metrics */
55 class metric_groups;
56
57 class metric_definition {
58 std::unique_ptr<impl::metric_definition_impl> _impl;
59 public:
60 metric_definition(const impl::metric_definition_impl& impl) noexcept;
61 metric_definition(metric_definition&& m) noexcept;
62 ~metric_definition();
63 friend metric_groups;
64 friend impl::metric_groups_impl;
65 };
66
67 class metric_group_definition {
68 public:
69 group_name_type name;
70 std::initializer_list<metric_definition> metrics;
71 metric_group_definition(const group_name_type& name, std::initializer_list<metric_definition> l);
72 metric_group_definition(const metric_group_definition&) = delete;
73 ~metric_group_definition();
74 };
75
76 /*!
77 * metric_groups
78 * \brief holds the metric definition.
79 *
80 * Add multiple metric groups definitions.
81 * Initialization can be done in the constructor or with a call to add_group
82 * @see metrics.hh for example and supported metrics
83 */
84 class metric_groups {
85 std::unique_ptr<impl::metric_groups_def> _impl;
86 public:
87 metric_groups() noexcept;
88 metric_groups(metric_groups&&) = default;
89 virtual ~metric_groups();
90 metric_groups& operator=(metric_groups&&) = default;
91 /*!
92 * \brief add metrics belong to the same group in the constructor.
93 *
94 * combine the constructor with the add_group functionality.
95 */
96 metric_groups(std::initializer_list<metric_group_definition> mg);
97
98 /*!
99 * \brief add metrics belong to the same group.
100 *
101 * use the metrics creation functions to add metrics.
102 *
103 * for example:
104 * _metrics.add_group("my_group", {
105 * make_counter("my_counter_name1", counter, description("my counter description")),
106 * make_counter("my_counter_name2", counter, description("my second counter description")),
107 * make_gauge("my_gauge_name1", gauge, description("my gauge description")),
108 * });
109 *
110 * metric name should be unique inside the group.
111 * you can change add_group calls like:
112 * _metrics.add_group("my group1", {...}).add_group("my group2", {...});
113 */
114 metric_groups& add_group(const group_name_type& name, const std::initializer_list<metric_definition>& l);
115
116 /*!
117 * \brief clear all metrics groups registrations.
118 */
119 void clear();
120 };
121
122
123 /*!
124 * \brief hold a single metric group
125 * Initialization is done in the constructor or
126 * with a call to add_group
127 */
128 class metric_group : public metric_groups {
129 public:
130 metric_group() noexcept;
131 metric_group(const metric_group&) = delete;
132 metric_group(metric_group&&) = default;
133 virtual ~metric_group();
134 metric_group& operator=(metric_group&&) = default;
135
136 /*!
137 * \brief add metrics belong to the same group in the constructor.
138 *
139 *
140 */
141 metric_group(const group_name_type& name, std::initializer_list<metric_definition> l);
142 };
143
144
145 }
146 }