#include "ConfigMonitor.h"
#include "HealthMonitor.h"
+#include "common/TextTable.h"
+#include "common/cmdparse.h"
+#include "include/stringify.h"
+
#include "MgrMonitor.h"
#define MGR_METADATA_PREFIX "mgr_metadata"
return true;
}
- string format;
- cmd_getval(cmdmap, "format", format);
- boost::scoped_ptr<Formatter> f(Formatter::create(format, "json-pretty",
- "json-pretty"));
+ string format = cmd_getval_or<string>(cmdmap, "format", "plain");
+ boost::scoped_ptr<Formatter> f(Formatter::create(format));
string prefix;
cmd_getval(cmdmap, "prefix", prefix);
int r = 0;
if (prefix == "mgr stat") {
+ if (!f) {
+ f.reset(Formatter::create(format, "json-pretty", "json-pretty"));
+ }
f->open_object_section("stat");
f->dump_unsigned("epoch", map.get_epoch());
f->dump_bool("available", map.get_available());
f->close_section();
f->flush(rdata);
} else if (prefix == "mgr dump") {
+ if (!f) {
+ f.reset(Formatter::create(format, "json-pretty", "json-pretty"));
+ }
int64_t epoch = cmd_getval_or<int64_t>(cmdmap, "epoch", map.get_epoch());
if (epoch == (int64_t)map.get_epoch()) {
f->dump_object("mgrmap", map);
} else if (prefix == "mgr module ls") {
string detail;
cmd_getval(cmdmap, "detail", detail);
+ if (f || (detail == "detail")) {
+ if (!f) {
+ f.reset(Formatter::create(format, "json-pretty", "json-pretty"));
+ }
+ f->open_object_section("modules");
+ {
+ f->open_array_section("always_on_modules");
+ for (auto& p : map.get_always_on_modules()) {
+ f->dump_string("module", p);
+ }
+ f->close_section();
+ f->open_array_section("enabled_modules");
+ for (auto& p : map.modules) {
+ if (map.get_always_on_modules().count(p) > 0)
+ continue;
+ // We only show the name for enabled modules. The any errors
+ // etc will show up as a health checks.
+ f->dump_string("module", p);
+ }
+ f->close_section();
+ f->open_array_section("disabled_modules");
+ for (auto& p : map.available_modules) {
+ if (map.modules.count(p.name) == 0 &&
+ map.get_always_on_modules().count(p.name) == 0) {
+ if (detail == "detail") {
+ // For disabled modules, we show the full info if the detail
+ // parameter is enabled, to give a hint about whether enabling it will work
+ p.dump(f.get());
+ } else {
+ // Otherwise, we give a shortened summary by default
+ f->dump_string("module", p.name);
+ }
+ }
+ }
+ f->close_section();
+ }
+ f->close_section();
+ f->flush(rdata);
+ } else {
+ TextTable tbl;
+ tbl.define_column("MODULE", TextTable::LEFT, TextTable::LEFT);
+ tbl.define_column(" ", TextTable::LEFT, TextTable::LEFT);
- f->open_object_section("modules");
- {
- f->open_array_section("always_on_modules");
for (auto& p : map.get_always_on_modules()) {
- f->dump_string("module", p);
+ tbl << p;
+ tbl << "on (always on)";
+ tbl << TextTable::endrow;
}
- f->close_section();
- f->open_array_section("enabled_modules");
for (auto& p : map.modules) {
if (map.get_always_on_modules().count(p) > 0)
continue;
- // We only show the name for enabled modules. The any errors
- // etc will show up as a health checks.
- f->dump_string("module", p);
+ tbl << p;
+ tbl << "on";
+ tbl << TextTable::endrow;
}
- f->close_section();
- f->open_array_section("disabled_modules");
for (auto& p : map.available_modules) {
if (map.modules.count(p.name) == 0 &&
map.get_always_on_modules().count(p.name) == 0) {
- if (detail == "detail") {
- // For disabled modules, we show the full info if the detail
- // parameter is enabled, to give a hint about whether enabling it will work
- p.dump(f.get());
- } else {
- // Otherwise, we give a shortened summary by default
- f->dump_string("module", p.name);
- }
+ tbl << p.name;
+ tbl << "-";
+ tbl << TextTable::endrow;
}
}
- f->close_section();
+ rdata.append(stringify(tbl));
}
- f->close_section();
- f->flush(rdata);
} else if (prefix == "mgr services") {
+ if (!f) {
+ f.reset(Formatter::create(format, "json-pretty", "json-pretty"));
+ }
f->open_object_section("services");
for (const auto &i : map.services) {
f->dump_string(i.first.c_str(), i.second);
f->close_section();
f->flush(rdata);
} else if (prefix == "mgr metadata") {
+ if (!f) {
+ f.reset(Formatter::create(format, "json-pretty", "json-pretty"));
+ }
string name;
cmd_getval(cmdmap, "who", name);
if (name.size() > 0 && !map.have_name(name)) {
r = -ENOENT;
goto reply;
}
- string format;
- cmd_getval(cmdmap, "format", format);
- boost::scoped_ptr<Formatter> f(Formatter::create(format, "json-pretty", "json-pretty"));
if (name.size()) {
f->open_object_section("mgr_metadata");
f->dump_string("name", name);
}
f->flush(rdata);
} else if (prefix == "mgr versions") {
+ if (!f) {
+ f.reset(Formatter::create(format, "json-pretty", "json-pretty"));
+ }
count_metadata("ceph_version", f.get());
f->flush(rdata);
r = 0;
} else if (prefix == "mgr count-metadata") {
+ if (!f) {
+ f.reset(Formatter::create(format, "json-pretty", "json-pretty"));
+ }
string field;
cmd_getval(cmdmap, "property", field);
count_metadata(field, f.get());