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.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
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
19 * Copyright (C) 2016 ScyllaDB.
25 * \file metrics_registration.hh
26 * \brief holds the metric_groups definition needed by class that reports metrics
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.
34 * metric_groups _metrics
36 * void setup_metrics();
40 * To define the metrics, include in your source file metircs.hh
41 * @see metrics.hh for the definition for adding a metric.
49 class metric_groups_def;
50 struct metric_definition_impl;
51 class metric_groups_impl;
54 using group_name_type = sstring; /*!< A group of logically related metrics */
57 class metric_definition {
58 std::unique_ptr<impl::metric_definition_impl> _impl;
60 metric_definition(const impl::metric_definition_impl& impl) noexcept;
61 metric_definition(metric_definition&& m) noexcept;
64 friend impl::metric_groups_impl;
67 class metric_group_definition {
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();
78 * \brief holds the metric definition.
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
85 std::unique_ptr<impl::metric_groups_def> _impl;
87 metric_groups() noexcept;
88 metric_groups(metric_groups&&) = default;
89 virtual ~metric_groups();
90 metric_groups& operator=(metric_groups&&) = default;
92 * \brief add metrics belong to the same group in the constructor.
94 * combine the constructor with the add_group functionality.
96 metric_groups(std::initializer_list<metric_group_definition> mg);
99 * \brief add metrics belong to the same group.
101 * use the metrics creation functions to add metrics.
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")),
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", {...});
114 metric_groups& add_group(const group_name_type& name, const std::initializer_list<metric_definition>& l);
117 * \brief clear all metrics groups registrations.
124 * \brief hold a single metric group
125 * Initialization is done in the constructor or
126 * with a call to add_group
128 class metric_group : public metric_groups {
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;
137 * \brief add metrics belong to the same group in the constructor.
141 metric_group(const group_name_type& name, std::initializer_list<metric_definition> l);