1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_MGR_MDS_PERF_METRIC_TYPES_H
5 #define CEPH_MGR_MDS_PERF_METRIC_TYPES_H
11 #include "include/denc.h"
12 #include "include/stringify.h"
14 #include "mds/mdstypes.h"
15 #include "mgr/Types.h"
17 typedef std::vector
<std::string
> MDSPerfMetricSubKey
; // array of regex match
18 typedef std::vector
<MDSPerfMetricSubKey
> MDSPerfMetricKey
;
20 enum class MDSPerfMetricSubKeyType
: uint8_t {
25 struct MDSPerfMetricSubKeyDescriptor
{
26 MDSPerfMetricSubKeyType type
= static_cast<MDSPerfMetricSubKeyType
>(-1);
27 std::string regex_str
;
30 bool is_supported() const {
32 case MDSPerfMetricSubKeyType::MDS_RANK
:
33 case MDSPerfMetricSubKeyType::CLIENT_ID
:
40 MDSPerfMetricSubKeyDescriptor() {
42 MDSPerfMetricSubKeyDescriptor(MDSPerfMetricSubKeyType type
, const std::string
®ex_str
)
43 : type(type
), regex_str(regex_str
) {
46 bool operator<(const MDSPerfMetricSubKeyDescriptor
&other
) const {
47 if (type
< other
.type
) {
50 if (type
> other
.type
) {
53 return regex_str
< other
.regex_str
;
56 DENC(MDSPerfMetricSubKeyDescriptor
, v
, p
) {
63 WRITE_CLASS_DENC(MDSPerfMetricSubKeyDescriptor
)
65 std::ostream
& operator<<(std::ostream
& os
, const MDSPerfMetricSubKeyDescriptor
&d
);
66 typedef std::vector
<MDSPerfMetricSubKeyDescriptor
> MDSPerfMetricKeyDescriptor
;
69 struct denc_traits
<MDSPerfMetricKeyDescriptor
> {
70 static constexpr bool supported
= true;
71 static constexpr bool bounded
= false;
72 static constexpr bool featured
= false;
73 static constexpr bool need_contiguous
= true;
74 static void bound_encode(const MDSPerfMetricKeyDescriptor
& v
, size_t& p
) {
75 p
+= sizeof(uint32_t);
76 const auto size
= v
.size();
83 static void encode(const MDSPerfMetricKeyDescriptor
& v
,
84 ceph::buffer::list::contiguous_appender
& p
) {
85 denc_varint(v
.size(), p
);
90 static void decode(MDSPerfMetricKeyDescriptor
& v
,
91 ceph::buffer::ptr::const_iterator
& p
) {
96 for (unsigned i
=0; i
< num
; ++i
) {
97 MDSPerfMetricSubKeyDescriptor d
;
99 if (!d
.is_supported()) {
104 d
.regex
= d
.regex_str
.c_str();
105 } catch (const std::regex_error
& e
) {
109 if (d
.regex
.mark_count() == 0) {
113 v
.push_back(std::move(d
));
118 enum class MDSPerformanceCounterType
: uint8_t {
120 READ_LATENCY_METRIC
= 1,
121 WRITE_LATENCY_METRIC
= 2,
122 METADATA_LATENCY_METRIC
= 3,
123 DENTRY_LEASE_METRIC
= 4,
124 OPENED_FILES_METRIC
= 5,
125 PINNED_ICAPS_METRIC
= 6,
126 OPENED_INODES_METRIC
= 7,
127 READ_IO_SIZES_METRIC
= 8,
128 WRITE_IO_SIZES_METRIC
= 9,
131 struct MDSPerformanceCounterDescriptor
{
132 MDSPerformanceCounterType type
= static_cast<MDSPerformanceCounterType
>(-1);
134 bool is_supported() const {
136 case MDSPerformanceCounterType::CAP_HIT_METRIC
:
137 case MDSPerformanceCounterType::READ_LATENCY_METRIC
:
138 case MDSPerformanceCounterType::WRITE_LATENCY_METRIC
:
139 case MDSPerformanceCounterType::METADATA_LATENCY_METRIC
:
140 case MDSPerformanceCounterType::DENTRY_LEASE_METRIC
:
141 case MDSPerformanceCounterType::OPENED_FILES_METRIC
:
142 case MDSPerformanceCounterType::PINNED_ICAPS_METRIC
:
143 case MDSPerformanceCounterType::OPENED_INODES_METRIC
:
144 case MDSPerformanceCounterType::READ_IO_SIZES_METRIC
:
145 case MDSPerformanceCounterType::WRITE_IO_SIZES_METRIC
:
152 MDSPerformanceCounterDescriptor() {
154 MDSPerformanceCounterDescriptor(MDSPerformanceCounterType type
) : type(type
) {
157 bool operator<(const MDSPerformanceCounterDescriptor
&other
) const {
158 return type
< other
.type
;
161 bool operator==(const MDSPerformanceCounterDescriptor
&other
) const {
162 return type
== other
.type
;
165 bool operator!=(const MDSPerformanceCounterDescriptor
&other
) const {
166 return type
!= other
.type
;
169 DENC(MDSPerformanceCounterDescriptor
, v
, p
) {
175 void pack_counter(const PerformanceCounter
&c
, ceph::buffer::list
*bl
) const;
176 void unpack_counter(ceph::buffer::list::const_iterator
& bl
, PerformanceCounter
*c
) const;
178 WRITE_CLASS_DENC(MDSPerformanceCounterDescriptor
)
180 std::ostream
& operator<<(std::ostream
&os
, const MDSPerformanceCounterDescriptor
&d
);
181 typedef std::vector
<MDSPerformanceCounterDescriptor
> MDSPerformanceCounterDescriptors
;
184 struct denc_traits
<MDSPerformanceCounterDescriptors
> {
185 static constexpr bool supported
= true;
186 static constexpr bool bounded
= false;
187 static constexpr bool featured
= false;
188 static constexpr bool need_contiguous
= true;
189 static void bound_encode(const MDSPerformanceCounterDescriptors
& v
, size_t& p
) {
190 p
+= sizeof(uint32_t);
191 const auto size
= v
.size();
194 denc(v
.front(), per
);
198 static void encode(const MDSPerformanceCounterDescriptors
& v
,
199 ceph::buffer::list::contiguous_appender
& p
) {
200 denc_varint(v
.size(), p
);
205 static void decode(MDSPerformanceCounterDescriptors
& v
,
206 ceph::buffer::ptr::const_iterator
& p
) {
211 for (unsigned i
=0; i
< num
; ++i
) {
212 MDSPerformanceCounterDescriptor d
;
214 if (d
.is_supported()) {
215 v
.push_back(std::move(d
));
221 struct MDSPerfMetricLimit
{
222 MDSPerformanceCounterDescriptor order_by
;
225 MDSPerfMetricLimit() {
227 MDSPerfMetricLimit(const MDSPerformanceCounterDescriptor
&order_by
, uint64_t max_count
)
228 : order_by(order_by
), max_count(max_count
) {
231 bool operator<(const MDSPerfMetricLimit
&other
) const {
232 if (order_by
!= other
.order_by
) {
233 return order_by
< other
.order_by
;
236 return max_count
< other
.max_count
;
239 DENC(MDSPerfMetricLimit
, v
, p
) {
242 denc(v
.max_count
, p
);
246 WRITE_CLASS_DENC(MDSPerfMetricLimit
)
248 std::ostream
&operator<<(std::ostream
&os
, const MDSPerfMetricLimit
&limit
);
249 typedef std::set
<MDSPerfMetricLimit
> MDSPerfMetricLimits
;
251 struct MDSPerfMetricQuery
{
252 MDSPerfMetricKeyDescriptor key_descriptor
;
253 MDSPerformanceCounterDescriptors performance_counter_descriptors
;
255 MDSPerfMetricQuery() {
257 MDSPerfMetricQuery(const MDSPerfMetricKeyDescriptor
&key_descriptor
,
258 const MDSPerformanceCounterDescriptors
&performance_counter_descriptors
)
259 : key_descriptor(key_descriptor
),
260 performance_counter_descriptors(performance_counter_descriptors
)
264 bool operator<(const MDSPerfMetricQuery
&other
) const {
265 if (key_descriptor
< other
.key_descriptor
) {
268 if (key_descriptor
> other
.key_descriptor
) {
271 return performance_counter_descriptors
< other
.performance_counter_descriptors
;
274 template <typename L
>
275 bool get_key(L
&& get_sub_key
, MDSPerfMetricKey
*key
) const {
276 for (auto &sub_key_descriptor
: key_descriptor
) {
277 MDSPerfMetricSubKey sub_key
;
278 if (!get_sub_key(sub_key_descriptor
, &sub_key
)) {
281 key
->push_back(sub_key
);
286 void get_performance_counter_descriptors(MDSPerformanceCounterDescriptors
*descriptors
) const {
287 *descriptors
= performance_counter_descriptors
;
290 template <typename L
>
291 void update_counters(L
&&update_counter
, PerformanceCounters
*counters
) const {
292 auto it
= counters
->begin();
293 for (auto &descriptor
: performance_counter_descriptors
) {
295 if (it
== counters
->end()) {
296 counters
->push_back(PerformanceCounter());
297 it
= std::prev(counters
->end());
299 update_counter(descriptor
, &(*it
));
304 DENC(MDSPerfMetricQuery
, v
, p
) {
306 denc(v
.key_descriptor
, p
);
307 denc(v
.performance_counter_descriptors
, p
);
311 void pack_counters(const PerformanceCounters
&counters
, ceph::buffer::list
*bl
) const;
313 WRITE_CLASS_DENC(MDSPerfMetricQuery
)
315 std::ostream
&operator<<(std::ostream
&os
, const MDSPerfMetricQuery
&query
);
317 struct MDSPerfCollector
: PerfCollector
{
318 std::map
<MDSPerfMetricKey
, PerformanceCounters
> counters
;
319 std::set
<mds_rank_t
> delayed_ranks
;
320 utime_t last_updated_mono
;
322 MDSPerfCollector(MetricQueryID query_id
)
323 : PerfCollector(query_id
) {
327 struct MDSPerfMetrics
{
328 MDSPerformanceCounterDescriptors performance_counter_descriptors
;
329 std::map
<MDSPerfMetricKey
, ceph::buffer::list
> group_packed_performance_counters
;
331 DENC(MDSPerfMetrics
, v
, p
) {
333 denc(v
.performance_counter_descriptors
, p
);
334 denc(v
.group_packed_performance_counters
, p
);
339 struct MDSPerfMetricReport
{
340 std::map
<MDSPerfMetricQuery
, MDSPerfMetrics
> reports
;
341 // set of active ranks that have delayed (stale) metrics
342 std::set
<mds_rank_t
> rank_metrics_delayed
;
344 DENC(MDSPerfMetricReport
, v
, p
) {
347 denc(v
.rank_metrics_delayed
, p
);
352 WRITE_CLASS_DENC(MDSPerfMetrics
)
353 WRITE_CLASS_DENC(MDSPerfMetricReport
)
355 #endif // CEPH_MGR_MDS_PERF_METRIC_TYPES_H