1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include <boost/algorithm/string.hpp>
8 #define dout_subsys ceph_subsys_mon
9 #include "common/debug.h"
10 #include "common/Clock.h"
11 #include "common/Formatter.h"
12 #include "global/global_context.h"
13 #include "include/ceph_features.h"
14 #include "include/stringify.h"
16 #include "osd/osd_types.h"
17 #include "osd/OSDMap.h"
18 #include <boost/range/adaptor/reversed.hpp>
20 #define dout_context g_ceph_context
27 using std::ostringstream
;
30 using std::stringstream
;
33 using ceph::bufferlist
;
34 using ceph::fixed_u_to_string
;
36 using TOPNSPC::common::cmd_getval
;
38 MEMPOOL_DEFINE_OBJECT_FACTORY(PGMapDigest
, pgmap_digest
, pgmap
);
39 MEMPOOL_DEFINE_OBJECT_FACTORY(PGMap
, pgmap
, pgmap
);
40 MEMPOOL_DEFINE_OBJECT_FACTORY(PGMap::Incremental
, pgmap_inc
, pgmap
);
43 // ---------------------
46 void PGMapDigest::encode(bufferlist
& bl
, uint64_t features
) const
48 // NOTE: see PGMap::encode_digest
50 if (!HAVE_FEATURE(features
, SERVER_MIMIC
)) {
52 } else if (!HAVE_FEATURE(features
, SERVER_NAUTILUS
)) {
55 ENCODE_START(v
, 1, bl
);
57 encode(num_pg_active
, bl
);
58 encode(num_pg_unknown
, bl
);
60 encode(pg_pool_sum
, bl
, features
);
61 encode(pg_sum
, bl
, features
);
62 encode(osd_sum
, bl
, features
);
64 encode(num_pg_by_state
, bl
);
66 uint32_t n
= num_pg_by_state
.size();
68 for (auto p
: num_pg_by_state
) {
69 encode((int32_t)p
.first
, bl
);
73 encode(num_pg_by_osd
, bl
);
74 encode(num_pg_by_pool
, bl
);
75 encode(osd_last_seq
, bl
);
76 encode(per_pool_sum_delta
, bl
, features
);
77 encode(per_pool_sum_deltas_stamps
, bl
);
78 encode(pg_sum_delta
, bl
, features
);
79 encode(stamp_delta
, bl
);
80 encode(avail_space_by_rule
, bl
);
82 encode(purged_snaps
, bl
);
85 encode(osd_sum_by_class
, bl
, features
);
90 void PGMapDigest::decode(bufferlist::const_iterator
& p
)
94 decode(num_pg_active
, p
);
95 decode(num_pg_unknown
, p
);
97 decode(pg_pool_sum
, p
);
101 decode(num_pg_by_state
, p
);
103 map
<int32_t, int32_t> nps
;
105 num_pg_by_state
.clear();
107 num_pg_by_state
[i
.first
] = i
.second
;
110 decode(num_pg_by_osd
, p
);
111 decode(num_pg_by_pool
, p
);
112 decode(osd_last_seq
, p
);
113 decode(per_pool_sum_delta
, p
);
114 decode(per_pool_sum_deltas_stamps
, p
);
115 decode(pg_sum_delta
, p
);
116 decode(stamp_delta
, p
);
117 decode(avail_space_by_rule
, p
);
119 decode(purged_snaps
, p
);
122 decode(osd_sum_by_class
, p
);
127 void PGMapDigest::dump(ceph::Formatter
*f
) const
129 f
->dump_unsigned("num_pg", num_pg
);
130 f
->dump_unsigned("num_pg_active", num_pg_active
);
131 f
->dump_unsigned("num_pg_unknown", num_pg_unknown
);
132 f
->dump_unsigned("num_osd", num_osd
);
133 f
->dump_object("pool_sum", pg_sum
);
134 f
->dump_object("osd_sum", osd_sum
);
136 f
->open_object_section("osd_sum_by_class");
137 for (auto& i
: osd_sum_by_class
) {
138 f
->dump_object(i
.first
.c_str(), i
.second
);
142 f
->open_array_section("pool_stats");
143 for (auto& p
: pg_pool_sum
) {
144 f
->open_object_section("pool_stat");
145 f
->dump_int("poolid", p
.first
);
146 auto q
= num_pg_by_pool
.find(p
.first
);
147 if (q
!= num_pg_by_pool
.end())
148 f
->dump_unsigned("num_pg", q
->second
);
153 f
->open_array_section("osd_stats");
155 // TODO: this isn't really correct since we can dump non-existent OSDs
156 // I dunno what osd_last_seq is set to in that case...
157 for (auto& p
: osd_last_seq
) {
158 f
->open_object_section("osd_stat");
159 f
->dump_int("osd", i
);
160 f
->dump_unsigned("seq", p
);
165 f
->open_array_section("num_pg_by_state");
166 for (auto& p
: num_pg_by_state
) {
167 f
->open_object_section("count");
168 f
->dump_string("state", pg_state_string(p
.first
));
169 f
->dump_unsigned("num", p
.second
);
173 f
->open_array_section("num_pg_by_osd");
174 for (auto& p
: num_pg_by_osd
) {
175 f
->open_object_section("count");
176 f
->dump_unsigned("osd", p
.first
);
177 f
->dump_unsigned("num_primary_pg", p
.second
.primary
);
178 f
->dump_unsigned("num_acting_pg", p
.second
.acting
);
179 f
->dump_unsigned("num_up_not_acting_pg", p
.second
.up_not_acting
);
183 f
->open_array_section("purged_snaps");
184 for (auto& j
: purged_snaps
) {
185 f
->open_object_section("pool");
186 f
->dump_int("pool", j
.first
);
187 f
->open_object_section("purged_snaps");
188 for (auto i
= j
.second
.begin(); i
!= j
.second
.end(); ++i
) {
189 f
->open_object_section("interval");
190 f
->dump_stream("start") << i
.get_start();
191 f
->dump_stream("length") << i
.get_len();
200 void PGMapDigest::generate_test_instances(list
<PGMapDigest
*>& ls
)
202 ls
.push_back(new PGMapDigest
);
205 inline std::string
percentify(const float& a
) {
206 std::stringstream ss
;
210 ss
<< std::fixed
<< std::setprecision(2) << a
;
214 void PGMapDigest::print_summary(ceph::Formatter
*f
, ostream
*out
) const
217 f
->open_array_section("pgs_by_state");
219 // list is descending numeric order (by count)
220 std::multimap
<int,uint64_t> state_by_count
; // count -> state
221 for (auto p
= num_pg_by_state
.begin();
222 p
!= num_pg_by_state
.end();
224 state_by_count
.insert(make_pair(p
->second
, p
->first
));
227 for (auto p
= state_by_count
.rbegin();
228 p
!= state_by_count
.rend();
231 f
->open_object_section("pgs_by_state_element");
232 f
->dump_string("state_name", pg_state_string(p
->second
));
233 f
->dump_unsigned("count", p
->first
);
241 f
->dump_unsigned("num_pgs", num_pg
);
242 f
->dump_unsigned("num_pools", pg_pool_sum
.size());
243 f
->dump_unsigned("num_objects", pg_sum
.stats
.sum
.num_objects
);
244 f
->dump_unsigned("data_bytes", pg_sum
.stats
.sum
.num_bytes
);
245 f
->dump_unsigned("bytes_used", osd_sum
.statfs
.get_used_raw());
246 f
->dump_unsigned("bytes_avail", osd_sum
.statfs
.available
);
247 f
->dump_unsigned("bytes_total", osd_sum
.statfs
.total
);
249 *out
<< " pools: " << pg_pool_sum
.size() << " pools, "
250 << num_pg
<< " pgs\n";
251 *out
<< " objects: " << si_u_t(pg_sum
.stats
.sum
.num_objects
) << " objects, "
252 << byte_u_t(pg_sum
.stats
.sum
.num_bytes
) << "\n";
254 << byte_u_t(osd_sum
.statfs
.get_used_raw()) << " used, "
255 << byte_u_t(osd_sum
.statfs
.available
) << " / "
256 << byte_u_t(osd_sum
.statfs
.total
) << " avail\n";
262 if (num_pg_unknown
> 0) {
263 float p
= (float)num_pg_unknown
/ (float)num_pg
;
265 f
->dump_float("unknown_pgs_ratio", p
);
268 snprintf(b
, sizeof(b
), "%.3lf", p
* 100.0);
269 *out
<< b
<< "% pgs unknown\n";
274 int num_pg_inactive
= num_pg
- num_pg_active
- num_pg_unknown
;
275 if (num_pg_inactive
> 0) {
276 float p
= (float)num_pg_inactive
/ (float)num_pg
;
278 f
->dump_float("inactive_pgs_ratio", p
);
284 snprintf(b
, sizeof(b
), "%.3f", p
* 100.0);
285 *out
<< b
<< "% pgs not active\n";
291 overall_recovery_summary(f
, &sl
);
292 if (!f
&& !sl
.empty()) {
293 for (auto p
= sl
.begin(); p
!= sl
.end(); ++p
) {
304 unsigned max_width
= 1;
305 for (auto p
= state_by_count
.rbegin(); p
!= state_by_count
.rend(); ++p
)
307 std::stringstream ss
;
309 max_width
= std::max
<size_t>(ss
.str().size(), max_width
);
312 for (auto p
= state_by_count
.rbegin(); p
!= state_by_count
.rend(); ++p
)
318 out
->setf(std::ios::left
);
319 *out
<< std::setw(max_width
) << p
->first
320 << " " << pg_state_string(p
->second
) << "\n";
321 out
->unsetf(std::ios::left
);
325 ostringstream ss_rec_io
;
326 overall_recovery_rate_summary(f
, &ss_rec_io
);
327 ostringstream ss_client_io
;
328 overall_client_io_rate_summary(f
, &ss_client_io
);
329 ostringstream ss_cache_io
;
330 overall_cache_io_rate_summary(f
, &ss_cache_io
);
332 if (!f
&& (ss_client_io
.str().length() || ss_rec_io
.str().length()
333 || ss_cache_io
.str().length())) {
338 if (!f
&& ss_client_io
.str().length())
339 *out
<< " client: " << ss_client_io
.str() << "\n";
340 if (!f
&& ss_rec_io
.str().length())
341 *out
<< " recovery: " << ss_rec_io
.str() << "\n";
342 if (!f
&& ss_cache_io
.str().length())
343 *out
<< " cache: " << ss_cache_io
.str() << "\n";
346 void PGMapDigest::print_oneline_summary(ceph::Formatter
*f
, ostream
*out
) const
348 std::stringstream ss
;
351 f
->open_array_section("num_pg_by_state");
352 for (auto p
= num_pg_by_state
.begin();
353 p
!= num_pg_by_state
.end();
356 f
->open_object_section("state");
357 f
->dump_string("name", pg_state_string(p
->first
));
358 f
->dump_unsigned("num", p
->second
);
361 if (p
!= num_pg_by_state
.begin())
363 ss
<< p
->second
<< " " << pg_state_string(p
->first
);
368 string states
= ss
.str();
370 *out
<< num_pg
<< " pgs: "
372 << byte_u_t(pg_sum
.stats
.sum
.num_bytes
) << " data, "
373 << byte_u_t(osd_sum
.statfs
.get_used()) << " used, "
374 << byte_u_t(osd_sum
.statfs
.available
) << " / "
375 << byte_u_t(osd_sum
.statfs
.total
) << " avail";
377 f
->dump_unsigned("num_pgs", num_pg
);
378 f
->dump_unsigned("num_bytes", pg_sum
.stats
.sum
.num_bytes
);
379 f
->dump_int("total_bytes", osd_sum
.statfs
.total
);
380 f
->dump_int("total_avail_bytes", osd_sum
.statfs
.available
);
381 f
->dump_int("total_used_bytes", osd_sum
.statfs
.get_used());
382 f
->dump_int("total_used_raw_bytes", osd_sum
.statfs
.get_used_raw());
385 // make non-negative; we can get negative values if osds send
386 // uncommitted stats and then "go backward" or if they are just
388 pool_stat_t pos_delta
= pg_sum_delta
;
390 if (pos_delta
.stats
.sum
.num_rd
||
391 pos_delta
.stats
.sum
.num_wr
) {
394 if (pos_delta
.stats
.sum
.num_rd
) {
395 int64_t rd
= (pos_delta
.stats
.sum
.num_rd_kb
<< 10) / (double)stamp_delta
;
397 *out
<< byte_u_t(rd
) << "/s rd, ";
399 f
->dump_unsigned("read_bytes_sec", rd
);
401 if (pos_delta
.stats
.sum
.num_wr
) {
402 int64_t wr
= (pos_delta
.stats
.sum
.num_wr_kb
<< 10) / (double)stamp_delta
;
404 *out
<< byte_u_t(wr
) << "/s wr, ";
406 f
->dump_unsigned("write_bytes_sec", wr
);
408 int64_t iops
= (pos_delta
.stats
.sum
.num_rd
+ pos_delta
.stats
.sum
.num_wr
) / (double)stamp_delta
;
410 *out
<< si_u_t(iops
) << " op/s";
412 f
->dump_unsigned("io_sec", iops
);
416 overall_recovery_summary(f
, &sl
);
418 for (auto p
= sl
.begin(); p
!= sl
.end(); ++p
)
420 std::stringstream ssr
;
421 overall_recovery_rate_summary(f
, &ssr
);
422 if (out
&& ssr
.str().length())
423 *out
<< "; " << ssr
.str() << " recovering";
426 void PGMapDigest::get_recovery_stats(
427 double *misplaced_ratio
,
428 double *degraded_ratio
,
429 double *inactive_pgs_ratio
,
430 double *unknown_pgs_ratio
) const
432 if (pg_sum
.stats
.sum
.num_objects_degraded
&&
433 pg_sum
.stats
.sum
.num_object_copies
> 0) {
434 *degraded_ratio
= (double)pg_sum
.stats
.sum
.num_objects_degraded
/
435 (double)pg_sum
.stats
.sum
.num_object_copies
;
439 if (pg_sum
.stats
.sum
.num_objects_misplaced
&&
440 pg_sum
.stats
.sum
.num_object_copies
> 0) {
441 *misplaced_ratio
= (double)pg_sum
.stats
.sum
.num_objects_misplaced
/
442 (double)pg_sum
.stats
.sum
.num_object_copies
;
444 *misplaced_ratio
= 0;
447 int num_pg_inactive
= num_pg
- num_pg_active
- num_pg_unknown
;
448 *inactive_pgs_ratio
= (double)num_pg_inactive
/ (double)num_pg
;
449 *unknown_pgs_ratio
= (double)num_pg_unknown
/ (double)num_pg
;
451 *inactive_pgs_ratio
= 0;
452 *unknown_pgs_ratio
= 0;
456 void PGMapDigest::recovery_summary(ceph::Formatter
*f
, list
<string
> *psl
,
457 const pool_stat_t
& pool_sum
) const
459 if (pool_sum
.stats
.sum
.num_objects_degraded
&& pool_sum
.stats
.sum
.num_object_copies
> 0) {
460 double pc
= (double)pool_sum
.stats
.sum
.num_objects_degraded
/
461 (double)pool_sum
.stats
.sum
.num_object_copies
* (double)100.0;
463 snprintf(b
, sizeof(b
), "%.3lf", pc
);
465 f
->dump_unsigned("degraded_objects", pool_sum
.stats
.sum
.num_objects_degraded
);
466 f
->dump_unsigned("degraded_total", pool_sum
.stats
.sum
.num_object_copies
);
467 f
->dump_float("degraded_ratio", pc
/ 100.0);
470 ss
<< pool_sum
.stats
.sum
.num_objects_degraded
471 << "/" << pool_sum
.stats
.sum
.num_object_copies
<< " objects degraded (" << b
<< "%)";
472 psl
->push_back(ss
.str());
475 if (pool_sum
.stats
.sum
.num_objects_misplaced
&& pool_sum
.stats
.sum
.num_object_copies
> 0) {
476 double pc
= (double)pool_sum
.stats
.sum
.num_objects_misplaced
/
477 (double)pool_sum
.stats
.sum
.num_object_copies
* (double)100.0;
479 snprintf(b
, sizeof(b
), "%.3lf", pc
);
481 f
->dump_unsigned("misplaced_objects", pool_sum
.stats
.sum
.num_objects_misplaced
);
482 f
->dump_unsigned("misplaced_total", pool_sum
.stats
.sum
.num_object_copies
);
483 f
->dump_float("misplaced_ratio", pc
/ 100.0);
486 ss
<< pool_sum
.stats
.sum
.num_objects_misplaced
487 << "/" << pool_sum
.stats
.sum
.num_object_copies
<< " objects misplaced (" << b
<< "%)";
488 psl
->push_back(ss
.str());
491 if (pool_sum
.stats
.sum
.num_objects_unfound
&& pool_sum
.stats
.sum
.num_objects
) {
492 double pc
= (double)pool_sum
.stats
.sum
.num_objects_unfound
/
493 (double)pool_sum
.stats
.sum
.num_objects
* (double)100.0;
495 snprintf(b
, sizeof(b
), "%.3lf", pc
);
497 f
->dump_unsigned("unfound_objects", pool_sum
.stats
.sum
.num_objects_unfound
);
498 f
->dump_unsigned("unfound_total", pool_sum
.stats
.sum
.num_objects
);
499 f
->dump_float("unfound_ratio", pc
/ 100.0);
502 ss
<< pool_sum
.stats
.sum
.num_objects_unfound
503 << "/" << pool_sum
.stats
.sum
.num_objects
<< " objects unfound (" << b
<< "%)";
504 psl
->push_back(ss
.str());
509 void PGMapDigest::recovery_rate_summary(ceph::Formatter
*f
, ostream
*out
,
510 const pool_stat_t
& delta_sum
,
511 utime_t delta_stamp
) const
513 // make non-negative; we can get negative values if osds send
514 // uncommitted stats and then "go backward" or if they are just
516 pool_stat_t pos_delta
= delta_sum
;
518 if (pos_delta
.stats
.sum
.num_objects_recovered
||
519 pos_delta
.stats
.sum
.num_bytes_recovered
||
520 pos_delta
.stats
.sum
.num_keys_recovered
) {
521 int64_t objps
= pos_delta
.stats
.sum
.num_objects_recovered
/ (double)delta_stamp
;
522 int64_t bps
= pos_delta
.stats
.sum
.num_bytes_recovered
/ (double)delta_stamp
;
523 int64_t kps
= pos_delta
.stats
.sum
.num_keys_recovered
/ (double)delta_stamp
;
525 f
->dump_int("recovering_objects_per_sec", objps
);
526 f
->dump_int("recovering_bytes_per_sec", bps
);
527 f
->dump_int("recovering_keys_per_sec", kps
);
528 f
->dump_int("num_objects_recovered", pos_delta
.stats
.sum
.num_objects_recovered
);
529 f
->dump_int("num_bytes_recovered", pos_delta
.stats
.sum
.num_bytes_recovered
);
530 f
->dump_int("num_keys_recovered", pos_delta
.stats
.sum
.num_keys_recovered
);
532 *out
<< byte_u_t(bps
) << "/s";
533 if (pos_delta
.stats
.sum
.num_keys_recovered
)
534 *out
<< ", " << si_u_t(kps
) << " keys/s";
535 *out
<< ", " << si_u_t(objps
) << " objects/s";
540 void PGMapDigest::overall_recovery_rate_summary(ceph::Formatter
*f
, ostream
*out
) const
542 recovery_rate_summary(f
, out
, pg_sum_delta
, stamp_delta
);
545 void PGMapDigest::overall_recovery_summary(ceph::Formatter
*f
, list
<string
> *psl
) const
547 recovery_summary(f
, psl
, pg_sum
);
550 void PGMapDigest::pool_recovery_rate_summary(ceph::Formatter
*f
, ostream
*out
,
551 uint64_t poolid
) const
553 auto p
= per_pool_sum_delta
.find(poolid
);
554 if (p
== per_pool_sum_delta
.end())
557 auto ts
= per_pool_sum_deltas_stamps
.find(p
->first
);
558 ceph_assert(ts
!= per_pool_sum_deltas_stamps
.end());
559 recovery_rate_summary(f
, out
, p
->second
.first
, ts
->second
);
562 void PGMapDigest::pool_recovery_summary(ceph::Formatter
*f
, list
<string
> *psl
,
563 uint64_t poolid
) const
565 auto p
= pg_pool_sum
.find(poolid
);
566 if (p
== pg_pool_sum
.end())
569 recovery_summary(f
, psl
, p
->second
);
572 void PGMapDigest::client_io_rate_summary(ceph::Formatter
*f
, ostream
*out
,
573 const pool_stat_t
& delta_sum
,
574 utime_t delta_stamp
) const
576 pool_stat_t pos_delta
= delta_sum
;
578 if (pos_delta
.stats
.sum
.num_rd
||
579 pos_delta
.stats
.sum
.num_wr
) {
580 if (pos_delta
.stats
.sum
.num_rd
) {
581 int64_t rd
= (pos_delta
.stats
.sum
.num_rd_kb
<< 10) / (double)delta_stamp
;
583 f
->dump_int("read_bytes_sec", rd
);
585 *out
<< byte_u_t(rd
) << "/s rd, ";
588 if (pos_delta
.stats
.sum
.num_wr
) {
589 int64_t wr
= (pos_delta
.stats
.sum
.num_wr_kb
<< 10) / (double)delta_stamp
;
591 f
->dump_int("write_bytes_sec", wr
);
593 *out
<< byte_u_t(wr
) << "/s wr, ";
596 int64_t iops_rd
= pos_delta
.stats
.sum
.num_rd
/ (double)delta_stamp
;
597 int64_t iops_wr
= pos_delta
.stats
.sum
.num_wr
/ (double)delta_stamp
;
599 f
->dump_int("read_op_per_sec", iops_rd
);
600 f
->dump_int("write_op_per_sec", iops_wr
);
602 *out
<< si_u_t(iops_rd
) << " op/s rd, " << si_u_t(iops_wr
) << " op/s wr";
607 void PGMapDigest::overall_client_io_rate_summary(ceph::Formatter
*f
, ostream
*out
) const
609 client_io_rate_summary(f
, out
, pg_sum_delta
, stamp_delta
);
612 void PGMapDigest::pool_client_io_rate_summary(ceph::Formatter
*f
, ostream
*out
,
613 uint64_t poolid
) const
615 auto p
= per_pool_sum_delta
.find(poolid
);
616 if (p
== per_pool_sum_delta
.end())
619 auto ts
= per_pool_sum_deltas_stamps
.find(p
->first
);
620 ceph_assert(ts
!= per_pool_sum_deltas_stamps
.end());
621 client_io_rate_summary(f
, out
, p
->second
.first
, ts
->second
);
624 void PGMapDigest::cache_io_rate_summary(ceph::Formatter
*f
, ostream
*out
,
625 const pool_stat_t
& delta_sum
,
626 utime_t delta_stamp
) const
628 pool_stat_t pos_delta
= delta_sum
;
630 bool have_output
= false;
632 if (pos_delta
.stats
.sum
.num_flush
) {
633 int64_t flush
= (pos_delta
.stats
.sum
.num_flush_kb
<< 10) / (double)delta_stamp
;
635 f
->dump_int("flush_bytes_sec", flush
);
637 *out
<< byte_u_t(flush
) << "/s flush";
641 if (pos_delta
.stats
.sum
.num_evict
) {
642 int64_t evict
= (pos_delta
.stats
.sum
.num_evict_kb
<< 10) / (double)delta_stamp
;
644 f
->dump_int("evict_bytes_sec", evict
);
648 *out
<< byte_u_t(evict
) << "/s evict";
652 if (pos_delta
.stats
.sum
.num_promote
) {
653 int64_t promote
= pos_delta
.stats
.sum
.num_promote
/ (double)delta_stamp
;
655 f
->dump_int("promote_op_per_sec", promote
);
659 *out
<< si_u_t(promote
) << " op/s promote";
663 if (pos_delta
.stats
.sum
.num_flush_mode_low
) {
665 f
->dump_int("num_flush_mode_low", pos_delta
.stats
.sum
.num_flush_mode_low
);
669 *out
<< si_u_t(pos_delta
.stats
.sum
.num_flush_mode_low
) << " PGs flushing";
673 if (pos_delta
.stats
.sum
.num_flush_mode_high
) {
675 f
->dump_int("num_flush_mode_high", pos_delta
.stats
.sum
.num_flush_mode_high
);
679 *out
<< si_u_t(pos_delta
.stats
.sum
.num_flush_mode_high
) << " PGs flushing (high)";
683 if (pos_delta
.stats
.sum
.num_evict_mode_some
) {
685 f
->dump_int("num_evict_mode_some", pos_delta
.stats
.sum
.num_evict_mode_some
);
689 *out
<< si_u_t(pos_delta
.stats
.sum
.num_evict_mode_some
) << " PGs evicting";
693 if (pos_delta
.stats
.sum
.num_evict_mode_full
) {
695 f
->dump_int("num_evict_mode_full", pos_delta
.stats
.sum
.num_evict_mode_full
);
699 *out
<< si_u_t(pos_delta
.stats
.sum
.num_evict_mode_full
) << " PGs evicting (full)";
704 void PGMapDigest::overall_cache_io_rate_summary(ceph::Formatter
*f
, ostream
*out
) const
706 cache_io_rate_summary(f
, out
, pg_sum_delta
, stamp_delta
);
709 void PGMapDigest::pool_cache_io_rate_summary(ceph::Formatter
*f
, ostream
*out
,
710 uint64_t poolid
) const
712 auto p
= per_pool_sum_delta
.find(poolid
);
713 if (p
== per_pool_sum_delta
.end())
716 auto ts
= per_pool_sum_deltas_stamps
.find(p
->first
);
717 ceph_assert(ts
!= per_pool_sum_deltas_stamps
.end());
718 cache_io_rate_summary(f
, out
, p
->second
.first
, ts
->second
);
721 ceph_statfs
PGMapDigest::get_statfs(OSDMap
&osdmap
,
722 boost::optional
<int64_t> data_pool
) const
726 object_stat_sum_t sum
;
729 auto i
= pg_pool_sum
.find(*data_pool
);
730 if (i
!= pg_pool_sum
.end()) {
731 sum
= i
->second
.stats
.sum
;
737 statfs
.kb_used
= (sum
.num_bytes
>> 10);
738 statfs
.kb_avail
= get_pool_free_space(osdmap
, *data_pool
) >> 10;
739 statfs
.num_objects
= sum
.num_objects
;
740 statfs
.kb
= statfs
.kb_used
+ statfs
.kb_avail
;
743 statfs
.kb
= osd_sum
.statfs
.kb();
744 statfs
.kb_used
= osd_sum
.statfs
.kb_used_raw();
745 statfs
.kb_avail
= osd_sum
.statfs
.kb_avail();
746 statfs
.num_objects
= pg_sum
.stats
.sum
.num_objects
;
752 void PGMapDigest::dump_pool_stats_full(
753 const OSDMap
&osd_map
,
761 f
->open_array_section("pools");
763 tbl
.define_column("POOL", TextTable::LEFT
, TextTable::LEFT
);
764 tbl
.define_column("ID", TextTable::RIGHT
, TextTable::RIGHT
);
765 tbl
.define_column("PGS", TextTable::RIGHT
, TextTable::RIGHT
);
766 tbl
.define_column("STORED", TextTable::RIGHT
, TextTable::RIGHT
);
768 tbl
.define_column("(DATA)", TextTable::RIGHT
, TextTable::RIGHT
);
769 tbl
.define_column("(OMAP)", TextTable::RIGHT
, TextTable::RIGHT
);
771 tbl
.define_column("OBJECTS", TextTable::RIGHT
, TextTable::RIGHT
);
772 tbl
.define_column("USED", TextTable::RIGHT
, TextTable::RIGHT
);
774 tbl
.define_column("(DATA)", TextTable::RIGHT
, TextTable::RIGHT
);
775 tbl
.define_column("(OMAP)", TextTable::RIGHT
, TextTable::RIGHT
);
777 tbl
.define_column("%USED", TextTable::RIGHT
, TextTable::RIGHT
);
778 tbl
.define_column("MAX AVAIL", TextTable::RIGHT
, TextTable::RIGHT
);
781 tbl
.define_column("QUOTA OBJECTS", TextTable::RIGHT
, TextTable::RIGHT
);
782 tbl
.define_column("QUOTA BYTES", TextTable::RIGHT
, TextTable::RIGHT
);
783 tbl
.define_column("DIRTY", TextTable::RIGHT
, TextTable::RIGHT
);
784 tbl
.define_column("USED COMPR", TextTable::RIGHT
, TextTable::RIGHT
);
785 tbl
.define_column("UNDER COMPR", TextTable::RIGHT
, TextTable::RIGHT
);
789 map
<int,uint64_t> avail_by_rule
;
790 for (auto p
= osd_map
.get_pools().begin();
791 p
!= osd_map
.get_pools().end(); ++p
) {
792 int64_t pool_id
= p
->first
;
793 if ((pool_id
< 0) || (pg_pool_sum
.count(pool_id
) == 0))
796 const string
& pool_name
= osd_map
.get_pool_name(pool_id
);
797 auto pool_pg_num
= osd_map
.get_pg_num(pool_id
);
798 const pool_stat_t
&stat
= pg_pool_sum
.at(pool_id
);
800 const pg_pool_t
*pool
= osd_map
.get_pg_pool(pool_id
);
801 int ruleno
= osd_map
.crush
->find_rule(pool
->get_crush_rule(),
805 if (avail_by_rule
.count(ruleno
) == 0) {
806 // FIXME: we don't guarantee avail_space_by_rule is up-to-date before this function is invoked
807 avail
= get_rule_avail(ruleno
);
810 avail_by_rule
[ruleno
] = avail
;
812 avail
= avail_by_rule
[ruleno
];
815 f
->open_object_section("pool");
816 f
->dump_string("name", pool_name
);
817 f
->dump_int("id", pool_id
);
818 f
->open_object_section("stats");
824 float raw_used_rate
= osd_map
.pool_raw_used_rate(pool_id
);
825 bool per_pool
= use_per_pool_stats();
826 bool per_pool_omap
= use_per_pool_omap_stats();
827 dump_object_stat_sum(tbl
, f
, stat
, avail
, raw_used_rate
, verbose
, per_pool
,
828 per_pool_omap
, pool
);
830 f
->close_section(); // stats
831 f
->close_section(); // pool
833 tbl
<< TextTable::endrow
;
839 ceph_assert(ss
!= nullptr);
840 *ss
<< "--- POOLS ---\n";
845 void PGMapDigest::dump_cluster_stats(stringstream
*ss
,
850 f
->open_object_section("stats");
851 f
->dump_int("total_bytes", osd_sum
.statfs
.total
);
852 f
->dump_int("total_avail_bytes", osd_sum
.statfs
.available
);
853 f
->dump_int("total_used_bytes", osd_sum
.statfs
.get_used());
854 f
->dump_int("total_used_raw_bytes", osd_sum
.statfs
.get_used_raw());
855 f
->dump_float("total_used_raw_ratio", osd_sum
.statfs
.get_used_raw_ratio());
856 f
->dump_unsigned("num_osds", osd_sum
.num_osds
);
857 f
->dump_unsigned("num_per_pool_osds", osd_sum
.num_per_pool_osds
);
858 f
->dump_unsigned("num_per_pool_omap_osds", osd_sum
.num_per_pool_omap_osds
);
860 f
->open_object_section("stats_by_class");
861 for (auto& i
: osd_sum_by_class
) {
862 f
->open_object_section(i
.first
.c_str());
863 f
->dump_int("total_bytes", i
.second
.statfs
.total
);
864 f
->dump_int("total_avail_bytes", i
.second
.statfs
.available
);
865 f
->dump_int("total_used_bytes", i
.second
.statfs
.get_used());
866 f
->dump_int("total_used_raw_bytes", i
.second
.statfs
.get_used_raw());
867 f
->dump_float("total_used_raw_ratio",
868 i
.second
.statfs
.get_used_raw_ratio());
873 ceph_assert(ss
!= nullptr);
875 tbl
.define_column("CLASS", TextTable::LEFT
, TextTable::LEFT
);
876 tbl
.define_column("SIZE", TextTable::RIGHT
, TextTable::RIGHT
);
877 tbl
.define_column("AVAIL", TextTable::RIGHT
, TextTable::RIGHT
);
878 tbl
.define_column("USED", TextTable::RIGHT
, TextTable::RIGHT
);
879 tbl
.define_column("RAW USED", TextTable::RIGHT
, TextTable::RIGHT
);
880 tbl
.define_column("%RAW USED", TextTable::RIGHT
, TextTable::RIGHT
);
883 for (auto& i
: osd_sum_by_class
) {
885 tbl
<< stringify(byte_u_t(i
.second
.statfs
.total
))
886 << stringify(byte_u_t(i
.second
.statfs
.available
))
887 << stringify(byte_u_t(i
.second
.statfs
.get_used()))
888 << stringify(byte_u_t(i
.second
.statfs
.get_used_raw()))
889 << percentify(i
.second
.statfs
.get_used_raw_ratio()*100.0)
890 << TextTable::endrow
;
893 tbl
<< stringify(byte_u_t(osd_sum
.statfs
.total
))
894 << stringify(byte_u_t(osd_sum
.statfs
.available
))
895 << stringify(byte_u_t(osd_sum
.statfs
.get_used()))
896 << stringify(byte_u_t(osd_sum
.statfs
.get_used_raw()))
897 << percentify(osd_sum
.statfs
.get_used_raw_ratio()*100.0)
898 << TextTable::endrow
;
900 *ss
<< "--- RAW STORAGE ---\n";
905 void PGMapDigest::dump_object_stat_sum(
906 TextTable
&tbl
, ceph::Formatter
*f
,
907 const pool_stat_t
&pool_stat
, uint64_t avail
,
908 float raw_used_rate
, bool verbose
, bool per_pool
, bool per_pool_omap
,
909 const pg_pool_t
*pool
)
911 const object_stat_sum_t
&sum
= pool_stat
.stats
.sum
;
912 const store_statfs_t statfs
= pool_stat
.store_stats
;
914 if (sum
.num_object_copies
> 0) {
915 raw_used_rate
*= (float)(sum
.num_object_copies
- sum
.num_objects_degraded
) / sum
.num_object_copies
;
918 uint64_t used_data_bytes
= pool_stat
.get_allocated_data_bytes(per_pool
);
919 uint64_t used_omap_bytes
= pool_stat
.get_allocated_omap_bytes(per_pool_omap
);
920 uint64_t used_bytes
= used_data_bytes
+ used_omap_bytes
;
923 // note avail passed in is raw_avail, calc raw_used here.
926 used
/= used
+ avail
;
927 } else if (used_bytes
) {
930 auto avail_res
= raw_used_rate
? avail
/ raw_used_rate
: 0;
931 // an approximation for actually stored user data
932 auto stored_data_normalized
= pool_stat
.get_user_data_bytes(
933 raw_used_rate
, per_pool
);
934 auto stored_omap_normalized
= pool_stat
.get_user_omap_bytes(
935 raw_used_rate
, per_pool_omap
);
936 auto stored_normalized
= stored_data_normalized
+ stored_omap_normalized
;
937 // same, amplied by replication or EC
938 auto stored_raw
= stored_normalized
* raw_used_rate
;
940 f
->dump_int("stored", stored_normalized
);
942 f
->dump_int("stored_data", stored_data_normalized
);
943 f
->dump_int("stored_omap", stored_omap_normalized
);
945 f
->dump_int("objects", sum
.num_objects
);
946 f
->dump_int("kb_used", shift_round_up(used_bytes
, 10));
947 f
->dump_int("bytes_used", used_bytes
);
949 f
->dump_int("data_bytes_used", used_data_bytes
);
950 f
->dump_int("omap_bytes_used", used_omap_bytes
);
952 f
->dump_float("percent_used", used
);
953 f
->dump_unsigned("max_avail", avail_res
);
955 f
->dump_int("quota_objects", pool
->quota_max_objects
);
956 f
->dump_int("quota_bytes", pool
->quota_max_bytes
);
957 f
->dump_int("dirty", sum
.num_objects_dirty
);
958 f
->dump_int("rd", sum
.num_rd
);
959 f
->dump_int("rd_bytes", sum
.num_rd_kb
* 1024ull);
960 f
->dump_int("wr", sum
.num_wr
);
961 f
->dump_int("wr_bytes", sum
.num_wr_kb
* 1024ull);
962 f
->dump_int("compress_bytes_used", statfs
.data_compressed_allocated
);
963 f
->dump_int("compress_under_bytes", statfs
.data_compressed_original
);
964 // Stored by user amplified by replication
965 f
->dump_int("stored_raw", stored_raw
);
966 f
->dump_unsigned("avail_raw", avail
);
969 tbl
<< stringify(byte_u_t(stored_normalized
));
971 tbl
<< stringify(byte_u_t(stored_data_normalized
));
972 tbl
<< stringify(byte_u_t(stored_omap_normalized
));
974 tbl
<< stringify(si_u_t(sum
.num_objects
));
975 tbl
<< stringify(byte_u_t(used_bytes
));
977 tbl
<< stringify(byte_u_t(used_data_bytes
));
978 tbl
<< stringify(byte_u_t(used_omap_bytes
));
980 tbl
<< percentify(used
*100);
981 tbl
<< stringify(byte_u_t(avail_res
));
983 if (pool
->quota_max_objects
== 0)
986 tbl
<< stringify(si_u_t(pool
->quota_max_objects
));
988 if (pool
->quota_max_bytes
== 0)
991 tbl
<< stringify(byte_u_t(pool
->quota_max_bytes
));
993 tbl
<< stringify(si_u_t(sum
.num_objects_dirty
))
994 << stringify(byte_u_t(statfs
.data_compressed_allocated
))
995 << stringify(byte_u_t(statfs
.data_compressed_original
))
1001 int64_t PGMapDigest::get_pool_free_space(const OSDMap
&osd_map
,
1002 int64_t poolid
) const
1004 const pg_pool_t
*pool
= osd_map
.get_pg_pool(poolid
);
1005 int ruleno
= osd_map
.crush
->find_rule(pool
->get_crush_rule(),
1009 avail
= get_rule_avail(ruleno
);
1013 return avail
/ osd_map
.pool_raw_used_rate(poolid
);
1016 int64_t PGMap::get_rule_avail(const OSDMap
& osdmap
, int ruleno
) const
1019 int r
= osdmap
.crush
->get_rule_weight_osd_map(ruleno
, &wm
);
1027 float fratio
= osdmap
.get_full_ratio();
1030 for (auto p
= wm
.begin(); p
!= wm
.end(); ++p
) {
1031 auto osd_info
= osd_stat
.find(p
->first
);
1032 if (osd_info
!= osd_stat
.end()) {
1033 if (osd_info
->second
.statfs
.total
== 0 || p
->second
== 0) {
1034 // osd must be out, hence its stats have been zeroed
1035 // (unless we somehow managed to have a disk with size 0...)
1037 // (p->second == 0), if osd weight is 0, no need to
1038 // calculate proj below.
1041 double unusable
= (double)osd_info
->second
.statfs
.kb() *
1043 double avail
= std::max(0.0, (double)osd_info
->second
.statfs
.kb_avail() - unusable
);
1045 int64_t proj
= (int64_t)(avail
/ (double)p
->second
);
1046 if (min
< 0 || proj
< min
) {
1050 if (osdmap
.is_up(p
->first
)) {
1051 // This is a level 4 rather than an error, because we might have
1052 // only just started, and not received the first stats message yet.
1053 dout(4) << "OSD " << p
->first
<< " is up, but has no stats" << dendl
;
1060 void PGMap::get_rules_avail(const OSDMap
& osdmap
,
1061 std::map
<int,int64_t> *avail_map
) const
1064 for (auto p
: osdmap
.get_pools()) {
1065 int64_t pool_id
= p
.first
;
1066 if ((pool_id
< 0) || (pg_pool_sum
.count(pool_id
) == 0))
1068 const pg_pool_t
*pool
= osdmap
.get_pg_pool(pool_id
);
1069 int ruleno
= osdmap
.crush
->find_rule(pool
->get_crush_rule(),
1072 if (avail_map
->count(ruleno
) == 0)
1073 (*avail_map
)[ruleno
] = get_rule_avail(osdmap
, ruleno
);
1077 // ---------------------
1080 void PGMap::Incremental::dump(ceph::Formatter
*f
) const
1082 f
->dump_unsigned("version", version
);
1083 f
->dump_stream("stamp") << stamp
;
1084 f
->dump_unsigned("osdmap_epoch", osdmap_epoch
);
1085 f
->dump_unsigned("pg_scan_epoch", pg_scan
);
1087 f
->open_array_section("pg_stat_updates");
1088 for (auto p
= pg_stat_updates
.begin(); p
!= pg_stat_updates
.end(); ++p
) {
1089 f
->open_object_section("pg_stat");
1090 f
->dump_stream("pgid") << p
->first
;
1096 f
->open_array_section("osd_stat_updates");
1097 for (auto p
= osd_stat_updates
.begin(); p
!= osd_stat_updates
.end(); ++p
) {
1098 f
->open_object_section("osd_stat");
1099 f
->dump_int("osd", p
->first
);
1104 f
->open_array_section("pool_statfs_updates");
1105 for (auto p
= pool_statfs_updates
.begin(); p
!= pool_statfs_updates
.end(); ++p
) {
1106 f
->open_object_section("pool_statfs");
1107 f
->dump_stream("poolid/osd") << p
->first
;
1113 f
->open_array_section("osd_stat_removals");
1114 for (auto p
= osd_stat_rm
.begin(); p
!= osd_stat_rm
.end(); ++p
)
1115 f
->dump_int("osd", *p
);
1118 f
->open_array_section("pg_removals");
1119 for (auto p
= pg_remove
.begin(); p
!= pg_remove
.end(); ++p
)
1120 f
->dump_stream("pgid") << *p
;
1124 void PGMap::Incremental::generate_test_instances(list
<PGMap::Incremental
*>& o
)
1126 o
.push_back(new Incremental
);
1127 o
.push_back(new Incremental
);
1128 o
.back()->version
= 1;
1129 o
.back()->stamp
= utime_t(123,345);
1130 o
.push_back(new Incremental
);
1131 o
.back()->version
= 2;
1132 o
.back()->pg_stat_updates
[pg_t(1,2)] = pg_stat_t();
1133 o
.back()->osd_stat_updates
[5] = osd_stat_t();
1134 o
.push_back(new Incremental
);
1135 o
.back()->version
= 3;
1136 o
.back()->osdmap_epoch
= 1;
1137 o
.back()->pg_scan
= 2;
1138 o
.back()->pg_stat_updates
[pg_t(4,5)] = pg_stat_t();
1139 o
.back()->osd_stat_updates
[6] = osd_stat_t();
1140 o
.back()->pg_remove
.insert(pg_t(1,2));
1141 o
.back()->osd_stat_rm
.insert(5);
1142 o
.back()->pool_statfs_updates
[std::make_pair(1234,4)] = store_statfs_t();
1147 void PGMap::apply_incremental(CephContext
*cct
, const Incremental
& inc
)
1149 ceph_assert(inc
.version
== version
+1);
1152 pool_stat_t pg_sum_old
= pg_sum
;
1153 mempool::pgmap::unordered_map
<int32_t, pool_stat_t
> pg_pool_sum_old
;
1154 pg_pool_sum_old
= pg_pool_sum
;
1156 for (auto p
= inc
.pg_stat_updates
.begin();
1157 p
!= inc
.pg_stat_updates
.end();
1159 const pg_t
&update_pg(p
->first
);
1160 auto update_pool
= update_pg
.pool();
1161 const pg_stat_t
&update_stat(p
->second
);
1163 auto pg_stat_iter
= pg_stat
.find(update_pg
);
1164 pool_stat_t
&pool_sum_ref
= pg_pool_sum
[update_pool
];
1165 if (pg_stat_iter
== pg_stat
.end()) {
1166 pg_stat
.insert(make_pair(update_pg
, update_stat
));
1168 stat_pg_sub(update_pg
, pg_stat_iter
->second
);
1169 pool_sum_ref
.sub(pg_stat_iter
->second
);
1170 pg_stat_iter
->second
= update_stat
;
1172 stat_pg_add(update_pg
, update_stat
);
1173 pool_sum_ref
.add(update_stat
);
1176 for (auto p
= inc
.pool_statfs_updates
.begin();
1177 p
!= inc
.pool_statfs_updates
.end();
1179 auto update_pool
= p
->first
.first
;
1180 auto update_osd
= p
->first
.second
;
1181 auto& statfs_inc
= p
->second
;
1183 auto pool_statfs_iter
=
1184 pool_statfs
.find(std::make_pair(update_pool
, update_osd
));
1185 if (pg_pool_sum
.count(update_pool
)) {
1186 pool_stat_t
&pool_sum_ref
= pg_pool_sum
[update_pool
];
1187 if (pool_statfs_iter
== pool_statfs
.end()) {
1188 pool_statfs
.emplace(std::make_pair(update_pool
, update_osd
), statfs_inc
);
1190 pool_sum_ref
.sub(pool_statfs_iter
->second
);
1191 pool_statfs_iter
->second
= statfs_inc
;
1193 pool_sum_ref
.add(statfs_inc
);
1197 for (auto p
= inc
.get_osd_stat_updates().begin();
1198 p
!= inc
.get_osd_stat_updates().end();
1201 const osd_stat_t
&new_stats(p
->second
);
1203 auto t
= osd_stat
.find(osd
);
1204 if (t
== osd_stat
.end()) {
1205 osd_stat
.insert(make_pair(osd
, new_stats
));
1207 stat_osd_sub(t
->first
, t
->second
);
1208 t
->second
= new_stats
;
1210 stat_osd_add(osd
, new_stats
);
1212 set
<int64_t> deleted_pools
;
1213 for (auto p
= inc
.pg_remove
.begin();
1214 p
!= inc
.pg_remove
.end();
1216 const pg_t
&removed_pg(*p
);
1217 auto s
= pg_stat
.find(removed_pg
);
1218 bool pool_erased
= false;
1219 if (s
!= pg_stat
.end()) {
1220 pool_erased
= stat_pg_sub(removed_pg
, s
->second
);
1222 // decrease pool stats if pg was removed
1223 auto pool_stats_it
= pg_pool_sum
.find(removed_pg
.pool());
1224 if (pool_stats_it
!= pg_pool_sum
.end()) {
1225 pool_stats_it
->second
.sub(s
->second
);
1230 deleted_pools
.insert(removed_pg
.pool());
1235 for (auto p
= inc
.get_osd_stat_rm().begin();
1236 p
!= inc
.get_osd_stat_rm().end();
1238 auto t
= osd_stat
.find(*p
);
1239 if (t
!= osd_stat
.end()) {
1240 stat_osd_sub(t
->first
, t
->second
);
1243 for (auto i
= pool_statfs
.begin(); i
!= pool_statfs
.end(); ++i
) {
1244 if (i
->first
.second
== *p
) {
1245 pg_pool_sum
[i
->first
.first
].sub(i
->second
);
1246 pool_statfs
.erase(i
);
1251 // skip calculating delta while sum was not synchronized
1252 if (!stamp
.is_zero() && !pg_sum_old
.stats
.sum
.is_zero()) {
1254 delta_t
= inc
.stamp
;
1256 // calculate a delta, and average over the last 2 deltas.
1257 pool_stat_t d
= pg_sum
;
1258 d
.stats
.sub(pg_sum_old
.stats
);
1259 pg_sum_deltas
.push_back(make_pair(d
, delta_t
));
1260 stamp_delta
+= delta_t
;
1261 pg_sum_delta
.stats
.add(d
.stats
);
1262 auto smooth_intervals
=
1263 cct
? cct
->_conf
.get_val
<uint64_t>("mon_stat_smooth_intervals") : 1;
1264 while (pg_sum_deltas
.size() > smooth_intervals
) {
1265 pg_sum_delta
.stats
.sub(pg_sum_deltas
.front().first
.stats
);
1266 stamp_delta
-= pg_sum_deltas
.front().second
;
1267 pg_sum_deltas
.pop_front();
1272 update_pool_deltas(cct
, inc
.stamp
, pg_pool_sum_old
);
1274 for (auto p
: deleted_pools
) {
1276 dout(20) << " deleted pool " << p
<< dendl
;
1280 if (inc
.osdmap_epoch
)
1281 last_osdmap_epoch
= inc
.osdmap_epoch
;
1283 last_pg_scan
= inc
.pg_scan
;
1286 void PGMap::calc_stats()
1292 pg_pool_sum
.clear();
1293 num_pg_by_pool
.clear();
1295 pg_sum
= pool_stat_t();
1296 osd_sum
= osd_stat_t();
1297 osd_sum_by_class
.clear();
1298 num_pg_by_state
.clear();
1299 num_pg_by_pool_state
.clear();
1300 num_pg_by_osd
.clear();
1302 for (auto p
= pg_stat
.begin();
1306 stat_pg_add(pg
, p
->second
);
1307 pg_pool_sum
[pg
.pool()].add(p
->second
);
1309 for (auto p
= pool_statfs
.begin();
1310 p
!= pool_statfs
.end();
1312 auto pool
= p
->first
.first
;
1313 pg_pool_sum
[pool
].add(p
->second
);
1315 for (auto p
= osd_stat
.begin();
1316 p
!= osd_stat
.end();
1318 stat_osd_add(p
->first
, p
->second
);
1321 void PGMap::stat_pg_add(const pg_t
&pgid
, const pg_stat_t
&s
,
1324 auto pool
= pgid
.pool();
1328 num_pg_by_state
[s
.state
]++;
1329 num_pg_by_pool_state
[pgid
.pool()][s
.state
]++;
1330 num_pg_by_pool
[pool
]++;
1332 if ((s
.state
& PG_STATE_CREATING
) &&
1333 s
.parent_split_bits
== 0) {
1334 creating_pgs
.insert(pgid
);
1335 if (s
.acting_primary
>= 0) {
1336 creating_pgs_by_osd_epoch
[s
.acting_primary
][s
.mapping_epoch
].insert(pgid
);
1340 if (s
.state
& PG_STATE_ACTIVE
) {
1350 for (auto p
= s
.blocked_by
.begin();
1351 p
!= s
.blocked_by
.end();
1353 ++blocked_by_sum
[*p
];
1356 for (auto p
= s
.acting
.begin(); p
!= s
.acting
.end(); ++p
) {
1357 pg_by_osd
[*p
].insert(pgid
);
1358 num_pg_by_osd
[*p
].acting
++;
1360 for (auto p
= s
.up
.begin(); p
!= s
.up
.end(); ++p
) {
1361 auto& t
= pg_by_osd
[*p
];
1362 if (t
.find(pgid
) == t
.end()) {
1364 num_pg_by_osd
[*p
].up_not_acting
++;
1368 if (s
.up_primary
>= 0) {
1369 num_pg_by_osd
[s
.up_primary
].primary
++;
1373 bool PGMap::stat_pg_sub(const pg_t
&pgid
, const pg_stat_t
&s
,
1376 bool pool_erased
= false;
1380 int end
= --num_pg_by_state
[s
.state
];
1381 ceph_assert(end
>= 0);
1383 num_pg_by_state
.erase(s
.state
);
1384 if (--num_pg_by_pool_state
[pgid
.pool()][s
.state
] == 0) {
1385 num_pg_by_pool_state
[pgid
.pool()].erase(s
.state
);
1387 end
= --num_pg_by_pool
[pgid
.pool()];
1392 if ((s
.state
& PG_STATE_CREATING
) &&
1393 s
.parent_split_bits
== 0) {
1394 creating_pgs
.erase(pgid
);
1395 if (s
.acting_primary
>= 0) {
1396 map
<epoch_t
,set
<pg_t
> >& r
= creating_pgs_by_osd_epoch
[s
.acting_primary
];
1397 r
[s
.mapping_epoch
].erase(pgid
);
1398 if (r
[s
.mapping_epoch
].empty())
1399 r
.erase(s
.mapping_epoch
);
1401 creating_pgs_by_osd_epoch
.erase(s
.acting_primary
);
1405 if (s
.state
& PG_STATE_ACTIVE
) {
1415 for (auto p
= s
.blocked_by
.begin();
1416 p
!= s
.blocked_by
.end();
1418 auto q
= blocked_by_sum
.find(*p
);
1419 ceph_assert(q
!= blocked_by_sum
.end());
1422 blocked_by_sum
.erase(q
);
1425 set
<int32_t> actingset
;
1426 for (auto p
= s
.acting
.begin(); p
!= s
.acting
.end(); ++p
) {
1427 actingset
.insert(*p
);
1428 auto& oset
= pg_by_osd
[*p
];
1431 pg_by_osd
.erase(*p
);
1432 auto it
= num_pg_by_osd
.find(*p
);
1433 if (it
!= num_pg_by_osd
.end() && it
->second
.acting
> 0)
1434 it
->second
.acting
--;
1436 for (auto p
= s
.up
.begin(); p
!= s
.up
.end(); ++p
) {
1437 auto& oset
= pg_by_osd
[*p
];
1440 pg_by_osd
.erase(*p
);
1441 if (actingset
.count(*p
))
1443 auto it
= num_pg_by_osd
.find(*p
);
1444 if (it
!= num_pg_by_osd
.end() && it
->second
.up_not_acting
> 0)
1445 it
->second
.up_not_acting
--;
1448 if (s
.up_primary
>= 0) {
1449 auto it
= num_pg_by_osd
.find(s
.up_primary
);
1450 if (it
!= num_pg_by_osd
.end() && it
->second
.primary
> 0)
1451 it
->second
.primary
--;
1456 void PGMap::calc_purged_snaps()
1458 purged_snaps
.clear();
1459 set
<int64_t> unknown
;
1460 for (auto& i
: pg_stat
) {
1461 if (i
.second
.state
== 0) {
1462 unknown
.insert(i
.first
.pool());
1463 purged_snaps
.erase(i
.first
.pool());
1465 } else if (unknown
.count(i
.first
.pool())) {
1468 auto j
= purged_snaps
.find(i
.first
.pool());
1469 if (j
== purged_snaps
.end()) {
1471 purged_snaps
[i
.first
.pool()] = i
.second
.purged_snaps
;
1473 j
->second
.intersection_of(i
.second
.purged_snaps
);
1478 void PGMap::calc_osd_sum_by_class(const OSDMap
& osdmap
)
1480 osd_sum_by_class
.clear();
1481 for (auto& i
: osd_stat
) {
1482 const char *class_name
= osdmap
.crush
->get_item_class(i
.first
);
1484 osd_sum_by_class
[class_name
].add(i
.second
);
1489 void PGMap::stat_osd_add(int osd
, const osd_stat_t
&s
)
1493 if (osd
>= (int)osd_last_seq
.size()) {
1494 osd_last_seq
.resize(osd
+ 1);
1496 osd_last_seq
[osd
] = s
.seq
;
1499 void PGMap::stat_osd_sub(int osd
, const osd_stat_t
&s
)
1503 ceph_assert(osd
< (int)osd_last_seq
.size());
1504 osd_last_seq
[osd
] = 0;
1507 void PGMap::encode_digest(const OSDMap
& osdmap
,
1508 bufferlist
& bl
, uint64_t features
)
1510 get_rules_avail(osdmap
, &avail_space_by_rule
);
1511 calc_osd_sum_by_class(osdmap
);
1512 calc_purged_snaps();
1513 PGMapDigest::encode(bl
, features
);
1516 void PGMap::encode(bufferlist
&bl
, uint64_t features
) const
1518 ENCODE_START(8, 8, bl
);
1519 encode(version
, bl
);
1520 encode(pg_stat
, bl
);
1521 encode(osd_stat
, bl
, features
);
1522 encode(last_osdmap_epoch
, bl
);
1523 encode(last_pg_scan
, bl
);
1525 encode(pool_statfs
, bl
, features
);
1529 void PGMap::decode(bufferlist::const_iterator
&bl
)
1531 DECODE_START(8, bl
);
1532 decode(version
, bl
);
1533 decode(pg_stat
, bl
);
1534 decode(osd_stat
, bl
);
1535 decode(last_osdmap_epoch
, bl
);
1536 decode(last_pg_scan
, bl
);
1538 decode(pool_statfs
, bl
);
1544 void PGMap::dump(ceph::Formatter
*f
, bool with_net
) const
1547 dump_pg_stats(f
, false);
1549 dump_osd_stats(f
, with_net
);
1552 void PGMap::dump_basic(ceph::Formatter
*f
) const
1554 f
->dump_unsigned("version", version
);
1555 f
->dump_stream("stamp") << stamp
;
1556 f
->dump_unsigned("last_osdmap_epoch", last_osdmap_epoch
);
1557 f
->dump_unsigned("last_pg_scan", last_pg_scan
);
1559 f
->open_object_section("pg_stats_sum");
1563 f
->open_object_section("osd_stats_sum");
1570 void PGMap::dump_delta(ceph::Formatter
*f
) const
1572 f
->open_object_section("pg_stats_delta");
1573 pg_sum_delta
.dump(f
);
1574 f
->dump_stream("stamp_delta") << stamp_delta
;
1578 void PGMap::dump_pg_stats(ceph::Formatter
*f
, bool brief
) const
1580 f
->open_array_section("pg_stats");
1581 for (auto i
= pg_stat
.begin();
1584 f
->open_object_section("pg_stat");
1585 f
->dump_stream("pgid") << i
->first
;
1587 i
->second
.dump_brief(f
);
1595 void PGMap::dump_pool_stats(ceph::Formatter
*f
) const
1597 f
->open_array_section("pool_stats");
1598 for (auto p
= pg_pool_sum
.begin();
1599 p
!= pg_pool_sum
.end();
1601 f
->open_object_section("pool_stat");
1602 f
->dump_int("poolid", p
->first
);
1603 auto q
= num_pg_by_pool
.find(p
->first
);
1604 if (q
!= num_pg_by_pool
.end())
1605 f
->dump_unsigned("num_pg", q
->second
);
1612 void PGMap::dump_osd_stats(ceph::Formatter
*f
, bool with_net
) const
1614 f
->open_array_section("osd_stats");
1615 for (auto q
= osd_stat
.begin();
1616 q
!= osd_stat
.end();
1618 f
->open_object_section("osd_stat");
1619 f
->dump_int("osd", q
->first
);
1620 q
->second
.dump(f
, with_net
);
1625 f
->open_array_section("pool_statfs");
1626 for (auto& p
: pool_statfs
) {
1627 f
->open_object_section("item");
1628 f
->dump_int("poolid", p
.first
.first
);
1629 f
->dump_int("osd", p
.first
.second
);
1636 void PGMap::dump_osd_ping_times(ceph::Formatter
*f
) const
1638 f
->open_array_section("osd_ping_times");
1639 for (auto& [osd
, stat
] : osd_stat
) {
1640 f
->open_object_section("osd_ping_time");
1641 f
->dump_int("osd", osd
);
1642 stat
.dump_ping_time(f
);
1648 void PGMap::dump_pg_stats_plain(
1650 const mempool::pgmap::unordered_map
<pg_t
, pg_stat_t
>& pg_stats
,
1656 tab
.define_column("PG_STAT", TextTable::LEFT
, TextTable::LEFT
);
1657 tab
.define_column("STATE", TextTable::LEFT
, TextTable::RIGHT
);
1658 tab
.define_column("UP", TextTable::LEFT
, TextTable::RIGHT
);
1659 tab
.define_column("UP_PRIMARY", TextTable::LEFT
, TextTable::RIGHT
);
1660 tab
.define_column("ACTING", TextTable::LEFT
, TextTable::RIGHT
);
1661 tab
.define_column("ACTING_PRIMARY", TextTable::LEFT
, TextTable::RIGHT
);
1664 tab
.define_column("PG_STAT", TextTable::LEFT
, TextTable::LEFT
);
1665 tab
.define_column("OBJECTS", TextTable::LEFT
, TextTable::RIGHT
);
1666 tab
.define_column("MISSING_ON_PRIMARY", TextTable::LEFT
, TextTable::RIGHT
);
1667 tab
.define_column("DEGRADED", TextTable::LEFT
, TextTable::RIGHT
);
1668 tab
.define_column("MISPLACED", TextTable::LEFT
, TextTable::RIGHT
);
1669 tab
.define_column("UNFOUND", TextTable::LEFT
, TextTable::RIGHT
);
1670 tab
.define_column("BYTES", TextTable::LEFT
, TextTable::RIGHT
);
1671 tab
.define_column("OMAP_BYTES*", TextTable::LEFT
, TextTable::RIGHT
);
1672 tab
.define_column("OMAP_KEYS*", TextTable::LEFT
, TextTable::RIGHT
);
1673 tab
.define_column("LOG", TextTable::LEFT
, TextTable::RIGHT
);
1674 tab
.define_column("DISK_LOG", TextTable::LEFT
, TextTable::RIGHT
);
1675 tab
.define_column("STATE", TextTable::LEFT
, TextTable::RIGHT
);
1676 tab
.define_column("STATE_STAMP", TextTable::LEFT
, TextTable::RIGHT
);
1677 tab
.define_column("VERSION", TextTable::LEFT
, TextTable::RIGHT
);
1678 tab
.define_column("REPORTED", TextTable::LEFT
, TextTable::RIGHT
);
1679 tab
.define_column("UP", TextTable::LEFT
, TextTable::RIGHT
);
1680 tab
.define_column("UP_PRIMARY", TextTable::LEFT
, TextTable::RIGHT
);
1681 tab
.define_column("ACTING", TextTable::LEFT
, TextTable::RIGHT
);
1682 tab
.define_column("ACTING_PRIMARY", TextTable::LEFT
, TextTable::RIGHT
);
1683 tab
.define_column("LAST_SCRUB", TextTable::LEFT
, TextTable::RIGHT
);
1684 tab
.define_column("SCRUB_STAMP", TextTable::LEFT
, TextTable::RIGHT
);
1685 tab
.define_column("LAST_DEEP_SCRUB", TextTable::LEFT
, TextTable::RIGHT
);
1686 tab
.define_column("DEEP_SCRUB_STAMP", TextTable::LEFT
, TextTable::RIGHT
);
1687 tab
.define_column("SNAPTRIMQ_LEN", TextTable::LEFT
, TextTable::RIGHT
);
1690 for (auto i
= pg_stats
.begin();
1691 i
!= pg_stats
.end(); ++i
) {
1692 const pg_stat_t
&st(i
->second
);
1695 << pg_state_string(st
.state
)
1699 << st
.acting_primary
1700 << TextTable::endrow
;
1702 ostringstream reported
;
1703 reported
<< st
.reported_epoch
<< ":" << st
.reported_seq
;
1706 << st
.stats
.sum
.num_objects
1707 << st
.stats
.sum
.num_objects_missing_on_primary
1708 << st
.stats
.sum
.num_objects_degraded
1709 << st
.stats
.sum
.num_objects_misplaced
1710 << st
.stats
.sum
.num_objects_unfound
1711 << st
.stats
.sum
.num_bytes
1712 << st
.stats
.sum
.num_omap_bytes
1713 << st
.stats
.sum
.num_omap_keys
1715 << st
.ondisk_log_size
1716 << pg_state_string(st
.state
)
1720 << pg_vector_string(st
.up
)
1722 << pg_vector_string(st
.acting
)
1723 << st
.acting_primary
1725 << st
.last_scrub_stamp
1726 << st
.last_deep_scrub
1727 << st
.last_deep_scrub_stamp
1729 << TextTable::endrow
;
1736 void PGMap::dump(ostream
& ss
) const
1739 dump_pg_stats(ss
, false);
1740 dump_pool_stats(ss
, false);
1741 dump_pg_sum_stats(ss
, false);
1745 void PGMap::dump_basic(ostream
& ss
) const
1747 ss
<< "version " << version
<< std::endl
;
1748 ss
<< "stamp " << stamp
<< std::endl
;
1749 ss
<< "last_osdmap_epoch " << last_osdmap_epoch
<< std::endl
;
1750 ss
<< "last_pg_scan " << last_pg_scan
<< std::endl
;
1753 void PGMap::dump_pg_stats(ostream
& ss
, bool brief
) const
1755 dump_pg_stats_plain(ss
, pg_stat
, brief
);
1758 void PGMap::dump_pool_stats(ostream
& ss
, bool header
) const
1763 tab
.define_column("POOLID", TextTable::LEFT
, TextTable::LEFT
);
1764 tab
.define_column("OBJECTS", TextTable::LEFT
, TextTable::RIGHT
);
1765 tab
.define_column("MISSING_ON_PRIMARY", TextTable::LEFT
, TextTable::RIGHT
);
1766 tab
.define_column("DEGRADED", TextTable::LEFT
, TextTable::RIGHT
);
1767 tab
.define_column("MISPLACED", TextTable::LEFT
, TextTable::RIGHT
);
1768 tab
.define_column("UNFOUND", TextTable::LEFT
, TextTable::RIGHT
);
1769 tab
.define_column("BYTES", TextTable::LEFT
, TextTable::RIGHT
);
1770 tab
.define_column("OMAP_BYTES*", TextTable::LEFT
, TextTable::RIGHT
);
1771 tab
.define_column("OMAP_KEYS*", TextTable::LEFT
, TextTable::RIGHT
);
1772 tab
.define_column("LOG", TextTable::LEFT
, TextTable::RIGHT
);
1773 tab
.define_column("DISK_LOG", TextTable::LEFT
, TextTable::RIGHT
);
1775 tab
.define_column("", TextTable::LEFT
, TextTable::LEFT
);
1776 tab
.define_column("", TextTable::LEFT
, TextTable::RIGHT
);
1777 tab
.define_column("", TextTable::LEFT
, TextTable::RIGHT
);
1778 tab
.define_column("", TextTable::LEFT
, TextTable::RIGHT
);
1779 tab
.define_column("", TextTable::LEFT
, TextTable::RIGHT
);
1780 tab
.define_column("", TextTable::LEFT
, TextTable::RIGHT
);
1781 tab
.define_column("", TextTable::LEFT
, TextTable::RIGHT
);
1782 tab
.define_column("", TextTable::LEFT
, TextTable::RIGHT
);
1783 tab
.define_column("", TextTable::LEFT
, TextTable::RIGHT
);
1784 tab
.define_column("", TextTable::LEFT
, TextTable::RIGHT
);
1785 tab
.define_column("", TextTable::LEFT
, TextTable::RIGHT
);
1788 for (auto p
= pg_pool_sum
.begin();
1789 p
!= pg_pool_sum
.end();
1792 << p
->second
.stats
.sum
.num_objects
1793 << p
->second
.stats
.sum
.num_objects_missing_on_primary
1794 << p
->second
.stats
.sum
.num_objects_degraded
1795 << p
->second
.stats
.sum
.num_objects_misplaced
1796 << p
->second
.stats
.sum
.num_objects_unfound
1797 << p
->second
.stats
.sum
.num_bytes
1798 << p
->second
.stats
.sum
.num_omap_bytes
1799 << p
->second
.stats
.sum
.num_omap_keys
1800 << p
->second
.log_size
1801 << p
->second
.ondisk_log_size
1802 << TextTable::endrow
;
1808 void PGMap::dump_pg_sum_stats(ostream
& ss
, bool header
) const
1813 tab
.define_column("PG_STAT", TextTable::LEFT
, TextTable::LEFT
);
1814 tab
.define_column("OBJECTS", TextTable::LEFT
, TextTable::RIGHT
);
1815 tab
.define_column("MISSING_ON_PRIMARY", TextTable::LEFT
, TextTable::RIGHT
);
1816 tab
.define_column("DEGRADED", TextTable::LEFT
, TextTable::RIGHT
);
1817 tab
.define_column("MISPLACED", TextTable::LEFT
, TextTable::RIGHT
);
1818 tab
.define_column("UNFOUND", TextTable::LEFT
, TextTable::RIGHT
);
1819 tab
.define_column("BYTES", TextTable::LEFT
, TextTable::RIGHT
);
1820 tab
.define_column("OMAP_BYTES*", TextTable::LEFT
, TextTable::RIGHT
);
1821 tab
.define_column("OMAP_KEYS*", TextTable::LEFT
, TextTable::RIGHT
);
1822 tab
.define_column("LOG", TextTable::LEFT
, TextTable::RIGHT
);
1823 tab
.define_column("DISK_LOG", TextTable::LEFT
, TextTable::RIGHT
);
1825 tab
.define_column("", TextTable::LEFT
, TextTable::LEFT
);
1826 tab
.define_column("", TextTable::LEFT
, TextTable::RIGHT
);
1827 tab
.define_column("", TextTable::LEFT
, TextTable::RIGHT
);
1828 tab
.define_column("", TextTable::LEFT
, TextTable::RIGHT
);
1829 tab
.define_column("", TextTable::LEFT
, TextTable::RIGHT
);
1830 tab
.define_column("", TextTable::LEFT
, TextTable::RIGHT
);
1831 tab
.define_column("", TextTable::LEFT
, TextTable::RIGHT
);
1832 tab
.define_column("", TextTable::LEFT
, TextTable::RIGHT
);
1833 tab
.define_column("", TextTable::LEFT
, TextTable::RIGHT
);
1834 tab
.define_column("", TextTable::LEFT
, TextTable::RIGHT
);
1835 tab
.define_column("", TextTable::LEFT
, TextTable::RIGHT
);
1839 << pg_sum
.stats
.sum
.num_objects
1840 << pg_sum
.stats
.sum
.num_objects_missing_on_primary
1841 << pg_sum
.stats
.sum
.num_objects_degraded
1842 << pg_sum
.stats
.sum
.num_objects_misplaced
1843 << pg_sum
.stats
.sum
.num_objects_unfound
1844 << pg_sum
.stats
.sum
.num_bytes
1845 << pg_sum
.stats
.sum
.num_omap_bytes
1846 << pg_sum
.stats
.sum
.num_omap_keys
1848 << pg_sum
.ondisk_log_size
1849 << TextTable::endrow
;
1854 void PGMap::dump_osd_stats(ostream
& ss
) const
1858 tab
.define_column("OSD_STAT", TextTable::LEFT
, TextTable::LEFT
);
1859 tab
.define_column("USED", TextTable::LEFT
, TextTable::RIGHT
);
1860 tab
.define_column("AVAIL", TextTable::LEFT
, TextTable::RIGHT
);
1861 tab
.define_column("USED_RAW", TextTable::LEFT
, TextTable::RIGHT
);
1862 tab
.define_column("TOTAL", TextTable::LEFT
, TextTable::RIGHT
);
1863 tab
.define_column("HB_PEERS", TextTable::LEFT
, TextTable::RIGHT
);
1864 tab
.define_column("PG_SUM", TextTable::LEFT
, TextTable::RIGHT
);
1865 tab
.define_column("PRIMARY_PG_SUM", TextTable::LEFT
, TextTable::RIGHT
);
1867 for (auto p
= osd_stat
.begin();
1868 p
!= osd_stat
.end();
1871 << byte_u_t(p
->second
.statfs
.get_used())
1872 << byte_u_t(p
->second
.statfs
.available
)
1873 << byte_u_t(p
->second
.statfs
.get_used_raw())
1874 << byte_u_t(p
->second
.statfs
.total
)
1875 << p
->second
.hb_peers
1876 << get_num_pg_by_osd(p
->first
)
1877 << get_num_primary_pg_by_osd(p
->first
)
1878 << TextTable::endrow
;
1882 << byte_u_t(osd_sum
.statfs
.get_used())
1883 << byte_u_t(osd_sum
.statfs
.available
)
1884 << byte_u_t(osd_sum
.statfs
.get_used_raw())
1885 << byte_u_t(osd_sum
.statfs
.total
)
1886 << TextTable::endrow
;
1891 void PGMap::dump_osd_sum_stats(ostream
& ss
) const
1895 tab
.define_column("OSD_STAT", TextTable::LEFT
, TextTable::LEFT
);
1896 tab
.define_column("USED", TextTable::LEFT
, TextTable::RIGHT
);
1897 tab
.define_column("AVAIL", TextTable::LEFT
, TextTable::RIGHT
);
1898 tab
.define_column("USED_RAW", TextTable::LEFT
, TextTable::RIGHT
);
1899 tab
.define_column("TOTAL", TextTable::LEFT
, TextTable::RIGHT
);
1902 << byte_u_t(osd_sum
.statfs
.get_used())
1903 << byte_u_t(osd_sum
.statfs
.available
)
1904 << byte_u_t(osd_sum
.statfs
.get_used_raw())
1905 << byte_u_t(osd_sum
.statfs
.total
)
1906 << TextTable::endrow
;
1911 void PGMap::get_stuck_stats(
1912 int types
, const utime_t cutoff
,
1913 mempool::pgmap::unordered_map
<pg_t
, pg_stat_t
>& stuck_pgs
) const
1915 ceph_assert(types
!= 0);
1916 for (auto i
= pg_stat
.begin();
1919 utime_t val
= cutoff
; // don't care about >= cutoff so that is infinity
1921 if ((types
& STUCK_INACTIVE
) && !(i
->second
.state
& PG_STATE_ACTIVE
)) {
1922 if (i
->second
.last_active
< val
)
1923 val
= i
->second
.last_active
;
1926 if ((types
& STUCK_UNCLEAN
) && !(i
->second
.state
& PG_STATE_CLEAN
)) {
1927 if (i
->second
.last_clean
< val
)
1928 val
= i
->second
.last_clean
;
1931 if ((types
& STUCK_DEGRADED
) && (i
->second
.state
& PG_STATE_DEGRADED
)) {
1932 if (i
->second
.last_undegraded
< val
)
1933 val
= i
->second
.last_undegraded
;
1936 if ((types
& STUCK_UNDERSIZED
) && (i
->second
.state
& PG_STATE_UNDERSIZED
)) {
1937 if (i
->second
.last_fullsized
< val
)
1938 val
= i
->second
.last_fullsized
;
1941 if ((types
& STUCK_STALE
) && (i
->second
.state
& PG_STATE_STALE
)) {
1942 if (i
->second
.last_unstale
< val
)
1943 val
= i
->second
.last_unstale
;
1946 // val is now the earliest any of the requested stuck states began
1948 stuck_pgs
[i
->first
] = i
->second
;
1953 bool PGMap::get_stuck_counts(const utime_t cutoff
, map
<string
, int>& note
) const
1961 for (auto i
= pg_stat
.begin();
1964 if (! (i
->second
.state
& PG_STATE_ACTIVE
)) {
1965 if (i
->second
.last_active
< cutoff
)
1968 if (! (i
->second
.state
& PG_STATE_CLEAN
)) {
1969 if (i
->second
.last_clean
< cutoff
)
1972 if (i
->second
.state
& PG_STATE_DEGRADED
) {
1973 if (i
->second
.last_undegraded
< cutoff
)
1976 if (i
->second
.state
& PG_STATE_UNDERSIZED
) {
1977 if (i
->second
.last_fullsized
< cutoff
)
1980 if (i
->second
.state
& PG_STATE_STALE
) {
1981 if (i
->second
.last_unstale
< cutoff
)
1987 note
["stuck inactive"] = inactive
;
1990 note
["stuck unclean"] = unclean
;
1993 note
["stuck undersized"] = undersized
;
1996 note
["stuck degraded"] = degraded
;
1999 note
["stuck stale"] = stale
;
2001 return inactive
|| unclean
|| undersized
|| degraded
|| stale
;
2004 void PGMap::dump_stuck(ceph::Formatter
*f
, int types
, utime_t cutoff
) const
2006 mempool::pgmap::unordered_map
<pg_t
, pg_stat_t
> stuck_pg_stats
;
2007 get_stuck_stats(types
, cutoff
, stuck_pg_stats
);
2008 f
->open_array_section("stuck_pg_stats");
2009 for (auto i
= stuck_pg_stats
.begin();
2010 i
!= stuck_pg_stats
.end();
2012 f
->open_object_section("pg_stat");
2013 f
->dump_stream("pgid") << i
->first
;
2020 void PGMap::dump_stuck_plain(ostream
& ss
, int types
, utime_t cutoff
) const
2022 mempool::pgmap::unordered_map
<pg_t
, pg_stat_t
> stuck_pg_stats
;
2023 get_stuck_stats(types
, cutoff
, stuck_pg_stats
);
2024 if (!stuck_pg_stats
.empty())
2025 dump_pg_stats_plain(ss
, stuck_pg_stats
, true);
2028 int PGMap::dump_stuck_pg_stats(
2032 vector
<string
>& args
) const
2034 int stuck_types
= 0;
2036 for (auto i
= args
.begin(); i
!= args
.end(); ++i
) {
2037 if (*i
== "inactive")
2038 stuck_types
|= PGMap::STUCK_INACTIVE
;
2039 else if (*i
== "unclean")
2040 stuck_types
|= PGMap::STUCK_UNCLEAN
;
2041 else if (*i
== "undersized")
2042 stuck_types
|= PGMap::STUCK_UNDERSIZED
;
2043 else if (*i
== "degraded")
2044 stuck_types
|= PGMap::STUCK_DEGRADED
;
2045 else if (*i
== "stale")
2046 stuck_types
|= PGMap::STUCK_STALE
;
2048 ds
<< "Unknown type: " << *i
<< std::endl
;
2053 utime_t
now(ceph_clock_now());
2054 utime_t cutoff
= now
- utime_t(threshold
, 0);
2057 dump_stuck_plain(ds
, stuck_types
, cutoff
);
2059 dump_stuck(f
, stuck_types
, cutoff
);
2066 void PGMap::dump_osd_perf_stats(ceph::Formatter
*f
) const
2068 f
->open_array_section("osd_perf_infos");
2069 for (auto i
= osd_stat
.begin();
2070 i
!= osd_stat
.end();
2072 f
->open_object_section("osd");
2073 f
->dump_int("id", i
->first
);
2075 f
->open_object_section("perf_stats");
2076 i
->second
.os_perf_stat
.dump(f
);
2083 void PGMap::print_osd_perf_stats(std::ostream
*ss
) const
2086 tab
.define_column("osd", TextTable::LEFT
, TextTable::RIGHT
);
2087 tab
.define_column("commit_latency(ms)", TextTable::LEFT
, TextTable::RIGHT
);
2088 tab
.define_column("apply_latency(ms)", TextTable::LEFT
, TextTable::RIGHT
);
2089 for (auto i
= osd_stat
.begin();
2090 i
!= osd_stat
.end();
2093 tab
<< i
->second
.os_perf_stat
.os_commit_latency_ns
/ 1000000ull;
2094 tab
<< i
->second
.os_perf_stat
.os_apply_latency_ns
/ 1000000ull;
2095 tab
<< TextTable::endrow
;
2100 void PGMap::dump_osd_blocked_by_stats(ceph::Formatter
*f
) const
2102 f
->open_array_section("osd_blocked_by_infos");
2103 for (auto i
= blocked_by_sum
.begin();
2104 i
!= blocked_by_sum
.end();
2106 f
->open_object_section("osd");
2107 f
->dump_int("id", i
->first
);
2108 f
->dump_int("num_blocked", i
->second
);
2113 void PGMap::print_osd_blocked_by_stats(std::ostream
*ss
) const
2116 tab
.define_column("osd", TextTable::LEFT
, TextTable::RIGHT
);
2117 tab
.define_column("num_blocked", TextTable::LEFT
, TextTable::RIGHT
);
2118 for (auto i
= blocked_by_sum
.begin();
2119 i
!= blocked_by_sum
.end();
2123 tab
<< TextTable::endrow
;
2130 * update aggregated delta
2132 * @param cct ceph context
2133 * @param ts Timestamp for the stats being delta'ed
2134 * @param old_pool_sum Previous stats sum
2135 * @param last_ts Last timestamp for pool
2136 * @param result_pool_sum Resulting stats
2137 * @param result_pool_delta Resulting pool delta
2138 * @param result_ts_delta Resulting timestamp delta
2139 * @param delta_avg_list List of last N computed deltas, used to average
2141 void PGMap::update_delta(
2144 const pool_stat_t
& old_pool_sum
,
2146 const pool_stat_t
& current_pool_sum
,
2147 pool_stat_t
*result_pool_delta
,
2148 utime_t
*result_ts_delta
,
2149 mempool::pgmap::list
<pair
<pool_stat_t
,utime_t
> > *delta_avg_list
)
2151 /* @p ts is the timestamp we want to associate with the data
2152 * in @p old_pool_sum, and on which we will base ourselves to
2153 * calculate the delta, stored in 'delta_t'.
2156 delta_t
= ts
; // start with the provided timestamp
2157 delta_t
-= *last_ts
; // take the last timestamp we saw
2158 *last_ts
= ts
; // @p ts becomes the last timestamp we saw
2160 // adjust delta_t, quick start if there is no update in a long period
2161 delta_t
= std::min(delta_t
,
2162 utime_t(2 * (cct
? cct
->_conf
->mon_delta_reset_interval
: 10), 0));
2164 // calculate a delta, and average over the last 6 deltas by default.
2165 /* start by taking a copy of our current @p result_pool_sum, and by
2166 * taking out the stats from @p old_pool_sum. This generates a stats
2167 * delta. Stash this stats delta in @p delta_avg_list, along with the
2168 * timestamp delta for these results.
2170 pool_stat_t d
= current_pool_sum
;
2171 d
.stats
.sub(old_pool_sum
.stats
);
2173 /* Aggregate current delta, and take out the last seen delta (if any) to
2175 * Skip calculating delta while sum was not synchronized.
2177 if(!old_pool_sum
.stats
.sum
.is_zero()) {
2178 delta_avg_list
->push_back(make_pair(d
,delta_t
));
2179 *result_ts_delta
+= delta_t
;
2180 result_pool_delta
->stats
.add(d
.stats
);
2182 size_t s
= cct
? cct
->_conf
.get_val
<uint64_t>("mon_stat_smooth_intervals") : 1;
2183 while (delta_avg_list
->size() > s
) {
2184 result_pool_delta
->stats
.sub(delta_avg_list
->front().first
.stats
);
2185 *result_ts_delta
-= delta_avg_list
->front().second
;
2186 delta_avg_list
->pop_front();
2191 * Update a given pool's deltas
2193 * @param cct Ceph Context
2194 * @param ts Timestamp for the stats being delta'ed
2195 * @param pool Pool's id
2196 * @param old_pool_sum Previous stats sum
2198 void PGMap::update_one_pool_delta(
2202 const pool_stat_t
& old_pool_sum
)
2204 if (per_pool_sum_deltas
.count(pool
) == 0) {
2205 ceph_assert(per_pool_sum_deltas_stamps
.count(pool
) == 0);
2206 ceph_assert(per_pool_sum_delta
.count(pool
) == 0);
2209 auto& sum_delta
= per_pool_sum_delta
[pool
];
2211 update_delta(cct
, ts
, old_pool_sum
, &sum_delta
.second
, pg_pool_sum
[pool
],
2212 &sum_delta
.first
, &per_pool_sum_deltas_stamps
[pool
],
2213 &per_pool_sum_deltas
[pool
]);
2217 * Update pools' deltas
2219 * @param cct CephContext
2220 * @param ts Timestamp for the stats being delta'ed
2221 * @param pg_pool_sum_old Map of pool stats for delta calcs.
2223 void PGMap::update_pool_deltas(
2224 CephContext
*cct
, const utime_t ts
,
2225 const mempool::pgmap::unordered_map
<int32_t,pool_stat_t
>& pg_pool_sum_old
)
2227 for (auto it
= pg_pool_sum_old
.begin();
2228 it
!= pg_pool_sum_old
.end(); ++it
) {
2229 update_one_pool_delta(cct
, ts
, it
->first
, it
->second
);
2233 void PGMap::clear_delta()
2235 pg_sum_delta
= pool_stat_t();
2236 pg_sum_deltas
.clear();
2237 stamp_delta
= utime_t();
2240 void PGMap::generate_test_instances(list
<PGMap
*>& o
)
2242 o
.push_back(new PGMap
);
2243 list
<Incremental
*> inc
;
2244 Incremental::generate_test_instances(inc
);
2247 while (!inc
.empty()) {
2248 PGMap
*pmp
= new PGMap();
2251 o
.back()->apply_incremental(NULL
, *inc
.front());
2257 void PGMap::get_filtered_pg_stats(uint64_t state
, int64_t poolid
, int64_t osdid
,
2258 bool primary
, set
<pg_t
>& pgs
) const
2260 for (auto i
= pg_stat
.begin();
2263 if ((poolid
>= 0) && (poolid
!= i
->first
.pool()))
2265 if ((osdid
>= 0) && !(i
->second
.is_acting_osd(osdid
,primary
)))
2267 if (state
== (uint64_t)-1 || // "all"
2268 (i
->second
.state
& state
) || // matches a state bit
2269 (state
== 0 && i
->second
.state
== 0)) { // matches "unknown" (== 0)
2270 pgs
.insert(i
->first
);
2275 void PGMap::dump_filtered_pg_stats(ceph::Formatter
*f
, set
<pg_t
>& pgs
) const
2277 f
->open_array_section("pg_stats");
2278 for (auto i
= pgs
.begin(); i
!= pgs
.end(); ++i
) {
2279 const pg_stat_t
& st
= pg_stat
.at(*i
);
2280 f
->open_object_section("pg_stat");
2281 f
->dump_stream("pgid") << *i
;
2288 void PGMap::dump_filtered_pg_stats(ostream
& ss
, set
<pg_t
>& pgs
) const
2291 utime_t now
= ceph_clock_now();
2293 tab
.define_column("PG", TextTable::LEFT
, TextTable::LEFT
);
2294 tab
.define_column("OBJECTS", TextTable::LEFT
, TextTable::RIGHT
);
2295 tab
.define_column("DEGRADED", TextTable::LEFT
, TextTable::RIGHT
);
2296 tab
.define_column("MISPLACED", TextTable::LEFT
, TextTable::RIGHT
);
2297 tab
.define_column("UNFOUND", TextTable::LEFT
, TextTable::RIGHT
);
2298 tab
.define_column("BYTES", TextTable::LEFT
, TextTable::RIGHT
);
2299 tab
.define_column("OMAP_BYTES*", TextTable::LEFT
, TextTable::RIGHT
);
2300 tab
.define_column("OMAP_KEYS*", TextTable::LEFT
, TextTable::RIGHT
);
2301 tab
.define_column("LOG", TextTable::LEFT
, TextTable::RIGHT
);
2302 tab
.define_column("STATE", TextTable::LEFT
, TextTable::RIGHT
);
2303 tab
.define_column("SINCE", TextTable::LEFT
, TextTable::RIGHT
);
2304 tab
.define_column("VERSION", TextTable::LEFT
, TextTable::RIGHT
);
2305 tab
.define_column("REPORTED", TextTable::LEFT
, TextTable::RIGHT
);
2306 tab
.define_column("UP", TextTable::LEFT
, TextTable::RIGHT
);
2307 tab
.define_column("ACTING", TextTable::LEFT
, TextTable::RIGHT
);
2308 tab
.define_column("SCRUB_STAMP", TextTable::LEFT
, TextTable::RIGHT
);
2309 tab
.define_column("DEEP_SCRUB_STAMP", TextTable::LEFT
, TextTable::RIGHT
);
2311 for (auto i
= pgs
.begin(); i
!= pgs
.end(); ++i
) {
2312 const pg_stat_t
& st
= pg_stat
.at(*i
);
2314 ostringstream reported
;
2315 reported
<< st
.reported_epoch
<< ":" << st
.reported_seq
;
2317 ostringstream upstr
, actingstr
;
2318 upstr
<< pg_vector_string(st
.up
) << 'p' << st
.up_primary
;
2319 actingstr
<< pg_vector_string(st
.acting
) << 'p' << st
.acting_primary
;
2321 << st
.stats
.sum
.num_objects
2322 << st
.stats
.sum
.num_objects_degraded
2323 << st
.stats
.sum
.num_objects_misplaced
2324 << st
.stats
.sum
.num_objects_unfound
2325 << st
.stats
.sum
.num_bytes
2326 << st
.stats
.sum
.num_omap_bytes
2327 << st
.stats
.sum
.num_omap_keys
2329 << pg_state_string(st
.state
)
2330 << utimespan_str(now
- st
.last_change
)
2335 << st
.last_scrub_stamp
2336 << st
.last_deep_scrub_stamp
2337 << TextTable::endrow
;
2343 void PGMap::dump_pool_stats_and_io_rate(int64_t poolid
, const OSDMap
&osd_map
,
2345 stringstream
*rs
) const {
2346 string pool_name
= osd_map
.get_pool_name(poolid
);
2348 f
->open_object_section("pool");
2349 f
->dump_string("pool_name", pool_name
.c_str());
2350 f
->dump_int("pool_id", poolid
);
2351 f
->open_object_section("recovery");
2355 pool_recovery_summary(f
, &sl
, poolid
);
2356 if (!f
&& !sl
.empty()) {
2358 tss
<< " " << p
<< "\n";
2361 f
->close_section(); // object section recovery
2362 f
->open_object_section("recovery_rate");
2365 pool_recovery_rate_summary(f
, &rss
, poolid
);
2366 if (!f
&& !rss
.str().empty())
2367 tss
<< " recovery io " << rss
.str() << "\n";
2369 f
->close_section(); // object section recovery_rate
2370 f
->open_object_section("client_io_rate");
2374 pool_client_io_rate_summary(f
, &rss
, poolid
);
2375 if (!f
&& !rss
.str().empty())
2376 tss
<< " client io " << rss
.str() << "\n";
2377 // dump cache tier IO rate for cache pool
2378 const pg_pool_t
*pool
= osd_map
.get_pg_pool(poolid
);
2379 if (pool
->is_tier()) {
2381 f
->close_section(); // object section client_io_rate
2382 f
->open_object_section("cache_io_rate");
2386 pool_cache_io_rate_summary(f
, &rss
, poolid
);
2387 if (!f
&& !rss
.str().empty())
2388 tss
<< " cache tier io " << rss
.str() << "\n";
2391 f
->close_section(); // object section cache_io_rate
2392 f
->close_section(); // object section pool
2394 *rs
<< "pool " << pool_name
<< " id " << poolid
<< "\n";
2395 if (!tss
.str().empty())
2396 *rs
<< tss
.str() << "\n";
2398 *rs
<< " nothing is going on\n\n";
2402 // Get crush parentage for an osd (skip root)
2403 set
<std::string
> PGMap::osd_parentage(const OSDMap
& osdmap
, int id
) const
2405 set
<std::string
> reporters_by_subtree
;
2406 auto reporter_subtree_level
= g_conf().get_val
<string
>("mon_osd_reporter_subtree_level");
2408 auto loc
= osdmap
.crush
->get_full_location(id
);
2409 for (auto& [parent_bucket_type
, parent_id
] : loc
) {
2410 // Should we show the root? Might not be too informative like "default"
2411 if (parent_bucket_type
!= "root" &&
2412 parent_bucket_type
!= reporter_subtree_level
) {
2413 reporters_by_subtree
.insert(parent_id
);
2416 return reporters_by_subtree
;
2419 void PGMap::get_health_checks(
2421 const OSDMap
& osdmap
,
2422 health_check_map_t
*checks
) const
2424 utime_t now
= ceph_clock_now();
2425 const auto max
= cct
->_conf
.get_val
<uint64_t>("mon_health_max_detail");
2426 const auto& pools
= osdmap
.get_pools();
2428 typedef enum pg_consequence_t
{
2429 UNAVAILABLE
= 1, // Client IO to the pool may block
2430 DEGRADED
= 2, // Fewer than the requested number of replicas are present
2431 BACKFILL_FULL
= 3, // Backfill is blocked for space considerations
2432 // This may or may not be a deadlock condition.
2433 DAMAGED
= 4, // The data may be missing or inconsistent on disk and
2435 RECOVERY_FULL
= 5 // Recovery is blocked because OSDs are full
2438 // For a given PG state, how should it be reported at the pool level?
2439 class PgStateResponse
{
2441 pg_consequence_t consequence
;
2442 typedef std::function
< utime_t(const pg_stat_t
&) > stuck_cb
;
2443 stuck_cb stuck_since
;
2446 PgStateResponse(const pg_consequence_t
& c
, stuck_cb
&& s
)
2447 : consequence(c
), stuck_since(std::move(s
)), invert(false)
2451 PgStateResponse(const pg_consequence_t
& c
, stuck_cb
&& s
, bool i
)
2452 : consequence(c
), stuck_since(std::move(s
)), invert(i
)
2457 // Record the PG state counts that contributed to a reported pool state
2460 // Map of PG_STATE_* to number of pgs in that state.
2461 std::map
<unsigned, unsigned> states
;
2463 // List of all PG IDs that had a state contributing
2464 // to this health condition.
2467 std::map
<pg_t
, std::string
> pg_messages
;
2470 // Map of PG state to how to respond to it
2471 std::map
<unsigned, PgStateResponse
> state_to_response
= {
2472 // Immediate reports
2473 { PG_STATE_INCONSISTENT
, {DAMAGED
, {}} },
2474 { PG_STATE_INCOMPLETE
, {UNAVAILABLE
, {}} },
2475 { PG_STATE_SNAPTRIM_ERROR
, {DAMAGED
, {}} },
2476 { PG_STATE_RECOVERY_UNFOUND
, {DAMAGED
, {}} },
2477 { PG_STATE_BACKFILL_UNFOUND
, {DAMAGED
, {}} },
2478 { PG_STATE_BACKFILL_TOOFULL
, {BACKFILL_FULL
, {}} },
2479 { PG_STATE_RECOVERY_TOOFULL
, {RECOVERY_FULL
, {}} },
2480 { PG_STATE_DEGRADED
, {DEGRADED
, {}} },
2481 { PG_STATE_DOWN
, {UNAVAILABLE
, {}} },
2482 // Delayed (wait until stuck) reports
2483 { PG_STATE_PEERING
, {UNAVAILABLE
, [](const pg_stat_t
&p
){return p
.last_peered
;} } },
2484 { PG_STATE_UNDERSIZED
, {DEGRADED
, [](const pg_stat_t
&p
){return p
.last_fullsized
;} } },
2485 { PG_STATE_STALE
, {UNAVAILABLE
, [](const pg_stat_t
&p
){return p
.last_unstale
;} } },
2486 // Delayed and inverted reports
2487 { PG_STATE_ACTIVE
, {UNAVAILABLE
, [](const pg_stat_t
&p
){return p
.last_active
;}, true} }
2490 // Specialized state printer that takes account of inversion of
2491 // ACTIVE, CLEAN checks.
2492 auto state_name
= [](const uint64_t &state
) {
2493 // Special cases for the states that are inverted checks
2494 if (state
== PG_STATE_CLEAN
) {
2495 return std::string("unclean");
2496 } else if (state
== PG_STATE_ACTIVE
) {
2497 return std::string("inactive");
2499 return pg_state_string(state
);
2503 // Map of what is wrong to information about why, implicitly also stores
2504 // the list of what is wrong.
2505 std::map
<pg_consequence_t
, PgCauses
> detected
;
2507 // Optimisation: trim down the number of checks to apply based on
2508 // the summary counters
2509 std::map
<unsigned, PgStateResponse
> possible_responses
;
2510 for (const auto &i
: num_pg_by_state
) {
2511 for (const auto &j
: state_to_response
) {
2512 if (!j
.second
.invert
) {
2513 // Check for normal tests by seeing if any pgs have the flag
2514 if (i
.first
& j
.first
) {
2515 possible_responses
.insert(j
);
2521 for (const auto &j
: state_to_response
) {
2522 if (j
.second
.invert
) {
2523 // Check for inverted tests by seeing if not-all pgs have the flag
2524 const auto &found
= num_pg_by_state
.find(j
.first
);
2525 if (found
== num_pg_by_state
.end() || found
->second
!= num_pg
) {
2526 possible_responses
.insert(j
);
2531 utime_t cutoff
= now
- utime_t(cct
->_conf
.get_val
<int64_t>("mon_pg_stuck_threshold"), 0);
2532 // Loop over all PGs, if there are any possibly-unhealthy states in there
2533 if (!possible_responses
.empty()) {
2534 for (const auto& i
: pg_stat
) {
2535 const auto &pg_id
= i
.first
;
2536 const auto &pg_info
= i
.second
;
2538 for (const auto &j
: state_to_response
) {
2539 const auto &pg_response_state
= j
.first
;
2540 const auto &pg_response
= j
.second
;
2542 // Apply the state test
2543 if (!(bool(pg_info
.state
& pg_response_state
) != pg_response
.invert
)) {
2547 // Apply stuckness test if needed
2548 if (pg_response
.stuck_since
) {
2549 // Delayed response, check for stuckness
2550 utime_t last_whatever
= pg_response
.stuck_since(pg_info
);
2551 if (last_whatever
.is_zero() &&
2552 pg_info
.last_change
>= cutoff
) {
2553 // still moving, ignore
2555 } else if (last_whatever
>= cutoff
) {
2556 // Not stuck enough, ignore.
2563 auto &causes
= detected
[pg_response
.consequence
];
2564 causes
.states
[pg_response_state
]++;
2565 causes
.pgs
.insert(pg_id
);
2567 // Don't bother composing detail string if we have already recorded
2569 if (causes
.pg_messages
.size() > max
) {
2573 std::ostringstream ss
;
2574 if (pg_response
.stuck_since
) {
2575 utime_t since
= pg_response
.stuck_since(pg_info
);
2576 ss
<< "pg " << pg_id
<< " is stuck " << state_name(pg_response_state
);
2577 if (since
== utime_t()) {
2578 ss
<< " since forever";
2580 utime_t dur
= now
- since
;
2581 ss
<< " for " << utimespan_str(dur
);
2583 ss
<< ", current state " << pg_state_string(pg_info
.state
)
2584 << ", last acting " << pg_info
.acting
;
2586 ss
<< "pg " << pg_id
<< " is "
2587 << pg_state_string(pg_info
.state
);
2588 ss
<< ", acting " << pg_info
.acting
;
2589 if (pg_info
.stats
.sum
.num_objects_unfound
) {
2590 ss
<< ", " << pg_info
.stats
.sum
.num_objects_unfound
2595 if (pg_info
.state
& PG_STATE_INCOMPLETE
) {
2596 const pg_pool_t
*pi
= osdmap
.get_pg_pool(pg_id
.pool());
2597 if (pi
&& pi
->min_size
> 1) {
2598 ss
<< " (reducing pool "
2599 << osdmap
.get_pool_name(pg_id
.pool())
2600 << " min_size from " << (int)pi
->min_size
2601 << " may help; search ceph.com/docs for 'incomplete')";
2605 causes
.pg_messages
[pg_id
] = ss
.str();
2609 dout(10) << __func__
<< " skipping loop over PGs: counters look OK" << dendl
;
2612 for (const auto &i
: detected
) {
2613 std::string health_code
;
2614 health_status_t sev
;
2615 std::string summary
;
2618 health_code
= "PG_AVAILABILITY";
2620 summary
= "Reduced data availability: ";
2623 health_code
= "PG_DEGRADED";
2624 summary
= "Degraded data redundancy: ";
2628 health_code
= "PG_BACKFILL_FULL";
2629 summary
= "Low space hindering backfill (add storage if this doesn't resolve itself): ";
2633 health_code
= "PG_DAMAGED";
2634 summary
= "Possible data damage: ";
2638 health_code
= "PG_RECOVERY_FULL";
2639 summary
= "Full OSDs blocking recovery: ";
2646 if (i
.first
== DEGRADED
) {
2647 if (pg_sum
.stats
.sum
.num_objects_degraded
&&
2648 pg_sum
.stats
.sum
.num_object_copies
> 0) {
2649 double pc
= (double)pg_sum
.stats
.sum
.num_objects_degraded
/
2650 (double)pg_sum
.stats
.sum
.num_object_copies
* (double)100.0;
2652 snprintf(b
, sizeof(b
), "%.3lf", pc
);
2654 ss
<< pg_sum
.stats
.sum
.num_objects_degraded
2655 << "/" << pg_sum
.stats
.sum
.num_object_copies
<< " objects degraded ("
2658 // Throw in a comma for the benefit of the following PG counts
2659 summary
+= ss
.str() + ", ";
2663 // Compose summary message saying how many PGs in what states led
2664 // to this health check failing
2665 std::vector
<std::string
> pg_msgs
;
2667 for (const auto &j
: i
.second
.states
) {
2668 std::ostringstream msg
;
2669 msg
<< j
.second
<< (j
.second
> 1 ? " pgs " : " pg ") << state_name(j
.first
);
2670 pg_msgs
.push_back(msg
.str());
2673 summary
+= joinify(pg_msgs
.begin(), pg_msgs
.end(), std::string(", "));
2675 health_check_t
*check
= &checks
->add(
2681 // Compose list of PGs contributing to this health check failing
2682 for (const auto &j
: i
.second
.pg_messages
) {
2683 check
->detail
.push_back(j
.second
);
2688 if (pg_sum
.stats
.sum
.num_scrub_errors
) {
2690 ss
<< pg_sum
.stats
.sum
.num_scrub_errors
<< " scrub errors";
2691 checks
->add("OSD_SCRUB_ERRORS", HEALTH_ERR
, ss
.str(),
2692 pg_sum
.stats
.sum
.num_scrub_errors
);
2695 // LARGE_OMAP_OBJECTS
2696 if (pg_sum
.stats
.sum
.num_large_omap_objects
) {
2697 list
<string
> detail
;
2698 for (auto &pool
: pools
) {
2699 const string
& pool_name
= osdmap
.get_pool_name(pool
.first
);
2700 auto it2
= pg_pool_sum
.find(pool
.first
);
2701 if (it2
== pg_pool_sum
.end()) {
2704 const pool_stat_t
*pstat
= &it2
->second
;
2705 if (pstat
== nullptr) {
2708 const object_stat_sum_t
& sum
= pstat
->stats
.sum
;
2709 if (sum
.num_large_omap_objects
) {
2711 ss
<< sum
.num_large_omap_objects
<< " large objects found in pool "
2712 << "'" << pool_name
<< "'";
2713 detail
.push_back(ss
.str());
2716 if (!detail
.empty()) {
2718 ss
<< pg_sum
.stats
.sum
.num_large_omap_objects
<< " large omap objects";
2719 auto& d
= checks
->add("LARGE_OMAP_OBJECTS", HEALTH_WARN
, ss
.str(),
2720 pg_sum
.stats
.sum
.num_large_omap_objects
);
2722 tip
<< "Search the cluster log for 'Large omap object found' for more "
2724 detail
.push_back(tip
.str());
2725 d
.detail
.swap(detail
);
2729 // CACHE_POOL_NEAR_FULL
2731 list
<string
> detail
;
2732 unsigned num_pools
= 0;
2733 for (auto& p
: pools
) {
2734 if ((!p
.second
.target_max_objects
&& !p
.second
.target_max_bytes
) ||
2735 !pg_pool_sum
.count(p
.first
)) {
2738 bool nearfull
= false;
2739 const string
& name
= osdmap
.get_pool_name(p
.first
);
2740 const pool_stat_t
& st
= get_pg_pool_sum_stat(p
.first
);
2741 uint64_t ratio
= p
.second
.cache_target_full_ratio_micro
+
2742 ((1000000 - p
.second
.cache_target_full_ratio_micro
) *
2743 cct
->_conf
->mon_cache_target_full_warn_ratio
);
2744 if (p
.second
.target_max_objects
&&
2745 (uint64_t)(st
.stats
.sum
.num_objects
-
2746 st
.stats
.sum
.num_objects_hit_set_archive
) >
2747 p
.second
.target_max_objects
* (ratio
/ 1000000.0)) {
2749 ss
<< "cache pool '" << name
<< "' with "
2750 << si_u_t(st
.stats
.sum
.num_objects
)
2751 << " objects at/near target max "
2752 << si_u_t(p
.second
.target_max_objects
) << " objects";
2753 detail
.push_back(ss
.str());
2756 if (p
.second
.target_max_bytes
&&
2757 (uint64_t)(st
.stats
.sum
.num_bytes
-
2758 st
.stats
.sum
.num_bytes_hit_set_archive
) >
2759 p
.second
.target_max_bytes
* (ratio
/ 1000000.0)) {
2761 ss
<< "cache pool '" << name
2762 << "' with " << byte_u_t(st
.stats
.sum
.num_bytes
)
2763 << " at/near target max "
2764 << byte_u_t(p
.second
.target_max_bytes
);
2765 detail
.push_back(ss
.str());
2772 if (!detail
.empty()) {
2774 ss
<< num_pools
<< " cache pools at or near target size";
2775 auto& d
= checks
->add("CACHE_POOL_NEAR_FULL", HEALTH_WARN
, ss
.str(),
2777 d
.detail
.swap(detail
);
2782 unsigned num_in
= osdmap
.get_num_in_osds();
2783 auto sum_pg_up
= std::max(static_cast<size_t>(pg_sum
.up
), pg_stat
.size());
2784 const auto min_pg_per_osd
=
2785 cct
->_conf
.get_val
<uint64_t>("mon_pg_warn_min_per_osd");
2786 if (num_in
&& min_pg_per_osd
> 0 && osdmap
.get_pools().size() > 0) {
2787 auto per
= sum_pg_up
/ num_in
;
2788 if (per
< min_pg_per_osd
&& per
) {
2790 ss
<< "too few PGs per OSD (" << per
2791 << " < min " << min_pg_per_osd
<< ")";
2792 checks
->add("TOO_FEW_PGS", HEALTH_WARN
, ss
.str(),
2793 min_pg_per_osd
- per
);
2798 auto max_pg_per_osd
= cct
->_conf
.get_val
<uint64_t>("mon_max_pg_per_osd");
2799 if (num_in
&& max_pg_per_osd
> 0) {
2800 auto per
= sum_pg_up
/ num_in
;
2801 if (per
> max_pg_per_osd
) {
2803 ss
<< "too many PGs per OSD (" << per
2804 << " > max " << max_pg_per_osd
<< ")";
2805 checks
->add("TOO_MANY_PGS", HEALTH_WARN
, ss
.str(),
2806 per
- max_pg_per_osd
);
2811 auto warn_too_few_osds
= cct
->_conf
.get_val
<bool>("mon_warn_on_too_few_osds");
2812 auto osd_pool_default_size
= cct
->_conf
.get_val
<uint64_t>("osd_pool_default_size");
2813 if (warn_too_few_osds
&& osdmap
.get_num_osds() < osd_pool_default_size
) {
2815 ss
<< "OSD count " << osdmap
.get_num_osds()
2816 << " < osd_pool_default_size " << osd_pool_default_size
;
2817 checks
->add("TOO_FEW_OSDS", HEALTH_WARN
, ss
.str(),
2818 osd_pool_default_size
- osdmap
.get_num_osds());
2822 // Convert milliseconds to microseconds
2823 auto warn_slow_ping_time
= cct
->_conf
.get_val
<double>("mon_warn_on_slow_ping_time") * 1000;
2824 auto grace
= cct
->_conf
.get_val
<int64_t>("osd_heartbeat_grace");
2825 if (warn_slow_ping_time
== 0) {
2826 double ratio
= cct
->_conf
.get_val
<double>("mon_warn_on_slow_ping_ratio");
2827 warn_slow_ping_time
= grace
;
2828 warn_slow_ping_time
*= 1000000 * ratio
; // Seconds of grace to microseconds at ratio
2830 if (warn_slow_ping_time
> 0) {
2832 struct mon_ping_item_t
{
2838 bool operator<(const mon_ping_item_t
& rhs
) const {
2839 if (pingtime
< rhs
.pingtime
)
2841 if (pingtime
> rhs
.pingtime
)
2843 if (from
< rhs
.from
)
2845 if (from
> rhs
.from
)
2851 list
<string
> detail_back
;
2852 list
<string
> detail_front
;
2853 list
<string
> detail
;
2854 set
<mon_ping_item_t
> back_sorted
, front_sorted
;
2855 for (auto i
: osd_stat
) {
2856 for (auto j
: i
.second
.hb_pingtime
) {
2858 // Maybe source info is old
2859 if (now
.sec() - j
.second
.last_update
> grace
* 60)
2862 mon_ping_item_t back
;
2863 back
.pingtime
= std::max(j
.second
.back_pingtime
[0], j
.second
.back_pingtime
[1]);
2864 back
.pingtime
= std::max(back
.pingtime
, j
.second
.back_pingtime
[2]);
2865 back
.from
= i
.first
;
2867 if (back
.pingtime
> warn_slow_ping_time
) {
2868 back
.improving
= (j
.second
.back_pingtime
[0] < j
.second
.back_pingtime
[1]
2869 && j
.second
.back_pingtime
[1] < j
.second
.back_pingtime
[2]);
2870 back_sorted
.emplace(back
);
2873 mon_ping_item_t front
;
2874 front
.pingtime
= std::max(j
.second
.front_pingtime
[0], j
.second
.front_pingtime
[1]);
2875 front
.pingtime
= std::max(front
.pingtime
, j
.second
.front_pingtime
[2]);
2876 front
.from
= i
.first
;
2878 if (front
.pingtime
> warn_slow_ping_time
) {
2879 front
.improving
= (j
.second
.front_pingtime
[0] < j
.second
.front_pingtime
[1]
2880 && j
.second
.front_pingtime
[1] < j
.second
.back_pingtime
[2]);
2881 front_sorted
.emplace(front
);
2884 if (i
.second
.num_shards_repaired
>
2885 cct
->_conf
.get_val
<uint64_t>("mon_osd_warn_num_repaired")) {
2887 ss
<< "osd." << i
.first
<< " had " << i
.second
.num_shards_repaired
<< " reads repaired";
2888 detail
.push_back(ss
.str());
2891 if (!detail
.empty()) {
2893 ss
<< "Too many repaired reads on " << detail
.size() << " OSDs";
2894 auto& d
= checks
->add("OSD_TOO_MANY_REPAIRS", HEALTH_WARN
, ss
.str(),
2896 d
.detail
.swap(detail
);
2898 int max_detail
= 10;
2899 for (auto &sback
: boost::adaptors::reverse(back_sorted
)) {
2901 if (max_detail
== 0) {
2902 ss
<< "Truncated long network list. Use ceph daemon mgr.# dump_osd_network for more information";
2903 detail_back
.push_back(ss
.str());
2907 ss
<< "Slow OSD heartbeats on back from osd." << sback
.from
2908 << " [" << osd_parentage(osdmap
, sback
.from
) << "]"
2909 << (osdmap
.is_down(sback
.from
) ? " (down)" : "")
2910 << " to osd." << sback
.to
2911 << " [" << osd_parentage(osdmap
, sback
.to
) << "]"
2912 << (osdmap
.is_down(sback
.to
) ? " (down)" : "")
2913 << " " << fixed_u_to_string(sback
.pingtime
, 3) << " msec"
2914 << (sback
.improving
? " possibly improving" : "");
2915 detail_back
.push_back(ss
.str());
2918 for (auto &sfront
: boost::adaptors::reverse(front_sorted
)) {
2920 if (max_detail
== 0) {
2921 ss
<< "Truncated long network list. Use ceph daemon mgr.# dump_osd_network for more information";
2922 detail_front
.push_back(ss
.str());
2926 // Get crush parentage for each osd
2927 ss
<< "Slow OSD heartbeats on front from osd." << sfront
.from
2928 << " [" << osd_parentage(osdmap
, sfront
.from
) << "]"
2929 << (osdmap
.is_down(sfront
.from
) ? " (down)" : "")
2930 << " to osd." << sfront
.to
2931 << " [" << osd_parentage(osdmap
, sfront
.to
) << "]"
2932 << (osdmap
.is_down(sfront
.to
) ? " (down)" : "")
2933 << " " << fixed_u_to_string(sfront
.pingtime
, 3) << " msec"
2934 << (sfront
.improving
? " possibly improving" : "");
2935 detail_front
.push_back(ss
.str());
2937 if (detail_back
.size() != 0) {
2939 ss
<< "Slow OSD heartbeats on back (longest "
2940 << fixed_u_to_string(back_sorted
.rbegin()->pingtime
, 3) << "ms)";
2941 auto& d
= checks
->add("OSD_SLOW_PING_TIME_BACK", HEALTH_WARN
, ss
.str(),
2942 back_sorted
.size());
2943 d
.detail
.swap(detail_back
);
2945 if (detail_front
.size() != 0) {
2947 ss
<< "Slow OSD heartbeats on front (longest "
2948 << fixed_u_to_string(front_sorted
.rbegin()->pingtime
, 3) << "ms)";
2949 auto& d
= checks
->add("OSD_SLOW_PING_TIME_FRONT", HEALTH_WARN
, ss
.str(),
2950 front_sorted
.size());
2951 d
.detail
.swap(detail_front
);
2956 // MANY_OBJECTS_PER_PG
2957 if (!pg_stat
.empty()) {
2958 list
<string
> pgp_detail
, many_detail
;
2959 const auto mon_pg_warn_min_objects
=
2960 cct
->_conf
.get_val
<int64_t>("mon_pg_warn_min_objects");
2961 const auto mon_pg_warn_min_pool_objects
=
2962 cct
->_conf
.get_val
<int64_t>("mon_pg_warn_min_pool_objects");
2963 const auto mon_pg_warn_max_object_skew
=
2964 cct
->_conf
.get_val
<double>("mon_pg_warn_max_object_skew");
2965 for (auto p
= pg_pool_sum
.begin();
2966 p
!= pg_pool_sum
.end();
2968 const pg_pool_t
*pi
= osdmap
.get_pg_pool(p
->first
);
2970 continue; // in case osdmap changes haven't propagated to PGMap yet
2971 const string
& name
= osdmap
.get_pool_name(p
->first
);
2972 // NOTE: we use pg_num_target and pgp_num_target for the purposes of
2973 // the warnings. If the cluster is failing to converge on the target
2974 // values that is a separate issue!
2975 if (pi
->get_pg_num_target() > pi
->get_pgp_num_target() &&
2976 !(name
.find(".DELETED") != string::npos
&&
2977 cct
->_conf
->mon_fake_pool_delete
)) {
2979 ss
<< "pool " << name
<< " pg_num "
2980 << pi
->get_pg_num_target()
2981 << " > pgp_num " << pi
->get_pgp_num_target();
2982 pgp_detail
.push_back(ss
.str());
2984 int average_objects_per_pg
= pg_sum
.stats
.sum
.num_objects
/ pg_stat
.size();
2985 if (average_objects_per_pg
> 0 &&
2986 pg_sum
.stats
.sum
.num_objects
>= mon_pg_warn_min_objects
&&
2987 p
->second
.stats
.sum
.num_objects
>= mon_pg_warn_min_pool_objects
) {
2988 int objects_per_pg
= p
->second
.stats
.sum
.num_objects
/
2989 pi
->get_pg_num_target();
2990 float ratio
= (float)objects_per_pg
/ (float)average_objects_per_pg
;
2991 if (mon_pg_warn_max_object_skew
> 0 &&
2992 ratio
> mon_pg_warn_max_object_skew
) {
2994 ss
<< "pool " << name
<< " objects per pg ("
2995 << objects_per_pg
<< ") is more than " << ratio
2996 << " times cluster average ("
2997 << average_objects_per_pg
<< ")";
2998 many_detail
.push_back(ss
.str());
3002 if (!pgp_detail
.empty()) {
3004 ss
<< pgp_detail
.size() << " pools have pg_num > pgp_num";
3005 auto& d
= checks
->add("SMALLER_PGP_NUM", HEALTH_WARN
, ss
.str(),
3007 d
.detail
.swap(pgp_detail
);
3009 if (!many_detail
.empty()) {
3011 ss
<< many_detail
.size() << " pools have many more objects per pg than"
3013 auto& d
= checks
->add("MANY_OBJECTS_PER_PG", HEALTH_WARN
, ss
.str(),
3014 many_detail
.size());
3015 d
.detail
.swap(many_detail
);
3022 float warn_threshold
= (float)g_conf().get_val
<int64_t>("mon_pool_quota_warn_threshold")/100;
3023 float crit_threshold
= (float)g_conf().get_val
<int64_t>("mon_pool_quota_crit_threshold")/100;
3024 list
<string
> full_detail
, nearfull_detail
;
3025 unsigned full_pools
= 0, nearfull_pools
= 0;
3026 for (auto it
: pools
) {
3027 auto it2
= pg_pool_sum
.find(it
.first
);
3028 if (it2
== pg_pool_sum
.end()) {
3031 const pool_stat_t
*pstat
= &it2
->second
;
3032 const object_stat_sum_t
& sum
= pstat
->stats
.sum
;
3033 const string
& pool_name
= osdmap
.get_pool_name(it
.first
);
3034 const pg_pool_t
&pool
= it
.second
;
3035 bool full
= false, nearfull
= false;
3036 if (pool
.quota_max_objects
> 0) {
3038 if ((uint64_t)sum
.num_objects
>= pool
.quota_max_objects
) {
3039 } else if (crit_threshold
> 0 &&
3040 sum
.num_objects
>= pool
.quota_max_objects
*crit_threshold
) {
3041 ss
<< "pool '" << pool_name
3042 << "' has " << sum
.num_objects
<< " objects"
3043 << " (max " << pool
.quota_max_objects
<< ")";
3044 full_detail
.push_back(ss
.str());
3046 } else if (warn_threshold
> 0 &&
3047 sum
.num_objects
>= pool
.quota_max_objects
*warn_threshold
) {
3048 ss
<< "pool '" << pool_name
3049 << "' has " << sum
.num_objects
<< " objects"
3050 << " (max " << pool
.quota_max_objects
<< ")";
3051 nearfull_detail
.push_back(ss
.str());
3055 if (pool
.quota_max_bytes
> 0) {
3057 if ((uint64_t)sum
.num_bytes
>= pool
.quota_max_bytes
) {
3058 } else if (crit_threshold
> 0 &&
3059 sum
.num_bytes
>= pool
.quota_max_bytes
*crit_threshold
) {
3060 ss
<< "pool '" << pool_name
3061 << "' has " << byte_u_t(sum
.num_bytes
)
3062 << " (max " << byte_u_t(pool
.quota_max_bytes
) << ")";
3063 full_detail
.push_back(ss
.str());
3065 } else if (warn_threshold
> 0 &&
3066 sum
.num_bytes
>= pool
.quota_max_bytes
*warn_threshold
) {
3067 ss
<< "pool '" << pool_name
3068 << "' has " << byte_u_t(sum
.num_bytes
)
3069 << " (max " << byte_u_t(pool
.quota_max_bytes
) << ")";
3070 nearfull_detail
.push_back(ss
.str());
3083 ss
<< full_pools
<< " pools full";
3084 auto& d
= checks
->add("POOL_FULL", HEALTH_ERR
, ss
.str(), full_pools
);
3085 d
.detail
.swap(full_detail
);
3087 if (nearfull_pools
) {
3089 ss
<< nearfull_pools
<< " pools nearfull";
3090 auto& d
= checks
->add("POOL_NEAR_FULL", HEALTH_WARN
, ss
.str(), nearfull_pools
);
3091 d
.detail
.swap(nearfull_detail
);
3096 if (pg_sum
.stats
.sum
.num_objects_misplaced
&&
3097 pg_sum
.stats
.sum
.num_object_copies
> 0 &&
3098 cct
->_conf
->mon_warn_on_misplaced
) {
3099 double pc
= (double)pg_sum
.stats
.sum
.num_objects_misplaced
/
3100 (double)pg_sum
.stats
.sum
.num_object_copies
* (double)100.0;
3102 snprintf(b
, sizeof(b
), "%.3lf", pc
);
3104 ss
<< pg_sum
.stats
.sum
.num_objects_misplaced
3105 << "/" << pg_sum
.stats
.sum
.num_object_copies
<< " objects misplaced ("
3107 checks
->add("OBJECT_MISPLACED", HEALTH_WARN
, ss
.str(),
3108 pg_sum
.stats
.sum
.num_objects_misplaced
);
3112 if (pg_sum
.stats
.sum
.num_objects_unfound
&&
3113 pg_sum
.stats
.sum
.num_objects
) {
3114 double pc
= (double)pg_sum
.stats
.sum
.num_objects_unfound
/
3115 (double)pg_sum
.stats
.sum
.num_objects
* (double)100.0;
3117 snprintf(b
, sizeof(b
), "%.3lf", pc
);
3119 ss
<< pg_sum
.stats
.sum
.num_objects_unfound
3120 << "/" << pg_sum
.stats
.sum
.num_objects
<< " objects unfound (" << b
<< "%)";
3121 auto& d
= checks
->add("OBJECT_UNFOUND", HEALTH_WARN
, ss
.str(),
3122 pg_sum
.stats
.sum
.num_objects_unfound
);
3124 for (auto& p
: pg_stat
) {
3125 if (p
.second
.stats
.sum
.num_objects_unfound
) {
3127 ss
<< "pg " << p
.first
3128 << " has " << p
.second
.stats
.sum
.num_objects_unfound
3129 << " unfound objects";
3130 d
.detail
.push_back(ss
.str());
3131 if (d
.detail
.size() > max
) {
3132 d
.detail
.push_back("(additional pgs left out for brevity)");
3141 // SLOW_OPS unifies them in mimic.
3142 if (osdmap
.require_osd_release
< ceph_release_t::mimic
&&
3143 cct
->_conf
->mon_osd_warn_op_age
> 0 &&
3144 !osd_sum
.op_queue_age_hist
.h
.empty() &&
3145 osd_sum
.op_queue_age_hist
.upper_bound() / 1000.0 >
3146 cct
->_conf
->mon_osd_warn_op_age
) {
3147 list
<string
> warn_detail
, error_detail
;
3148 unsigned warn
= 0, error
= 0;
3150 cct
->_conf
->mon_osd_warn_op_age
* cct
->_conf
->mon_osd_err_op_age_ratio
;
3151 const pow2_hist_t
& h
= osd_sum
.op_queue_age_hist
;
3152 for (unsigned i
= h
.h
.size() - 1; i
> 0; --i
) {
3153 float ub
= (float)(1 << i
) / 1000.0;
3154 if (ub
< cct
->_conf
->mon_osd_warn_op_age
)
3158 ss
<< h
.h
[i
] << " ops are blocked > " << ub
<< " sec";
3161 error_detail
.push_back(ss
.str());
3164 warn_detail
.push_back(ss
.str());
3169 map
<float,set
<int>> warn_osd_by_max
; // max -> osds
3170 map
<float,set
<int>> error_osd_by_max
; // max -> osds
3171 if (!warn_detail
.empty() || !error_detail
.empty()) {
3172 for (auto& p
: osd_stat
) {
3173 const pow2_hist_t
& h
= p
.second
.op_queue_age_hist
;
3174 for (unsigned i
= h
.h
.size() - 1; i
> 0; --i
) {
3175 float ub
= (float)(1 << i
) / 1000.0;
3176 if (ub
< cct
->_conf
->mon_osd_warn_op_age
)
3180 error_osd_by_max
[ub
].insert(p
.first
);
3182 warn_osd_by_max
[ub
].insert(p
.first
);
3190 if (!warn_detail
.empty()) {
3192 ss
<< warn
<< " slow requests are blocked > "
3193 << cct
->_conf
->mon_osd_warn_op_age
<< " sec";
3194 auto& d
= checks
->add("REQUEST_SLOW", HEALTH_WARN
, ss
.str(), warn
);
3195 d
.detail
.swap(warn_detail
);
3197 for (auto& p
: warn_osd_by_max
) {
3199 if (p
.second
.size() > 1) {
3200 ss
<< "osds " << p
.second
3201 << " have blocked requests > " << p
.first
<< " sec";
3203 ss
<< "osd." << *p
.second
.begin()
3204 << " has blocked requests > " << p
.first
<< " sec";
3206 d
.detail
.push_back(ss
.str());
3212 if (!error_detail
.empty()) {
3214 ss
<< error
<< " stuck requests are blocked > "
3215 << err_age
<< " sec";
3216 auto& d
= checks
->add("REQUEST_STUCK", HEALTH_ERR
, ss
.str(), error
);
3217 d
.detail
.swap(error_detail
);
3219 for (auto& p
: error_osd_by_max
) {
3221 if (p
.second
.size() > 1) {
3222 ss
<< "osds " << p
.second
3223 << " have stuck requests > " << p
.first
<< " sec";
3225 ss
<< "osd." << *p
.second
.begin()
3226 << " has stuck requests > " << p
.first
<< " sec";
3228 d
.detail
.push_back(ss
.str());
3236 // OBJECT_STORE_WARN
3237 if (osd_sum
.os_alerts
.size()) {
3238 map
<string
, pair
<size_t, list
<string
>>> os_alerts_sum
;
3240 for (auto& a
: osd_sum
.os_alerts
) {
3242 string s0
= " osd.";
3243 s0
+= stringify(a
.first
);
3244 for (auto& aa
: a
.second
) {
3248 auto it
= os_alerts_sum
.find(aa
.first
);
3249 if (it
== os_alerts_sum
.end()) {
3252 os_alerts_sum
.emplace(aa
.first
, std::make_pair(1, d
));
3254 auto& p
= it
->second
;
3256 p
.second
.emplace_back(s
);
3264 for (auto& asum
: os_alerts_sum
) {
3265 string summary
= stringify(asum
.second
.first
) + " OSD(s)";
3266 if (asum
.first
== "BLUEFS_SPILLOVER") {
3267 summary
+= " experiencing BlueFS spillover";
3268 } else if (asum
.first
== "BLUESTORE_NO_COMPRESSION") {
3269 summary
+= " have broken BlueStore compression";
3270 } else if (asum
.first
== "BLUESTORE_LEGACY_STATFS") {
3271 summary
+= " reporting legacy (not per-pool) BlueStore stats";
3272 } else if (asum
.first
== "BLUESTORE_DISK_SIZE_MISMATCH") {
3273 summary
+= " have dangerous mismatch between BlueStore block device and free list sizes";
3274 } else if (asum
.first
== "BLUESTORE_NO_PER_PG_OMAP") {
3275 summary
+= " reporting legacy (not per-pg) BlueStore omap";
3276 } else if (asum
.first
== "BLUESTORE_NO_PER_POOL_OMAP") {
3277 summary
+= " reporting legacy (not per-pool) BlueStore omap usage stats";
3278 } else if (asum
.first
== "BLUESTORE_SPURIOUS_READ_ERRORS") {
3279 summary
+= " have spurious read errors";
3282 auto& d
= checks
->add(asum
.first
, HEALTH_WARN
, summary
, asum
.second
.first
);
3283 for (auto& s
: asum
.second
.second
) {
3284 d
.detail
.push_back(s
);
3289 // PG_NOT_DEEP_SCRUBBED
3290 if (cct
->_conf
->mon_warn_pg_not_scrubbed_ratio
||
3291 cct
->_conf
->mon_warn_pg_not_deep_scrubbed_ratio
) {
3292 list
<string
> detail
, deep_detail
;
3293 int detail_max
= max
, deep_detail_max
= max
;
3294 int detail_more
= 0, deep_detail_more
= 0;
3295 int detail_total
= 0, deep_detail_total
= 0;
3296 for (auto& p
: pg_stat
) {
3297 int64_t pnum
= p
.first
.pool();
3298 auto pool
= osdmap
.get_pg_pool(pnum
);
3301 if (cct
->_conf
->mon_warn_pg_not_scrubbed_ratio
) {
3302 double scrub_max_interval
= 0;
3303 pool
->opts
.get(pool_opts_t::SCRUB_MAX_INTERVAL
, &scrub_max_interval
);
3304 if (scrub_max_interval
<= 0) {
3305 scrub_max_interval
= cct
->_conf
->osd_scrub_max_interval
;
3307 const double age
= (cct
->_conf
->mon_warn_pg_not_scrubbed_ratio
* scrub_max_interval
) +
3309 utime_t cutoff
= now
;
3311 if (p
.second
.last_scrub_stamp
< cutoff
) {
3312 if (detail_max
> 0) {
3314 ss
<< "pg " << p
.first
<< " not scrubbed since "
3315 << p
.second
.last_scrub_stamp
;
3316 detail
.push_back(ss
.str());
3324 if (cct
->_conf
->mon_warn_pg_not_deep_scrubbed_ratio
) {
3325 double deep_scrub_interval
= 0;
3326 pool
->opts
.get(pool_opts_t::DEEP_SCRUB_INTERVAL
, &deep_scrub_interval
);
3327 if (deep_scrub_interval
<= 0) {
3328 deep_scrub_interval
= cct
->_conf
->osd_deep_scrub_interval
;
3330 double deep_age
= (cct
->_conf
->mon_warn_pg_not_deep_scrubbed_ratio
* deep_scrub_interval
) +
3331 deep_scrub_interval
;
3332 utime_t deep_cutoff
= now
;
3333 deep_cutoff
-= deep_age
;
3334 if (p
.second
.last_deep_scrub_stamp
< deep_cutoff
) {
3335 if (deep_detail_max
> 0) {
3337 ss
<< "pg " << p
.first
<< " not deep-scrubbed since "
3338 << p
.second
.last_deep_scrub_stamp
;
3339 deep_detail
.push_back(ss
.str());
3344 ++deep_detail_total
;
3350 ss
<< detail_total
<< " pgs not scrubbed in time";
3351 auto& d
= checks
->add("PG_NOT_SCRUBBED", HEALTH_WARN
, ss
.str(), detail_total
);
3353 if (!detail
.empty()) {
3354 d
.detail
.swap(detail
);
3358 ss
<< detail_more
<< " more pgs... ";
3359 d
.detail
.push_back(ss
.str());
3363 if (deep_detail_total
) {
3365 ss
<< deep_detail_total
<< " pgs not deep-scrubbed in time";
3366 auto& d
= checks
->add("PG_NOT_DEEP_SCRUBBED", HEALTH_WARN
, ss
.str(),
3369 if (!deep_detail
.empty()) {
3370 d
.detail
.swap(deep_detail
);
3372 if (deep_detail_more
) {
3374 ss
<< deep_detail_more
<< " more pgs... ";
3375 d
.detail
.push_back(ss
.str());
3382 if (g_conf().get_val
<bool>("mon_warn_on_pool_no_app")) {
3383 list
<string
> detail
;
3384 for (auto &it
: pools
) {
3385 const pg_pool_t
&pool
= it
.second
;
3386 const string
& pool_name
= osdmap
.get_pool_name(it
.first
);
3387 auto it2
= pg_pool_sum
.find(it
.first
);
3388 if (it2
== pg_pool_sum
.end()) {
3391 const pool_stat_t
*pstat
= &it2
->second
;
3392 if (pstat
== nullptr) {
3395 const object_stat_sum_t
& sum
= pstat
->stats
.sum
;
3396 // application metadata is not encoded until luminous is minimum
3398 if (sum
.num_objects
> 0 && pool
.application_metadata
.empty() &&
3401 ss
<< "application not enabled on pool '" << pool_name
<< "'";
3402 detail
.push_back(ss
.str());
3405 if (!detail
.empty()) {
3407 ss
<< detail
.size() << " pool(s) do not have an application enabled";
3408 auto& d
= checks
->add("POOL_APP_NOT_ENABLED", HEALTH_WARN
, ss
.str(),
3411 tip
<< "use 'ceph osd pool application enable <pool-name> "
3412 << "<app-name>', where <app-name> is 'cephfs', 'rbd', 'rgw', "
3413 << "or freeform for custom applications.";
3414 detail
.push_back(tip
.str());
3415 d
.detail
.swap(detail
);
3419 // PG_SLOW_SNAP_TRIMMING
3420 if (!pg_stat
.empty() && cct
->_conf
->mon_osd_snap_trim_queue_warn_on
> 0) {
3421 uint32_t snapthreshold
= cct
->_conf
->mon_osd_snap_trim_queue_warn_on
;
3422 uint64_t snaptrimq_exceeded
= 0;
3423 uint32_t longest_queue
= 0;
3424 const pg_t
* longest_q_pg
= nullptr;
3425 list
<string
> detail
;
3427 for (auto& i
: pg_stat
) {
3428 uint32_t current_len
= i
.second
.snaptrimq_len
;
3429 if (current_len
>= snapthreshold
) {
3430 snaptrimq_exceeded
++;
3431 if (longest_queue
<= current_len
) {
3432 longest_q_pg
= &i
.first
;
3433 longest_queue
= current_len
;
3435 if (detail
.size() < max
- 1) {
3437 ss
<< "snap trim queue for pg " << i
.first
<< " at " << current_len
;
3438 detail
.push_back(ss
.str());
3441 if (detail
.size() < max
) {
3442 detail
.push_back("...more pgs affected");
3448 if (snaptrimq_exceeded
) {
3451 ss
<< "longest queue on pg " << *longest_q_pg
<< " at " << longest_queue
;
3452 detail
.push_back(ss
.str());
3456 ss
<< "snap trim queue for " << snaptrimq_exceeded
<< " pg(s) >= " << snapthreshold
<< " (mon_osd_snap_trim_queue_warn_on)";
3457 auto& d
= checks
->add("PG_SLOW_SNAP_TRIMMING", HEALTH_WARN
, ss
.str(),
3458 snaptrimq_exceeded
);
3459 detail
.push_back("try decreasing \"osd snap trim sleep\" and/or increasing \"osd pg max concurrent snap trims\".");
3460 d
.detail
.swap(detail
);
3465 void PGMap::print_summary(ceph::Formatter
*f
, ostream
*out
) const
3468 f
->open_array_section("pgs_by_pool_state");
3469 for (auto& i
: num_pg_by_pool_state
) {
3470 f
->open_object_section("per_pool_pgs_by_state");
3471 f
->dump_int("pool_id", i
.first
);
3472 f
->open_array_section("pg_state_counts");
3473 for (auto& j
: i
.second
) {
3474 f
->open_object_section("pg_state_count");
3475 f
->dump_string("state_name", pg_state_string(j
.first
));
3476 f
->dump_int("count", j
.second
);
3484 PGMapDigest::print_summary(f
, out
);
3487 int process_pg_map_command(
3488 const string
& orig_prefix
,
3489 const cmdmap_t
& orig_cmdmap
,
3490 const PGMap
& pg_map
,
3491 const OSDMap
& osdmap
,
3496 string prefix
= orig_prefix
;
3497 auto cmdmap
= orig_cmdmap
;
3499 string omap_stats_note
=
3500 "\n* NOTE: Omap statistics are gathered during deep scrub and "
3501 "may be inaccurate soon afterwards depending on utilization. See "
3502 "http://docs.ceph.com/en/latest/dev/placement-group/#omap-statistics "
3503 "for further details.\n";
3504 bool omap_stats_note_required
= false;
3506 // perhaps these would be better in the parsing, but it's weird
3507 bool primary
= false;
3508 if (prefix
== "pg dump_json") {
3510 v
.push_back(string("all"));
3511 cmd_putval(g_ceph_context
, cmdmap
, "dumpcontents", v
);
3513 } else if (prefix
== "pg dump_pools_json") {
3515 v
.push_back(string("pools"));
3516 cmd_putval(g_ceph_context
, cmdmap
, "dumpcontents", v
);
3518 } else if (prefix
== "pg ls-by-primary") {
3521 } else if (prefix
== "pg ls-by-osd") {
3523 } else if (prefix
== "pg ls-by-pool") {
3526 cmd_getval(cmdmap
, "poolstr", poolstr
);
3527 int64_t pool
= osdmap
.lookup_pg_pool_name(poolstr
.c_str());
3529 *ss
<< "pool " << poolstr
<< " does not exist";
3532 cmd_putval(g_ceph_context
, cmdmap
, "pool", pool
);
3536 if (prefix
== "pg stat") {
3538 f
->open_object_section("pg_summary");
3539 pg_map
.print_oneline_summary(f
, NULL
);
3549 if (prefix
== "pg getmap") {
3550 pg_map
.encode(*odata
);
3551 *ss
<< "got pgmap version " << pg_map
.version
;
3555 if (prefix
== "pg dump") {
3557 vector
<string
> dumpcontents
;
3559 if (cmd_getval(cmdmap
, "dumpcontents", dumpcontents
)) {
3560 copy(dumpcontents
.begin(), dumpcontents
.end(),
3561 inserter(what
, what
.end()));
3566 if (what
.count("all")) {
3567 f
->open_object_section("pg_map");
3570 } else if (what
.count("summary") || what
.count("sum")) {
3571 f
->open_object_section("pg_map");
3572 pg_map
.dump_basic(f
);
3575 if (what
.count("pools")) {
3576 pg_map
.dump_pool_stats(f
);
3578 if (what
.count("osds")) {
3579 pg_map
.dump_osd_stats(f
);
3581 if (what
.count("pgs")) {
3582 pg_map
.dump_pg_stats(f
, false);
3584 if (what
.count("pgs_brief")) {
3585 pg_map
.dump_pg_stats(f
, true);
3587 if (what
.count("delta")) {
3588 f
->open_object_section("delta");
3589 pg_map
.dump_delta(f
);
3595 if (what
.count("all")) {
3597 omap_stats_note_required
= true;
3598 } else if (what
.count("summary") || what
.count("sum")) {
3599 pg_map
.dump_basic(ds
);
3600 pg_map
.dump_pg_sum_stats(ds
, true);
3601 pg_map
.dump_osd_sum_stats(ds
);
3602 omap_stats_note_required
= true;
3604 if (what
.count("pgs_brief")) {
3605 pg_map
.dump_pg_stats(ds
, true);
3608 if (what
.count("pgs")) {
3609 pg_map
.dump_pg_stats(ds
, false);
3611 omap_stats_note_required
= true;
3613 if (what
.count("pools")) {
3614 pg_map
.dump_pool_stats(ds
, header
);
3615 omap_stats_note_required
= true;
3617 if (what
.count("osds")) {
3618 pg_map
.dump_osd_stats(ds
);
3622 if (omap_stats_note_required
) {
3623 odata
->append(omap_stats_note
);
3626 *ss
<< "dumped " << what
;
3630 if (prefix
== "pg ls") {
3633 vector
<string
>states
;
3635 cmd_getval(cmdmap
, "pool", pool
);
3636 cmd_getval(cmdmap
, "osd", osd
);
3637 cmd_getval(cmdmap
, "states", states
);
3638 if (pool
>= 0 && !osdmap
.have_pg_pool(pool
)) {
3639 *ss
<< "pool " << pool
<< " does not exist";
3642 if (osd
>= 0 && !osdmap
.is_up(osd
)) {
3643 *ss
<< "osd " << osd
<< " is not up";
3647 states
.push_back("all");
3651 while (!states
.empty()) {
3652 string state_str
= states
.back();
3654 if (state_str
== "all") {
3658 auto filter
= pg_string_state(state_str
);
3660 *ss
<< "'" << state_str
<< "' is not a valid pg state,"
3661 << " available choices: " << pg_state_string(0xFFFFFFFF);
3670 pg_map
.get_filtered_pg_stats(state
, pool
, osd
, primary
, pgs
);
3672 if (f
&& !pgs
.empty()) {
3673 pg_map
.dump_filtered_pg_stats(f
, pgs
);
3675 } else if (!pgs
.empty()) {
3676 pg_map
.dump_filtered_pg_stats(ds
, pgs
);
3678 odata
->append(omap_stats_note
);
3683 if (prefix
== "pg dump_stuck") {
3684 vector
<string
> stuckop_vec
;
3685 cmd_getval(cmdmap
, "stuckops", stuckop_vec
);
3686 if (stuckop_vec
.empty())
3687 stuckop_vec
.push_back("unclean");
3689 cmd_getval(cmdmap
, "threshold", threshold
,
3690 g_conf().get_val
<int64_t>("mon_pg_stuck_threshold"));
3692 if (pg_map
.dump_stuck_pg_stats(ds
, f
, (int)threshold
, stuckop_vec
) < 0) {
3701 if (prefix
== "pg debug") {
3703 cmd_getval(cmdmap
, "debugop", debugop
,
3704 string("unfound_objects_exist"));
3705 if (debugop
== "unfound_objects_exist") {
3706 bool unfound_objects_exist
= false;
3707 for (const auto& p
: pg_map
.pg_stat
) {
3708 if (p
.second
.stats
.sum
.num_objects_unfound
> 0) {
3709 unfound_objects_exist
= true;
3713 if (unfound_objects_exist
)
3720 if (debugop
== "degraded_pgs_exist") {
3721 bool degraded_pgs_exist
= false;
3722 for (const auto& p
: pg_map
.pg_stat
) {
3723 if (p
.second
.stats
.sum
.num_objects_degraded
> 0) {
3724 degraded_pgs_exist
= true;
3728 if (degraded_pgs_exist
)
3737 if (prefix
== "osd perf") {
3739 f
->open_object_section("osdstats");
3740 pg_map
.dump_osd_perf_stats(f
);
3744 pg_map
.print_osd_perf_stats(&ds
);
3750 if (prefix
== "osd blocked-by") {
3752 f
->open_object_section("osd_blocked_by");
3753 pg_map
.dump_osd_blocked_by_stats(f
);
3757 pg_map
.print_osd_blocked_by_stats(&ds
);
3766 void PGMapUpdater::check_osd_map(
3768 const OSDMap
& osdmap
,
3770 PGMap::Incremental
*pending_inc
)
3772 for (auto& p
: pgmap
.osd_stat
) {
3773 if (!osdmap
.exists(p
.first
)) {
3775 pending_inc
->rm_stat(p
.first
);
3776 } else if (osdmap
.is_out(p
.first
)) {
3778 if (p
.second
.statfs
.total
!= 0) {
3779 pending_inc
->stat_osd_out(p
.first
);
3781 } else if (!osdmap
.is_up(p
.first
)) {
3782 // zero the op_queue_age_hist
3783 if (!p
.second
.op_queue_age_hist
.empty()) {
3784 pending_inc
->stat_osd_down_up(p
.first
, pgmap
);
3789 // deleted pgs (pools)?
3790 for (auto& p
: pgmap
.pg_pool_sum
) {
3791 if (!osdmap
.have_pg_pool(p
.first
)) {
3792 ldout(cct
, 10) << __func__
<< " pool " << p
.first
<< " gone, removing pgs"
3794 for (auto& q
: pgmap
.pg_stat
) {
3795 if (q
.first
.pool() == p
.first
) {
3796 pending_inc
->pg_remove
.insert(q
.first
);
3799 auto q
= pending_inc
->pg_stat_updates
.begin();
3800 while (q
!= pending_inc
->pg_stat_updates
.end()) {
3801 if (q
->first
.pool() == p
.first
) {
3802 q
= pending_inc
->pg_stat_updates
.erase(q
);
3810 // new (split or new pool) or merged pgs?
3811 map
<int64_t,unsigned> new_pg_num
;
3812 for (auto& p
: osdmap
.get_pools()) {
3813 int64_t poolid
= p
.first
;
3814 const pg_pool_t
& pi
= p
.second
;
3815 auto q
= pgmap
.num_pg_by_pool
.find(poolid
);
3816 unsigned my_pg_num
= 0;
3817 if (q
!= pgmap
.num_pg_by_pool
.end())
3818 my_pg_num
= q
->second
;
3819 unsigned pg_num
= pi
.get_pg_num();
3820 new_pg_num
[poolid
] = pg_num
;
3821 if (my_pg_num
< pg_num
) {
3822 ldout(cct
,10) << __func__
<< " pool " << poolid
<< " pg_num " << pg_num
3823 << " > my pg_num " << my_pg_num
<< dendl
;
3824 for (unsigned ps
= my_pg_num
; ps
< pg_num
; ++ps
) {
3825 pg_t
pgid(ps
, poolid
);
3826 if (pending_inc
->pg_stat_updates
.count(pgid
) == 0) {
3827 ldout(cct
,20) << __func__
<< " adding " << pgid
<< dendl
;
3828 pg_stat_t
&stats
= pending_inc
->pg_stat_updates
[pgid
];
3829 stats
.last_fresh
= osdmap
.get_modified();
3830 stats
.last_active
= osdmap
.get_modified();
3831 stats
.last_change
= osdmap
.get_modified();
3832 stats
.last_peered
= osdmap
.get_modified();
3833 stats
.last_clean
= osdmap
.get_modified();
3834 stats
.last_unstale
= osdmap
.get_modified();
3835 stats
.last_undegraded
= osdmap
.get_modified();
3836 stats
.last_fullsized
= osdmap
.get_modified();
3837 stats
.last_scrub_stamp
= osdmap
.get_modified();
3838 stats
.last_deep_scrub_stamp
= osdmap
.get_modified();
3839 stats
.last_clean_scrub_stamp
= osdmap
.get_modified();
3842 } else if (my_pg_num
> pg_num
) {
3843 ldout(cct
,10) << __func__
<< " pool " << poolid
<< " pg_num " << pg_num
3844 << " < my pg_num " << my_pg_num
<< dendl
;
3845 for (unsigned i
= pg_num
; i
< my_pg_num
; ++i
) {
3846 pg_t
pgid(i
, poolid
);
3847 ldout(cct
,20) << __func__
<< " removing merged " << pgid
<< dendl
;
3848 if (pgmap
.pg_stat
.count(pgid
)) {
3849 pending_inc
->pg_remove
.insert(pgid
);
3851 pending_inc
->pg_stat_updates
.erase(pgid
);
3855 auto i
= pending_inc
->pg_stat_updates
.begin();
3856 while (i
!= pending_inc
->pg_stat_updates
.end()) {
3857 auto j
= new_pg_num
.find(i
->first
.pool());
3858 if (j
== new_pg_num
.end() ||
3859 i
->first
.ps() >= j
->second
) {
3860 ldout(cct
,20) << __func__
<< " removing pending update to old "
3861 << i
->first
<< dendl
;
3862 i
= pending_inc
->pg_stat_updates
.erase(i
);
3869 static void _try_mark_pg_stale(
3870 const OSDMap
& osdmap
,
3872 const pg_stat_t
& cur
,
3873 PGMap::Incremental
*pending_inc
)
3875 if ((cur
.state
& PG_STATE_STALE
) == 0 &&
3876 cur
.acting_primary
!= -1 &&
3877 osdmap
.is_down(cur
.acting_primary
)) {
3879 auto q
= pending_inc
->pg_stat_updates
.find(pgid
);
3880 if (q
!= pending_inc
->pg_stat_updates
.end()) {
3881 if ((q
->second
.acting_primary
== cur
.acting_primary
) ||
3882 ((q
->second
.state
& PG_STATE_STALE
) == 0 &&
3883 q
->second
.acting_primary
!= -1 &&
3884 osdmap
.is_down(q
->second
.acting_primary
))) {
3885 newstat
= &q
->second
;
3887 // pending update is no longer down or already stale
3891 newstat
= &pending_inc
->pg_stat_updates
[pgid
];
3894 dout(10) << __func__
<< " marking pg " << pgid
3895 << " stale (acting_primary " << newstat
->acting_primary
3897 newstat
->state
|= PG_STATE_STALE
;
3898 newstat
->last_unstale
= ceph_clock_now();
3902 void PGMapUpdater::check_down_pgs(
3903 const OSDMap
&osdmap
,
3904 const PGMap
&pg_map
,
3906 const set
<int>& need_check_down_pg_osds
,
3907 PGMap::Incremental
*pending_inc
)
3909 // if a large number of osds changed state, just iterate over the whole
3911 if (need_check_down_pg_osds
.size() > (unsigned)osdmap
.get_num_osds() *
3912 g_conf().get_val
<double>("mon_pg_check_down_all_threshold")) {
3917 for (const auto& p
: pg_map
.pg_stat
) {
3918 _try_mark_pg_stale(osdmap
, p
.first
, p
.second
, pending_inc
);
3921 for (auto osd
: need_check_down_pg_osds
) {
3922 if (osdmap
.is_down(osd
)) {
3923 auto p
= pg_map
.pg_by_osd
.find(osd
);
3924 if (p
== pg_map
.pg_by_osd
.end()) {
3927 for (auto pgid
: p
->second
) {
3928 const pg_stat_t
&stat
= pg_map
.pg_stat
.at(pgid
);
3929 ceph_assert(stat
.acting_primary
== osd
);
3930 _try_mark_pg_stale(osdmap
, pgid
, stat
, pending_inc
);
3937 int reweight::by_utilization(
3938 const OSDMap
&osdmap
,
3943 bool by_pg
, const set
<int64_t> *pools
,
3945 mempool::osdmap::map
<int32_t, uint32_t>* new_weights
,
3946 std::stringstream
*ss
,
3947 std::string
*out_str
,
3951 *ss
<< "You must give a percentage higher than 100. "
3952 "The reweighting threshold will be calculated as <average-utilization> "
3953 "times <input-percentage>. For example, an argument of 200 would "
3954 "reweight OSDs which are twice as utilized as the average OSD.\n";
3958 vector
<int> pgs_by_osd(osdmap
.get_max_osd());
3960 // Avoid putting a small number (or 0) in the denominator when calculating
3962 double average_util
;
3965 double weight_sum
= 0.0; // sum up the crush weights
3966 unsigned num_pg_copies
= 0;
3968 for (const auto& pg
: pgm
.pg_stat
) {
3969 if (pools
&& pools
->count(pg
.first
.pool()) == 0)
3971 for (const auto acting
: pg
.second
.acting
) {
3972 if (!osdmap
.exists(acting
)) {
3975 if (acting
>= (int)pgs_by_osd
.size())
3976 pgs_by_osd
.resize(acting
);
3977 if (pgs_by_osd
[acting
] == 0) {
3978 if (osdmap
.crush
->get_item_weightf(acting
) <= 0) {
3979 //skip if we currently can not identify item
3982 weight_sum
+= osdmap
.crush
->get_item_weightf(acting
);
3985 ++pgs_by_osd
[acting
];
3990 if (!num_osds
|| (num_pg_copies
/ num_osds
< g_conf()->mon_reweight_min_pgs_per_osd
)) {
3991 *ss
<< "Refusing to reweight: we only have " << num_pg_copies
3992 << " PGs across " << num_osds
<< " osds!\n";
3996 average_util
= (double)num_pg_copies
/ weight_sum
;
3998 // by osd utilization
3999 int num_osd
= std::max
<size_t>(1, pgm
.osd_stat
.size());
4000 if ((uint64_t)pgm
.osd_sum
.statfs
.total
/ num_osd
4001 < g_conf()->mon_reweight_min_bytes_per_osd
) {
4002 *ss
<< "Refusing to reweight: we only have " << pgm
.osd_sum
.statfs
.kb()
4003 << " kb across all osds!\n";
4006 if ((uint64_t)pgm
.osd_sum
.statfs
.get_used_raw() / num_osd
4007 < g_conf()->mon_reweight_min_bytes_per_osd
) {
4008 *ss
<< "Refusing to reweight: we only have "
4009 << pgm
.osd_sum
.statfs
.kb_used_raw()
4010 << " kb used across all osds!\n";
4014 average_util
= (double)pgm
.osd_sum
.statfs
.get_used_raw() /
4015 (double)pgm
.osd_sum
.statfs
.total
;
4018 // adjust down only if we are above the threshold
4019 const double overload_util
= average_util
* (double)oload
/ 100.0;
4021 // but aggressively adjust weights up whenever possible.
4022 const double underload_util
= average_util
;
4024 const unsigned max_change
= (unsigned)(max_changef
* (double)0x10000);
4028 f
->open_object_section("reweight_by_utilization");
4029 f
->dump_int("overload_min", oload
);
4030 f
->dump_float("max_change", max_changef
);
4031 f
->dump_int("max_change_osds", max_osds
);
4032 f
->dump_float("average_utilization", average_util
);
4033 f
->dump_float("overload_utilization", overload_util
);
4035 oss
<< "oload " << oload
<< "\n";
4036 oss
<< "max_change " << max_changef
<< "\n";
4037 oss
<< "max_change_osds " << max_osds
<< "\n";
4039 oss
<< "average_utilization " << std::fixed
<< average_util
<< "\n";
4040 oss
<< "overload_utilization " << overload_util
<< "\n";
4042 int num_changed
= 0;
4044 // precompute util for each OSD
4045 std::vector
<std::pair
<int, float> > util_by_osd
;
4046 for (const auto& p
: pgm
.osd_stat
) {
4047 std::pair
<int, float> osd_util
;
4048 osd_util
.first
= p
.first
;
4050 if (p
.first
>= (int)pgs_by_osd
.size() ||
4051 pgs_by_osd
[p
.first
] == 0) {
4052 // skip if this OSD does not contain any pg
4053 // belonging to the specified pool(s).
4057 if (osdmap
.crush
->get_item_weightf(p
.first
) <= 0) {
4058 // skip if we are unable to locate item.
4063 pgs_by_osd
[p
.first
] / osdmap
.crush
->get_item_weightf(p
.first
);
4066 (double)p
.second
.statfs
.get_used_raw() / (double)p
.second
.statfs
.total
;
4068 util_by_osd
.push_back(osd_util
);
4071 // sort by absolute deviation from the mean utilization,
4072 // in descending order.
4073 std::sort(util_by_osd
.begin(), util_by_osd
.end(),
4074 [average_util
](std::pair
<int, float> l
, std::pair
<int, float> r
) {
4075 return abs(l
.second
- average_util
) > abs(r
.second
- average_util
);
4080 f
->open_array_section("reweights");
4082 for (const auto& p
: util_by_osd
) {
4083 unsigned weight
= osdmap
.get_weight(p
.first
);
4085 // skip if OSD is currently out
4088 float util
= p
.second
;
4090 if (util
>= overload_util
) {
4091 // Assign a lower weight to overloaded OSDs. The current weight
4092 // is a factor to take into account the original weights,
4093 // to represent e.g. differing storage capacities
4094 unsigned new_weight
= (unsigned)((average_util
/ util
) * (float)weight
);
4095 if (weight
> max_change
)
4096 new_weight
= std::max(new_weight
, weight
- max_change
);
4097 new_weights
->insert({p
.first
, new_weight
});
4099 f
->open_object_section("osd");
4100 f
->dump_int("osd", p
.first
);
4101 f
->dump_float("weight", (float)weight
/ (float)0x10000);
4102 f
->dump_float("new_weight", (float)new_weight
/ (float)0x10000);
4105 oss
<< "osd." << p
.first
<< " weight "
4106 << (float)weight
/ (float)0x10000 << " -> "
4107 << (float)new_weight
/ (float)0x10000 << "\n";
4109 if (++num_changed
>= max_osds
)
4112 if (!no_increasing
&& util
<= underload_util
) {
4113 // assign a higher weight.. if we can.
4114 unsigned new_weight
= (unsigned)((average_util
/ util
) * (float)weight
);
4115 new_weight
= std::min(new_weight
, weight
+ max_change
);
4116 if (new_weight
> 0x10000)
4117 new_weight
= 0x10000;
4118 if (new_weight
> weight
) {
4119 new_weights
->insert({p
.first
, new_weight
});
4120 oss
<< "osd." << p
.first
<< " weight "
4121 << (float)weight
/ (float)0x10000 << " -> "
4122 << (float)new_weight
/ (float)0x10000 << "\n";
4123 if (++num_changed
>= max_osds
)
4133 newmap
.deepish_copy_from(osdmap
);
4134 OSDMap::Incremental newinc
;
4135 newinc
.fsid
= newmap
.get_fsid();
4136 newinc
.epoch
= newmap
.get_epoch() + 1;
4137 newinc
.new_weight
= *new_weights
;
4138 newmap
.apply_incremental(newinc
);
4140 osdmap
.summarize_mapping_stats(&newmap
, pools
, out_str
, f
);
4146 *out_str
+= oss
.str();