Skip to content

Commit

Permalink
mon: get the OSDMonitor's pg info dump functions away from using PGMap
Browse files Browse the repository at this point in the history
Signed-off-by: Greg Farnum <[email protected]>
  • Loading branch information
gregsfortytwo authored and liewegas committed Jun 2, 2017
1 parent 16c39e5 commit d8cd319
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
45 changes: 21 additions & 24 deletions src/mon/OSDMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,10 @@ class OSDUtilizationDumper : public CrushTreeDumper::Dumper<F> {
typedef CrushTreeDumper::Dumper<F> Parent;

OSDUtilizationDumper(const CrushWrapper *crush, const OSDMap *osdmap_,
const PGMap *pgm_, bool tree_) :
const PGStatService *pgs_, bool tree_) :
Parent(crush),
osdmap(osdmap_),
pgm(pgm_),
pgs(pgs_),
tree(tree_),
average_util(average_utilization()),
min_var(-1),
Expand Down Expand Up @@ -591,7 +591,7 @@ class OSDUtilizationDumper : public CrushTreeDumper::Dumper<F> {
if (average_util)
var = util / average_util;

size_t num_pgs = qi.is_bucket() ? 0 : pgm->get_num_pg_by_osd(qi.id);
size_t num_pgs = qi.is_bucket() ? 0 : pgs->get_num_pg_by_osd(qi.id);

dump_item(qi, reweight, kb, kb_used, kb_avail, util, var, num_pgs, f);

Expand Down Expand Up @@ -638,13 +638,11 @@ class OSDUtilizationDumper : public CrushTreeDumper::Dumper<F> {

bool get_osd_utilization(int id, int64_t* kb, int64_t* kb_used,
int64_t* kb_avail) const {
typedef ceph::unordered_map<int32_t,osd_stat_t> OsdStat;
OsdStat::const_iterator p = pgm->osd_stat.find(id);
if (p == pgm->osd_stat.end())
return false;
*kb = p->second.kb;
*kb_used = p->second.kb_used;
*kb_avail = p->second.kb_avail;
const osd_stat_t *p = pgs->get_osd_stat(id);
if (!p) return false;
*kb = p->kb;
*kb_used = p->kb_used;
*kb_avail = p->kb_avail;
return *kb > 0;
}

Expand Down Expand Up @@ -678,7 +676,7 @@ class OSDUtilizationDumper : public CrushTreeDumper::Dumper<F> {

protected:
const OSDMap *osdmap;
const PGMap *pgm;
const PGStatService *pgs;
bool tree;
double average_util;
double min_var;
Expand All @@ -692,8 +690,8 @@ class OSDUtilizationPlainDumper : public OSDUtilizationDumper<TextTable> {
typedef OSDUtilizationDumper<TextTable> Parent;

OSDUtilizationPlainDumper(const CrushWrapper *crush, const OSDMap *osdmap,
const PGMap *pgm, bool tree) :
Parent(crush, osdmap, pgm, tree) {}
const PGStatService *pgs, bool tree) :
Parent(crush, osdmap, pgs, tree) {}

void dump(TextTable *tbl) {
tbl->define_column("ID", TextTable::LEFT, TextTable::RIGHT);
Expand All @@ -713,9 +711,9 @@ class OSDUtilizationPlainDumper : public OSDUtilizationDumper<TextTable> {
dump_stray(tbl);

*tbl << "" << "" << "TOTAL"
<< si_t(pgm->osd_sum.kb << 10)
<< si_t(pgm->osd_sum.kb_used << 10)
<< si_t(pgm->osd_sum.kb_avail << 10)
<< si_t(pgs->get_osd_sum().kb << 10)
<< si_t(pgs->get_osd_sum().kb_used << 10)
<< si_t(pgs->get_osd_sum().kb_avail << 10)
<< lowprecision_t(average_util)
<< ""
<< TextTable::endrow;
Expand Down Expand Up @@ -798,8 +796,8 @@ class OSDUtilizationFormatDumper : public OSDUtilizationDumper<Formatter> {
typedef OSDUtilizationDumper<Formatter> Parent;

OSDUtilizationFormatDumper(const CrushWrapper *crush, const OSDMap *osdmap,
const PGMap *pgm, bool tree) :
Parent(crush, osdmap, pgm, tree) {}
const PGStatService *pgs, bool tree) :
Parent(crush, osdmap, pgs, tree) {}

void dump(Formatter *f) {
f->open_array_section("nodes");
Expand Down Expand Up @@ -838,9 +836,9 @@ class OSDUtilizationFormatDumper : public OSDUtilizationDumper<Formatter> {
public:
void summary(Formatter *f) {
f->open_object_section("summary");
f->dump_int("total_kb", pgm->osd_sum.kb);
f->dump_int("total_kb_used", pgm->osd_sum.kb_used);
f->dump_int("total_kb_avail", pgm->osd_sum.kb_avail);
f->dump_int("total_kb", pgs->get_osd_sum().kb);
f->dump_int("total_kb_used", pgs->get_osd_sum().kb_used);
f->dump_int("total_kb_avail", pgs->get_osd_sum().kb_avail);
f->dump_float("average_utilization", average_util);
f->dump_float("min_var", min_var);
f->dump_float("max_var", max_var);
Expand All @@ -851,18 +849,17 @@ class OSDUtilizationFormatDumper : public OSDUtilizationDumper<Formatter> {

void OSDMonitor::print_utilization(ostream &out, Formatter *f, bool tree) const
{
const PGMap *pgm = &mon->pgservice.get_pg_map();
const CrushWrapper *crush = osdmap.crush.get();

if (f) {
f->open_object_section("df");
OSDUtilizationFormatDumper d(crush, &osdmap, pgm, tree);
OSDUtilizationFormatDumper d(crush, &osdmap, &mon->pgservice, tree);
d.dump(f);
d.summary(f);
f->close_section();
f->flush(out);
} else {
OSDUtilizationPlainDumper d(crush, &osdmap, pgm, tree);
OSDUtilizationPlainDumper d(crush, &osdmap, &mon->pgservice, tree);
TextTable tbl;
d.dump(&tbl);
out << tbl
Expand Down
19 changes: 19 additions & 0 deletions src/mon/PGStatService.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ class PGStatService : public PGMap {

PGMap& get_pg_map() { return parent; }

const pool_stat_t& get_pg_sum() const { return parent.pg_sum; }
const osd_stat_t& get_osd_sum() const { return parent.osd_sum; }

typedef ceph::unordered_map<pg_t,pg_stat_t>::const_iterator PGStatIter;
typedef ceph::unordered_map<int32_t,osd_stat_t>::const_iterator OSDStatIter;
PGStatIter pg_stat_iter_begin() const { return parent.pg_stat.begin(); }
PGStatIter pg_stat_iter_end() const { return parent.pg_stat.end(); }
OSDStatIter osd_stat_iter_begin() const { return parent.osd_stat.begin(); }
OSDStatIter osd_stat_iter_end() const { return parent.osd_stat.end(); }
const osd_stat_t *get_osd_stat(int osd) const {
auto i = parent.osd_stat.find(osd);
if (i == parent.osd_stat.end()) {
return NULL;
}
return &i->second;
}

float get_full_ratio() const { return parent.full_ratio; }
float get_nearfull_ratio() const { return parent.nearfull_ratio; }

Expand All @@ -68,6 +85,8 @@ class PGStatService : public PGMap {
bool have_full_osds() const { return !parent.full_osds.empty(); }
bool have_nearfull_osds() const { return !parent.nearfull_osds.empty(); }

size_t get_num_pg_by_osd(int osd) const { return parent.get_num_pg_by_osd(osd); }

void print_summary(Formatter *f, ostream *out) const { parent.print_summary(f, out); }
void dump_fs_stats(stringstream *ss, Formatter *f, bool verbose) const {
parent.dump_fs_stats(ss, f, verbose);
Expand Down

0 comments on commit d8cd319

Please sign in to comment.