-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPGMap.cc
4139 lines (3821 loc) · 129 KB
/
PGMap.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#include <boost/algorithm/string.hpp>
#include "PGMap.h"
#define dout_subsys ceph_subsys_mon
#include "common/debug.h"
#include "common/Clock.h"
#include "common/Formatter.h"
#include "global/global_context.h"
#include "include/ceph_features.h"
#include "include/stringify.h"
#include "osd/osd_types.h"
#include "osd/OSDMap.h"
#include <boost/range/adaptor/reversed.hpp>
#define dout_context g_ceph_context
using std::list;
using std::make_pair;
using std::map;
using std::pair;
using std::ostream;
using std::ostringstream;
using std::set;
using std::string;
using std::stringstream;
using std::vector;
using ceph::bufferlist;
using ceph::fixed_u_to_string;
using TOPNSPC::common::cmd_getval;
MEMPOOL_DEFINE_OBJECT_FACTORY(PGMapDigest, pgmap_digest, pgmap);
MEMPOOL_DEFINE_OBJECT_FACTORY(PGMap, pgmap, pgmap);
MEMPOOL_DEFINE_OBJECT_FACTORY(PGMap::Incremental, pgmap_inc, pgmap);
// ---------------------
// PGMapDigest
void PGMapDigest::encode(bufferlist& bl, uint64_t features) const
{
// NOTE: see PGMap::encode_digest
uint8_t v = 4;
if (!HAVE_FEATURE(features, SERVER_MIMIC)) {
v = 1;
} else if (!HAVE_FEATURE(features, SERVER_NAUTILUS)) {
v = 3;
}
ENCODE_START(v, 1, bl);
encode(num_pg, bl);
encode(num_pg_active, bl);
encode(num_pg_unknown, bl);
encode(num_osd, bl);
encode(pg_pool_sum, bl, features);
encode(pg_sum, bl, features);
encode(osd_sum, bl, features);
if (v >= 2) {
encode(num_pg_by_state, bl);
} else {
uint32_t n = num_pg_by_state.size();
encode(n, bl);
for (auto p : num_pg_by_state) {
encode((int32_t)p.first, bl);
encode(p.second, bl);
}
}
encode(num_pg_by_osd, bl);
encode(num_pg_by_pool, bl);
encode(osd_last_seq, bl);
encode(per_pool_sum_delta, bl, features);
encode(per_pool_sum_deltas_stamps, bl);
encode(pg_sum_delta, bl, features);
encode(stamp_delta, bl);
encode(avail_space_by_rule, bl);
if (struct_v >= 3) {
encode(purged_snaps, bl);
}
if (struct_v >= 4) {
encode(osd_sum_by_class, bl, features);
}
ENCODE_FINISH(bl);
}
void PGMapDigest::decode(bufferlist::const_iterator& p)
{
DECODE_START(4, p);
decode(num_pg, p);
decode(num_pg_active, p);
decode(num_pg_unknown, p);
decode(num_osd, p);
decode(pg_pool_sum, p);
decode(pg_sum, p);
decode(osd_sum, p);
if (struct_v >= 2) {
decode(num_pg_by_state, p);
} else {
map<int32_t, int32_t> nps;
decode(nps, p);
num_pg_by_state.clear();
for (auto i : nps) {
num_pg_by_state[i.first] = i.second;
}
}
decode(num_pg_by_osd, p);
decode(num_pg_by_pool, p);
decode(osd_last_seq, p);
decode(per_pool_sum_delta, p);
decode(per_pool_sum_deltas_stamps, p);
decode(pg_sum_delta, p);
decode(stamp_delta, p);
decode(avail_space_by_rule, p);
if (struct_v >= 3) {
decode(purged_snaps, p);
}
if (struct_v >= 4) {
decode(osd_sum_by_class, p);
}
DECODE_FINISH(p);
}
void PGMapDigest::dump(ceph::Formatter *f) const
{
f->dump_unsigned("num_pg", num_pg);
f->dump_unsigned("num_pg_active", num_pg_active);
f->dump_unsigned("num_pg_unknown", num_pg_unknown);
f->dump_unsigned("num_osd", num_osd);
f->dump_object("pool_sum", pg_sum);
f->dump_object("osd_sum", osd_sum);
f->open_object_section("osd_sum_by_class");
for (auto& i : osd_sum_by_class) {
f->dump_object(i.first.c_str(), i.second);
}
f->close_section();
f->open_array_section("pool_stats");
for (auto& p : pg_pool_sum) {
f->open_object_section("pool_stat");
f->dump_int("poolid", p.first);
auto q = num_pg_by_pool.find(p.first);
if (q != num_pg_by_pool.end())
f->dump_unsigned("num_pg", q->second);
p.second.dump(f);
f->close_section();
}
f->close_section();
f->open_array_section("osd_stats");
int i = 0;
// TODO: this isn't really correct since we can dump non-existent OSDs
// I dunno what osd_last_seq is set to in that case...
for (auto& p : osd_last_seq) {
f->open_object_section("osd_stat");
f->dump_int("osd", i);
f->dump_unsigned("seq", p);
f->close_section();
++i;
}
f->close_section();
f->open_array_section("num_pg_by_state");
for (auto& p : num_pg_by_state) {
f->open_object_section("count");
f->dump_string("state", pg_state_string(p.first));
f->dump_unsigned("num", p.second);
f->close_section();
}
f->close_section();
f->open_array_section("num_pg_by_osd");
for (auto& p : num_pg_by_osd) {
f->open_object_section("count");
f->dump_unsigned("osd", p.first);
f->dump_unsigned("num_primary_pg", p.second.primary);
f->dump_unsigned("num_acting_pg", p.second.acting);
f->dump_unsigned("num_up_not_acting_pg", p.second.up_not_acting);
f->close_section();
}
f->close_section();
f->open_array_section("purged_snaps");
for (auto& j : purged_snaps) {
f->open_object_section("pool");
f->dump_int("pool", j.first);
f->open_object_section("purged_snaps");
for (auto i = j.second.begin(); i != j.second.end(); ++i) {
f->open_object_section("interval");
f->dump_stream("start") << i.get_start();
f->dump_stream("length") << i.get_len();
f->close_section();
}
f->close_section();
f->close_section();
}
f->close_section();
}
void PGMapDigest::generate_test_instances(list<PGMapDigest*>& ls)
{
ls.push_back(new PGMapDigest);
}
inline std::string percentify(const float& a) {
std::stringstream ss;
if (a < 0.01)
ss << "0";
else
ss << std::fixed << std::setprecision(2) << a;
return ss.str();
}
void PGMapDigest::print_summary(ceph::Formatter *f, ostream *out) const
{
if (f)
f->open_array_section("pgs_by_state");
// list is descending numeric order (by count)
std::multimap<int,uint64_t> state_by_count; // count -> state
for (auto p = num_pg_by_state.begin();
p != num_pg_by_state.end();
++p) {
state_by_count.insert(make_pair(p->second, p->first));
}
if (f) {
for (auto p = state_by_count.rbegin();
p != state_by_count.rend();
++p)
{
f->open_object_section("pgs_by_state_element");
f->dump_string("state_name", pg_state_string(p->second));
f->dump_unsigned("count", p->first);
f->close_section();
}
}
if (f)
f->close_section();
if (f) {
f->dump_unsigned("num_pgs", num_pg);
f->dump_unsigned("num_pools", pg_pool_sum.size());
f->dump_unsigned("num_objects", pg_sum.stats.sum.num_objects);
f->dump_unsigned("data_bytes", pg_sum.stats.sum.num_bytes);
f->dump_unsigned("bytes_used", osd_sum.statfs.get_used_raw());
f->dump_unsigned("bytes_avail", osd_sum.statfs.available);
f->dump_unsigned("bytes_total", osd_sum.statfs.total);
} else {
*out << " pools: " << pg_pool_sum.size() << " pools, "
<< num_pg << " pgs\n";
*out << " objects: " << si_u_t(pg_sum.stats.sum.num_objects) << " objects, "
<< byte_u_t(pg_sum.stats.sum.num_bytes) << "\n";
*out << " usage: "
<< byte_u_t(osd_sum.statfs.get_used_raw()) << " used, "
<< byte_u_t(osd_sum.statfs.available) << " / "
<< byte_u_t(osd_sum.statfs.total) << " avail\n";
*out << " pgs: ";
}
bool pad = false;
if (num_pg_unknown > 0) {
float p = (float)num_pg_unknown / (float)num_pg;
if (f) {
f->dump_float("unknown_pgs_ratio", p);
} else {
char b[20];
snprintf(b, sizeof(b), "%.3lf", p * 100.0);
*out << b << "% pgs unknown\n";
pad = true;
}
}
int num_pg_inactive = num_pg - num_pg_active - num_pg_unknown;
if (num_pg_inactive > 0) {
float p = (float)num_pg_inactive / (float)num_pg;
if (f) {
f->dump_float("inactive_pgs_ratio", p);
} else {
if (pad) {
*out << " ";
}
char b[20];
snprintf(b, sizeof(b), "%.3f", p * 100.0);
*out << b << "% pgs not active\n";
pad = true;
}
}
list<string> sl;
overall_recovery_summary(f, &sl);
if (!f && !sl.empty()) {
for (auto p = sl.begin(); p != sl.end(); ++p) {
if (pad) {
*out << " ";
}
*out << *p << "\n";
pad = true;
}
}
sl.clear();
if (!f) {
unsigned max_width = 1;
for (auto p = state_by_count.rbegin(); p != state_by_count.rend(); ++p)
{
std::stringstream ss;
ss << p->first;
max_width = std::max<size_t>(ss.str().size(), max_width);
}
for (auto p = state_by_count.rbegin(); p != state_by_count.rend(); ++p)
{
if (pad) {
*out << " ";
}
pad = true;
out->setf(std::ios::left);
*out << std::setw(max_width) << p->first
<< " " << pg_state_string(p->second) << "\n";
out->unsetf(std::ios::left);
}
}
ostringstream ss_rec_io;
overall_recovery_rate_summary(f, &ss_rec_io);
ostringstream ss_client_io;
overall_client_io_rate_summary(f, &ss_client_io);
ostringstream ss_cache_io;
overall_cache_io_rate_summary(f, &ss_cache_io);
if (!f && (ss_client_io.str().length() || ss_rec_io.str().length()
|| ss_cache_io.str().length())) {
*out << "\n \n";
*out << " io:\n";
}
if (!f && ss_client_io.str().length())
*out << " client: " << ss_client_io.str() << "\n";
if (!f && ss_rec_io.str().length())
*out << " recovery: " << ss_rec_io.str() << "\n";
if (!f && ss_cache_io.str().length())
*out << " cache: " << ss_cache_io.str() << "\n";
}
void PGMapDigest::print_oneline_summary(ceph::Formatter *f, ostream *out) const
{
std::stringstream ss;
if (f)
f->open_array_section("num_pg_by_state");
for (auto p = num_pg_by_state.begin();
p != num_pg_by_state.end();
++p) {
if (f) {
f->open_object_section("state");
f->dump_string("name", pg_state_string(p->first));
f->dump_unsigned("num", p->second);
f->close_section();
}
if (p != num_pg_by_state.begin())
ss << ", ";
ss << p->second << " " << pg_state_string(p->first);
}
if (f)
f->close_section();
string states = ss.str();
if (out)
*out << num_pg << " pgs: "
<< states << "; "
<< byte_u_t(pg_sum.stats.sum.num_bytes) << " data, "
<< byte_u_t(osd_sum.statfs.get_used()) << " used, "
<< byte_u_t(osd_sum.statfs.available) << " / "
<< byte_u_t(osd_sum.statfs.total) << " avail";
if (f) {
f->dump_unsigned("num_pgs", num_pg);
f->dump_unsigned("num_bytes", pg_sum.stats.sum.num_bytes);
f->dump_int("total_bytes", osd_sum.statfs.total);
f->dump_int("total_avail_bytes", osd_sum.statfs.available);
f->dump_int("total_used_bytes", osd_sum.statfs.get_used());
f->dump_int("total_used_raw_bytes", osd_sum.statfs.get_used_raw());
}
// make non-negative; we can get negative values if osds send
// uncommitted stats and then "go backward" or if they are just
// buggy/wrong.
pool_stat_t pos_delta = pg_sum_delta;
pos_delta.floor(0);
if (pos_delta.stats.sum.num_rd ||
pos_delta.stats.sum.num_wr) {
if (out)
*out << "; ";
if (pos_delta.stats.sum.num_rd) {
int64_t rd = (pos_delta.stats.sum.num_rd_kb << 10) / (double)stamp_delta;
if (out)
*out << byte_u_t(rd) << "/s rd, ";
if (f)
f->dump_unsigned("read_bytes_sec", rd);
}
if (pos_delta.stats.sum.num_wr) {
int64_t wr = (pos_delta.stats.sum.num_wr_kb << 10) / (double)stamp_delta;
if (out)
*out << byte_u_t(wr) << "/s wr, ";
if (f)
f->dump_unsigned("write_bytes_sec", wr);
}
int64_t iops = (pos_delta.stats.sum.num_rd + pos_delta.stats.sum.num_wr) / (double)stamp_delta;
if (out)
*out << si_u_t(iops) << " op/s";
if (f)
f->dump_unsigned("io_sec", iops);
}
list<string> sl;
overall_recovery_summary(f, &sl);
if (out)
for (auto p = sl.begin(); p != sl.end(); ++p)
*out << "; " << *p;
std::stringstream ssr;
overall_recovery_rate_summary(f, &ssr);
if (out && ssr.str().length())
*out << "; " << ssr.str() << " recovering";
}
void PGMapDigest::get_recovery_stats(
double *misplaced_ratio,
double *degraded_ratio,
double *inactive_pgs_ratio,
double *unknown_pgs_ratio) const
{
if (pg_sum.stats.sum.num_objects_degraded &&
pg_sum.stats.sum.num_object_copies > 0) {
*degraded_ratio = (double)pg_sum.stats.sum.num_objects_degraded /
(double)pg_sum.stats.sum.num_object_copies;
} else {
*degraded_ratio = 0;
}
if (pg_sum.stats.sum.num_objects_misplaced &&
pg_sum.stats.sum.num_object_copies > 0) {
*misplaced_ratio = (double)pg_sum.stats.sum.num_objects_misplaced /
(double)pg_sum.stats.sum.num_object_copies;
} else {
*misplaced_ratio = 0;
}
if (num_pg > 0) {
int num_pg_inactive = num_pg - num_pg_active - num_pg_unknown;
*inactive_pgs_ratio = (double)num_pg_inactive / (double)num_pg;
*unknown_pgs_ratio = (double)num_pg_unknown / (double)num_pg;
} else {
*inactive_pgs_ratio = 0;
*unknown_pgs_ratio = 0;
}
}
void PGMapDigest::recovery_summary(ceph::Formatter *f, list<string> *psl,
const pool_stat_t& pool_sum) const
{
if (pool_sum.stats.sum.num_objects_degraded && pool_sum.stats.sum.num_object_copies > 0) {
double pc = (double)pool_sum.stats.sum.num_objects_degraded /
(double)pool_sum.stats.sum.num_object_copies * (double)100.0;
char b[20];
snprintf(b, sizeof(b), "%.3lf", pc);
if (f) {
f->dump_unsigned("degraded_objects", pool_sum.stats.sum.num_objects_degraded);
f->dump_unsigned("degraded_total", pool_sum.stats.sum.num_object_copies);
f->dump_float("degraded_ratio", pc / 100.0);
} else {
ostringstream ss;
ss << pool_sum.stats.sum.num_objects_degraded
<< "/" << pool_sum.stats.sum.num_object_copies << " objects degraded (" << b << "%)";
psl->push_back(ss.str());
}
}
if (pool_sum.stats.sum.num_objects_misplaced && pool_sum.stats.sum.num_object_copies > 0) {
double pc = (double)pool_sum.stats.sum.num_objects_misplaced /
(double)pool_sum.stats.sum.num_object_copies * (double)100.0;
char b[20];
snprintf(b, sizeof(b), "%.3lf", pc);
if (f) {
f->dump_unsigned("misplaced_objects", pool_sum.stats.sum.num_objects_misplaced);
f->dump_unsigned("misplaced_total", pool_sum.stats.sum.num_object_copies);
f->dump_float("misplaced_ratio", pc / 100.0);
} else {
ostringstream ss;
ss << pool_sum.stats.sum.num_objects_misplaced
<< "/" << pool_sum.stats.sum.num_object_copies << " objects misplaced (" << b << "%)";
psl->push_back(ss.str());
}
}
if (pool_sum.stats.sum.num_objects_unfound && pool_sum.stats.sum.num_objects) {
double pc = (double)pool_sum.stats.sum.num_objects_unfound /
(double)pool_sum.stats.sum.num_objects * (double)100.0;
char b[20];
snprintf(b, sizeof(b), "%.3lf", pc);
if (f) {
f->dump_unsigned("unfound_objects", pool_sum.stats.sum.num_objects_unfound);
f->dump_unsigned("unfound_total", pool_sum.stats.sum.num_objects);
f->dump_float("unfound_ratio", pc / 100.0);
} else {
ostringstream ss;
ss << pool_sum.stats.sum.num_objects_unfound
<< "/" << pool_sum.stats.sum.num_objects << " objects unfound (" << b << "%)";
psl->push_back(ss.str());
}
}
}
void PGMapDigest::recovery_rate_summary(ceph::Formatter *f, ostream *out,
const pool_stat_t& delta_sum,
utime_t delta_stamp) const
{
// make non-negative; we can get negative values if osds send
// uncommitted stats and then "go backward" or if they are just
// buggy/wrong.
pool_stat_t pos_delta = delta_sum;
pos_delta.floor(0);
if (pos_delta.stats.sum.num_objects_recovered ||
pos_delta.stats.sum.num_bytes_recovered ||
pos_delta.stats.sum.num_keys_recovered) {
int64_t objps = pos_delta.stats.sum.num_objects_recovered / (double)delta_stamp;
int64_t bps = pos_delta.stats.sum.num_bytes_recovered / (double)delta_stamp;
int64_t kps = pos_delta.stats.sum.num_keys_recovered / (double)delta_stamp;
if (f) {
f->dump_int("recovering_objects_per_sec", objps);
f->dump_int("recovering_bytes_per_sec", bps);
f->dump_int("recovering_keys_per_sec", kps);
f->dump_int("num_objects_recovered", pos_delta.stats.sum.num_objects_recovered);
f->dump_int("num_bytes_recovered", pos_delta.stats.sum.num_bytes_recovered);
f->dump_int("num_keys_recovered", pos_delta.stats.sum.num_keys_recovered);
} else {
*out << byte_u_t(bps) << "/s";
if (pos_delta.stats.sum.num_keys_recovered)
*out << ", " << si_u_t(kps) << " keys/s";
*out << ", " << si_u_t(objps) << " objects/s";
}
}
}
void PGMapDigest::overall_recovery_rate_summary(ceph::Formatter *f, ostream *out) const
{
recovery_rate_summary(f, out, pg_sum_delta, stamp_delta);
}
void PGMapDigest::overall_recovery_summary(ceph::Formatter *f, list<string> *psl) const
{
recovery_summary(f, psl, pg_sum);
}
void PGMapDigest::pool_recovery_rate_summary(ceph::Formatter *f, ostream *out,
uint64_t poolid) const
{
auto p = per_pool_sum_delta.find(poolid);
if (p == per_pool_sum_delta.end())
return;
auto ts = per_pool_sum_deltas_stamps.find(p->first);
ceph_assert(ts != per_pool_sum_deltas_stamps.end());
recovery_rate_summary(f, out, p->second.first, ts->second);
}
void PGMapDigest::pool_recovery_summary(ceph::Formatter *f, list<string> *psl,
uint64_t poolid) const
{
auto p = pg_pool_sum.find(poolid);
if (p == pg_pool_sum.end())
return;
recovery_summary(f, psl, p->second);
}
void PGMapDigest::client_io_rate_summary(ceph::Formatter *f, ostream *out,
const pool_stat_t& delta_sum,
utime_t delta_stamp) const
{
pool_stat_t pos_delta = delta_sum;
pos_delta.floor(0);
if (pos_delta.stats.sum.num_rd ||
pos_delta.stats.sum.num_wr) {
if (pos_delta.stats.sum.num_rd) {
int64_t rd = (pos_delta.stats.sum.num_rd_kb << 10) / (double)delta_stamp;
if (f) {
f->dump_int("read_bytes_sec", rd);
} else {
*out << byte_u_t(rd) << "/s rd, ";
}
}
if (pos_delta.stats.sum.num_wr) {
int64_t wr = (pos_delta.stats.sum.num_wr_kb << 10) / (double)delta_stamp;
if (f) {
f->dump_int("write_bytes_sec", wr);
} else {
*out << byte_u_t(wr) << "/s wr, ";
}
}
int64_t iops_rd = pos_delta.stats.sum.num_rd / (double)delta_stamp;
int64_t iops_wr = pos_delta.stats.sum.num_wr / (double)delta_stamp;
if (f) {
f->dump_int("read_op_per_sec", iops_rd);
f->dump_int("write_op_per_sec", iops_wr);
} else {
*out << si_u_t(iops_rd) << " op/s rd, " << si_u_t(iops_wr) << " op/s wr";
}
}
}
void PGMapDigest::overall_client_io_rate_summary(ceph::Formatter *f, ostream *out) const
{
client_io_rate_summary(f, out, pg_sum_delta, stamp_delta);
}
void PGMapDigest::pool_client_io_rate_summary(ceph::Formatter *f, ostream *out,
uint64_t poolid) const
{
auto p = per_pool_sum_delta.find(poolid);
if (p == per_pool_sum_delta.end())
return;
auto ts = per_pool_sum_deltas_stamps.find(p->first);
ceph_assert(ts != per_pool_sum_deltas_stamps.end());
client_io_rate_summary(f, out, p->second.first, ts->second);
}
void PGMapDigest::cache_io_rate_summary(ceph::Formatter *f, ostream *out,
const pool_stat_t& delta_sum,
utime_t delta_stamp) const
{
pool_stat_t pos_delta = delta_sum;
pos_delta.floor(0);
bool have_output = false;
if (pos_delta.stats.sum.num_flush) {
int64_t flush = (pos_delta.stats.sum.num_flush_kb << 10) / (double)delta_stamp;
if (f) {
f->dump_int("flush_bytes_sec", flush);
} else {
*out << byte_u_t(flush) << "/s flush";
have_output = true;
}
}
if (pos_delta.stats.sum.num_evict) {
int64_t evict = (pos_delta.stats.sum.num_evict_kb << 10) / (double)delta_stamp;
if (f) {
f->dump_int("evict_bytes_sec", evict);
} else {
if (have_output)
*out << ", ";
*out << byte_u_t(evict) << "/s evict";
have_output = true;
}
}
if (pos_delta.stats.sum.num_promote) {
int64_t promote = pos_delta.stats.sum.num_promote / (double)delta_stamp;
if (f) {
f->dump_int("promote_op_per_sec", promote);
} else {
if (have_output)
*out << ", ";
*out << si_u_t(promote) << " op/s promote";
have_output = true;
}
}
if (pos_delta.stats.sum.num_flush_mode_low) {
if (f) {
f->dump_int("num_flush_mode_low", pos_delta.stats.sum.num_flush_mode_low);
} else {
if (have_output)
*out << ", ";
*out << si_u_t(pos_delta.stats.sum.num_flush_mode_low) << " PGs flushing";
have_output = true;
}
}
if (pos_delta.stats.sum.num_flush_mode_high) {
if (f) {
f->dump_int("num_flush_mode_high", pos_delta.stats.sum.num_flush_mode_high);
} else {
if (have_output)
*out << ", ";
*out << si_u_t(pos_delta.stats.sum.num_flush_mode_high) << " PGs flushing (high)";
have_output = true;
}
}
if (pos_delta.stats.sum.num_evict_mode_some) {
if (f) {
f->dump_int("num_evict_mode_some", pos_delta.stats.sum.num_evict_mode_some);
} else {
if (have_output)
*out << ", ";
*out << si_u_t(pos_delta.stats.sum.num_evict_mode_some) << " PGs evicting";
have_output = true;
}
}
if (pos_delta.stats.sum.num_evict_mode_full) {
if (f) {
f->dump_int("num_evict_mode_full", pos_delta.stats.sum.num_evict_mode_full);
} else {
if (have_output)
*out << ", ";
*out << si_u_t(pos_delta.stats.sum.num_evict_mode_full) << " PGs evicting (full)";
}
}
}
void PGMapDigest::overall_cache_io_rate_summary(ceph::Formatter *f, ostream *out) const
{
cache_io_rate_summary(f, out, pg_sum_delta, stamp_delta);
}
void PGMapDigest::pool_cache_io_rate_summary(ceph::Formatter *f, ostream *out,
uint64_t poolid) const
{
auto p = per_pool_sum_delta.find(poolid);
if (p == per_pool_sum_delta.end())
return;
auto ts = per_pool_sum_deltas_stamps.find(p->first);
ceph_assert(ts != per_pool_sum_deltas_stamps.end());
cache_io_rate_summary(f, out, p->second.first, ts->second);
}
ceph_statfs PGMapDigest::get_statfs(OSDMap &osdmap,
boost::optional<int64_t> data_pool) const
{
ceph_statfs statfs;
bool filter = false;
object_stat_sum_t sum;
if (data_pool) {
auto i = pg_pool_sum.find(*data_pool);
if (i != pg_pool_sum.end()) {
sum = i->second.stats.sum;
filter = true;
}
}
if (filter) {
statfs.kb_used = (sum.num_bytes >> 10);
statfs.kb_avail = get_pool_free_space(osdmap, *data_pool) >> 10;
statfs.num_objects = sum.num_objects;
statfs.kb = statfs.kb_used + statfs.kb_avail;
} else {
// these are in KB.
statfs.kb = osd_sum.statfs.kb();
statfs.kb_used = osd_sum.statfs.kb_used_raw();
statfs.kb_avail = osd_sum.statfs.kb_avail();
statfs.num_objects = pg_sum.stats.sum.num_objects;
}
return statfs;
}
void PGMapDigest::dump_pool_stats_full(
const OSDMap &osd_map,
stringstream *ss,
ceph::Formatter *f,
bool verbose) const
{
TextTable tbl;
if (f) {
f->open_array_section("pools");
} else {
tbl.define_column("POOL", TextTable::LEFT, TextTable::LEFT);
tbl.define_column("ID", TextTable::LEFT, TextTable::RIGHT);
tbl.define_column("PGS", TextTable::LEFT, TextTable::RIGHT);
tbl.define_column("STORED", TextTable::LEFT, TextTable::RIGHT);
if (verbose) {
tbl.define_column("(DATA)", TextTable::LEFT, TextTable::RIGHT);
tbl.define_column("(OMAP)", TextTable::LEFT, TextTable::RIGHT);
}
tbl.define_column("OBJECTS", TextTable::LEFT, TextTable::RIGHT);
tbl.define_column("USED", TextTable::LEFT, TextTable::RIGHT);
if (verbose) {
tbl.define_column("(DATA)", TextTable::LEFT, TextTable::RIGHT);
tbl.define_column("(OMAP)", TextTable::LEFT, TextTable::RIGHT);
}
tbl.define_column("%USED", TextTable::LEFT, TextTable::RIGHT);
tbl.define_column("MAX AVAIL", TextTable::LEFT, TextTable::RIGHT);
if (verbose) {
tbl.define_column("QUOTA OBJECTS", TextTable::LEFT, TextTable::LEFT);
tbl.define_column("QUOTA BYTES", TextTable::LEFT, TextTable::LEFT);
tbl.define_column("DIRTY", TextTable::LEFT, TextTable::RIGHT);
tbl.define_column("USED COMPR", TextTable::LEFT, TextTable::RIGHT);
tbl.define_column("UNDER COMPR", TextTable::LEFT, TextTable::RIGHT);
}
}
map<int,uint64_t> avail_by_rule;
for (auto p = osd_map.get_pools().begin();
p != osd_map.get_pools().end(); ++p) {
int64_t pool_id = p->first;
if ((pool_id < 0) || (pg_pool_sum.count(pool_id) == 0))
continue;
const string& pool_name = osd_map.get_pool_name(pool_id);
auto pool_pg_num = osd_map.get_pg_num(pool_id);
const pool_stat_t &stat = pg_pool_sum.at(pool_id);
const pg_pool_t *pool = osd_map.get_pg_pool(pool_id);
int ruleno = osd_map.crush->find_rule(pool->get_crush_rule(),
pool->get_type(),
pool->get_size());
int64_t avail;
if (avail_by_rule.count(ruleno) == 0) {
// FIXME: we don't guarantee avail_space_by_rule is up-to-date before this function is invoked
avail = get_rule_avail(ruleno);
if (avail < 0)
avail = 0;
avail_by_rule[ruleno] = avail;
} else {
avail = avail_by_rule[ruleno];
}
if (f) {
f->open_object_section("pool");
f->dump_string("name", pool_name);
f->dump_int("id", pool_id);
f->open_object_section("stats");
} else {
tbl << pool_name
<< pool_id
<< pool_pg_num;
}
float raw_used_rate = osd_map.pool_raw_used_rate(pool_id);
bool per_pool = use_per_pool_stats();
bool per_pool_omap = use_per_pool_omap_stats();
dump_object_stat_sum(tbl, f, stat, avail, raw_used_rate, verbose, per_pool,
per_pool_omap, pool);
if (f) {
f->close_section(); // stats
f->close_section(); // pool
} else {
tbl << TextTable::endrow;
}
}
if (f)
f->close_section();
else {
ceph_assert(ss != nullptr);
*ss << "--- POOLS ---\n";
*ss << tbl;
}
}
void PGMapDigest::dump_cluster_stats(stringstream *ss,
ceph::Formatter *f,
bool verbose) const
{
if (f) {
f->open_object_section("stats");
f->dump_int("total_bytes", osd_sum.statfs.total);
f->dump_int("total_avail_bytes", osd_sum.statfs.available);
f->dump_int("total_used_bytes", osd_sum.statfs.get_used());
f->dump_int("total_used_raw_bytes", osd_sum.statfs.get_used_raw());
f->dump_float("total_used_raw_ratio", osd_sum.statfs.get_used_raw_ratio());
f->dump_unsigned("num_osds", osd_sum.num_osds);
f->dump_unsigned("num_per_pool_osds", osd_sum.num_per_pool_osds);
f->dump_unsigned("num_per_pool_omap_osds", osd_sum.num_per_pool_omap_osds);
f->close_section();
f->open_object_section("stats_by_class");
for (auto& i : osd_sum_by_class) {
f->open_object_section(i.first.c_str());
f->dump_int("total_bytes", i.second.statfs.total);
f->dump_int("total_avail_bytes", i.second.statfs.available);
f->dump_int("total_used_bytes", i.second.statfs.get_used());
f->dump_int("total_used_raw_bytes", i.second.statfs.get_used_raw());
f->dump_float("total_used_raw_ratio",
i.second.statfs.get_used_raw_ratio());
f->close_section();
}
f->close_section();
} else {
ceph_assert(ss != nullptr);
TextTable tbl;
tbl.define_column("CLASS", TextTable::LEFT, TextTable::LEFT);
tbl.define_column("SIZE", TextTable::LEFT, TextTable::RIGHT);
tbl.define_column("AVAIL", TextTable::LEFT, TextTable::RIGHT);
tbl.define_column("USED", TextTable::LEFT, TextTable::RIGHT);
tbl.define_column("RAW USED", TextTable::LEFT, TextTable::RIGHT);
tbl.define_column("%RAW USED", TextTable::LEFT, TextTable::RIGHT);
for (auto& i : osd_sum_by_class) {
tbl << i.first;
tbl << stringify(byte_u_t(i.second.statfs.total))
<< stringify(byte_u_t(i.second.statfs.available))
<< stringify(byte_u_t(i.second.statfs.get_used()))
<< stringify(byte_u_t(i.second.statfs.get_used_raw()))
<< percentify(i.second.statfs.get_used_raw_ratio()*100.0)
<< TextTable::endrow;
}
tbl << "TOTAL";
tbl << stringify(byte_u_t(osd_sum.statfs.total))
<< stringify(byte_u_t(osd_sum.statfs.available))
<< stringify(byte_u_t(osd_sum.statfs.get_used()))
<< stringify(byte_u_t(osd_sum.statfs.get_used_raw()))
<< percentify(osd_sum.statfs.get_used_raw_ratio()*100.0)
<< TextTable::endrow;
*ss << "--- RAW STORAGE ---\n";
*ss << tbl;
}
}
void PGMapDigest::dump_object_stat_sum(
TextTable &tbl, ceph::Formatter *f,
const pool_stat_t &pool_stat, uint64_t avail,
float raw_used_rate, bool verbose, bool per_pool, bool per_pool_omap,
const pg_pool_t *pool)
{
const object_stat_sum_t &sum = pool_stat.stats.sum;
const store_statfs_t statfs = pool_stat.store_stats;
if (sum.num_object_copies > 0) {
raw_used_rate *= (float)(sum.num_object_copies - sum.num_objects_degraded) / sum.num_object_copies;
}
uint64_t used_data_bytes = pool_stat.get_allocated_data_bytes(per_pool);
uint64_t used_omap_bytes = pool_stat.get_allocated_omap_bytes(per_pool_omap);
uint64_t used_bytes = used_data_bytes + used_omap_bytes;
float used = 0.0;
// note avail passed in is raw_avail, calc raw_used here.
if (avail) {
used = used_bytes;
used /= used + avail;
} else if (used_bytes) {
used = 1.0;
}
auto avail_res = raw_used_rate ? avail / raw_used_rate : 0;
// an approximation for actually stored user data
auto stored_data_normalized = pool_stat.get_user_data_bytes(
raw_used_rate, per_pool);
auto stored_omap_normalized = pool_stat.get_user_omap_bytes(
raw_used_rate, per_pool_omap);
auto stored_normalized = stored_data_normalized + stored_omap_normalized;
// same, amplied by replication or EC
auto stored_raw = stored_normalized * raw_used_rate;
if (f) {
f->dump_int("stored", stored_normalized);
if (verbose) {
f->dump_int("stored_data", stored_data_normalized);
f->dump_int("stored_omap", stored_omap_normalized);
}
f->dump_int("objects", sum.num_objects);
f->dump_int("kb_used", shift_round_up(used_bytes, 10));
f->dump_int("bytes_used", used_bytes);
if (verbose) {
f->dump_int("data_bytes_used", used_data_bytes);
f->dump_int("omap_bytes_used", used_omap_bytes);
}
f->dump_float("percent_used", used);
f->dump_unsigned("max_avail", avail_res);
if (verbose) {
f->dump_int("quota_objects", pool->quota_max_objects);
f->dump_int("quota_bytes", pool->quota_max_bytes);
f->dump_int("dirty", sum.num_objects_dirty);
f->dump_int("rd", sum.num_rd);
f->dump_int("rd_bytes", sum.num_rd_kb * 1024ull);
f->dump_int("wr", sum.num_wr);
f->dump_int("wr_bytes", sum.num_wr_kb * 1024ull);
f->dump_int("compress_bytes_used", statfs.data_compressed_allocated);
f->dump_int("compress_under_bytes", statfs.data_compressed_original);
// Stored by user amplified by replication
f->dump_int("stored_raw", stored_raw);
f->dump_unsigned("avail_raw", avail);
}
} else {
tbl << stringify(byte_u_t(stored_normalized));
if (verbose) {
tbl << stringify(byte_u_t(stored_data_normalized));
tbl << stringify(byte_u_t(stored_omap_normalized));
}
tbl << stringify(si_u_t(sum.num_objects));
tbl << stringify(byte_u_t(used_bytes));
if (verbose) {
tbl << stringify(byte_u_t(used_data_bytes));
tbl << stringify(byte_u_t(used_omap_bytes));
}
tbl << percentify(used*100);
tbl << stringify(byte_u_t(avail_res));
if (verbose) {
if (pool->quota_max_objects == 0)
tbl << "N/A";
else
tbl << stringify(si_u_t(pool->quota_max_objects));
if (pool->quota_max_bytes == 0)
tbl << "N/A";
else
tbl << stringify(byte_u_t(pool->quota_max_bytes));
tbl << stringify(si_u_t(sum.num_objects_dirty))
<< stringify(byte_u_t(statfs.data_compressed_allocated))
<< stringify(byte_u_t(statfs.data_compressed_original))
;
}
}
}