}
stringstream rs;
r = cluster_state.with_osdmap_and_pgmap([&](const OSDMap& osdmap, const PGMap& pgmap) {
- string class_name;
- string item_name;
// sanity check filter(s)
if (filter_by == "class") {
if (!osdmap.crush->class_exists(filter)) {
rs << "specified class '" << filter << "' does not exist";
return -EINVAL;
}
- class_name = filter;
}
if (filter_by == "name") {
if (!osdmap.crush->name_exists(filter)) {
rs << "specified name '" << filter << "' does not exist";
return -EINVAL;
}
- item_name = filter;
}
print_osd_utilization(osdmap, pgmap, ss,
- f.get(), method == "tree",
- class_name, item_name);
-
+ f.get(), method == "tree", filter);
cmdctx->odata.append(ss);
return 0;
});
OSDUtilizationDumper(const CrushWrapper *crush, const OSDMap *osdmap_,
const PGMap& pgmap_, bool tree_,
- const string& class_name_,
- const string& item_name_) :
+ const string& filter) :
Parent(crush, osdmap_->get_pool_names()),
osdmap(osdmap_),
pgmap(pgmap_),
tree(tree_),
- class_name(class_name_),
- item_name(item_name_),
min_var(-1),
max_var(-1),
stddev(0),
sum(0) {
- if (osdmap->crush->name_exists(item_name)) {
- // filter out items we are allowed to dump
- auto item_id = osdmap->crush->get_item_id(item_name);
+ if (osdmap->crush->name_exists(filter)) {
+ // filter by crush node
+ auto item_id = osdmap->crush->get_item_id(filter);
allowed.insert(item_id);
osdmap->crush->get_all_children(item_id, &allowed);
+ } else if (osdmap->crush->class_exists(filter)) {
+ // filter by device class
+ class_id = osdmap->crush->get_class_id(filter);
}
average_util = average_utilization();
}
bool should_dump(int id) const {
if (!allowed.empty() && !allowed.count(id)) // filter by name
return false;
- if (id >= 0 && !class_name.empty()) {
- const char* item_class_name = osdmap->crush->get_item_class(id);
- if (!item_class_name || // not bound to a class yet
- item_class_name != class_name) // or already bound to
- // a different class
+ if (id >= 0 && class_id >= 0) {
+ auto item_class_id = osdmap->crush->get_item_class_id(id);
+ if (item_class_id < 0 || // not bound to a class yet
+ item_class_id != class_id) // or already bound to a different class
return false;
}
return true;
}
set<int> get_dumped_osds() {
- if (class_name.empty() && item_name.empty()) {
+ if (allowed.empty() && class_id < 0) {
// old way, all
return {};
}
const OSDMap *osdmap;
const PGMap& pgmap;
bool tree;
- const string class_name;
- const string item_name;
double average_util;
double min_var;
double max_var;
double stddev;
double sum;
+ int class_id = -1;
set<int> allowed;
set<int> dumped_osds;
};
OSDUtilizationPlainDumper(const CrushWrapper *crush, const OSDMap *osdmap,
const PGMap& pgmap, bool tree,
- const string& class_name,
- const string& item_name) :
- Parent(crush, osdmap, pgmap, tree, class_name, item_name) {}
+ const string& filter) :
+ Parent(crush, osdmap, pgmap, tree, filter) {}
void dump(TextTable *tbl) {
tbl->define_column("ID", TextTable::LEFT, TextTable::RIGHT);
OSDUtilizationFormatDumper(const CrushWrapper *crush, const OSDMap *osdmap,
const PGMap& pgmap, bool tree,
- const string& class_name,
- const string& item_name) :
- Parent(crush, osdmap, pgmap, tree, class_name, item_name) {}
+ const string& filter) :
+ Parent(crush, osdmap, pgmap, tree, filter) {}
void dump(Formatter *f) {
f->open_array_section("nodes");
ostream& out,
Formatter *f,
bool tree,
- const string& class_name,
- const string& item_name)
+ const string& filter)
{
const CrushWrapper *crush = osdmap.crush.get();
if (f) {
f->open_object_section("df");
- OSDUtilizationFormatDumper d(crush, &osdmap, pgmap, tree,
- class_name, item_name);
+ OSDUtilizationFormatDumper d(crush, &osdmap, pgmap, tree, filter);
d.dump(f);
d.summary(f);
f->close_section();
f->flush(out);
} else {
- OSDUtilizationPlainDumper d(crush, &osdmap, pgmap, tree,
- class_name, item_name);
+ OSDUtilizationPlainDumper d(crush, &osdmap, pgmap, tree, filter);
TextTable tbl;
d.dump(&tbl);
out << tbl << d.summary() << "\n";