ceph health --format json-pretty
ceph health detail --format xml-pretty
+ ceph node ls
+ for t in mon osd mds ; do
+ ceph node ls $t
+ done
+
ceph_watch_start
mymsg="this is a test log message $$.$(date)"
ceph log "$mymsg"
// distro info
lsb_release_parse(m, cct);
}
+
+void dump_services(Formatter* f, const map<string, list<int> >& services, const char* type)
+{
+ assert(f);
+
+ f->open_object_section(type);
+ for (map<string, list<int> >::const_iterator host = services.begin();
+ host != services.end(); ++host) {
+ f->open_array_section(host->first.c_str());
+ const list<int>& hosted = host->second;
+ for (list<int>::const_iterator s = hosted.begin();
+ s != hosted.end(); ++s) {
+ f->dump_int(type, *s);
+ }
+ f->close_section();
+ }
+ f->close_section();
+}
/// collect info from @p uname(2), @p /proc/meminfo and @p /proc/cpuinfo
void collect_sys_info(map<string, string> *m, CephContext *cct);
+/// dump service ids grouped by their host to the specified formatter
+/// @param f formatter for the output
+/// @param services a map from hostname to a list of service id hosted by this host
+/// @param type the service type of given @p services, for example @p osd or @p mon.
+void dump_services(Formatter* f, const map<string, list<int> >& services, const char* type);
+
#endif /* CEPH_UTIL_H */
return 0;
}
+int MDSMonitor::print_nodes(Formatter *f)
+{
+ assert(f);
+
+ map<mds_gid_t, Metadata> metadata;
+ if (int r = load_metadata(metadata)) {
+ return r;
+ }
+
+ map<string, list<int> > mdses; // hostname => rank
+ for (map<mds_gid_t, Metadata>::iterator it = metadata.begin();
+ it != metadata.end(); ++it) {
+ const Metadata& m = it->second;
+ Metadata::const_iterator hostname = m.find("hostname");
+ if (hostname == m.end()) {
+ // not likely though
+ continue;
+ }
+ const mds_gid_t gid = it->first;
+ assert(mdsmap.get_state_gid(gid) != MDSMap::STATE_NULL);
+ const MDSMap::mds_info_t& mds_info = mdsmap.get_info_gid(gid);
+ mdses[hostname->second].push_back(mds_info.rank);
+ }
+
+ dump_services(f, mdses, "mds");
+ return 0;
+}
+
void MDSMonitor::tick()
{
// make sure mds's are still alive
void dump_info(Formatter *f);
int dump_metadata(const string& who, Formatter *f, ostream& err);
+ int print_nodes(Formatter *f);
void check_subs();
void check_sub(Subscription *sub);
"send a command to a specific daemon", "mon", "rw", "cli,rest")
COMMAND_WITH_FLAG("version", "show mon daemon version", "mon", "r", "cli,rest",
NOFORWARD)
-
+COMMAND("node ls " \
+ "name=type,type=CephChoices,strings=all|osd|mon|mds,req=false",
+ "list all nodes in cluster [type]", "mon", "r", "cli,rest")
/*
* MDS commands (MDSMonitor.cc)
*/
ss2 << "report " << rdata.crc32c(6789);
rs = ss2.str();
r = 0;
+ } else if (prefix == "node ls") {
+ string node_type("all");
+ cmd_getval(g_ceph_context, cmdmap, "type", node_type);
+ if (!f)
+ f.reset(Formatter::create("json-pretty"));
+ if (node_type == "all") {
+ f->open_object_section("nodes");
+ print_nodes(f.get(), ds);
+ osdmon()->print_nodes(f.get());
+ mdsmon()->print_nodes(f.get());
+ f->close_section();
+ } else if (node_type == "mon") {
+ print_nodes(f.get(), ds);
+ } else if (node_type == "osd") {
+ osdmon()->print_nodes(f.get());
+ } else if (node_type == "mds") {
+ mdsmon()->print_nodes(f.get());
+ }
+ f->flush(ds);
+ rdata.append(ds);
+ rs = "";
+ r = 0;
} else if (prefix == "mon_metadata") {
string name;
cmd_getval(g_ceph_context, cmdmap, "id", name);
return 0;
}
+int Monitor::print_nodes(Formatter *f, ostream& err)
+{
+ map<int, Metadata> metadata;
+ if (int r = load_metadata(metadata)) {
+ err << "Unable to load metadata.\n";
+ return r;
+ }
+
+ map<string, list<int> > mons; // hostname => mon
+ for (map<int, Metadata>::iterator it = metadata.begin();
+ it != metadata.end(); ++it) {
+ const Metadata& m = it->second;
+ Metadata::const_iterator hostname = m.find("hostname");
+ if (hostname == m.end()) {
+ // not likely though
+ continue;
+ }
+ mons[hostname->second].push_back(it->first);
+ }
+
+ dump_services(f, mons, "mon");
+ return 0;
+}
+
// ----------------------------------------------
// scrub
void handle_mon_metadata(MMonMetadata *m);
int get_mon_metadata(int mon, Formatter *f, ostream& err);
+ int print_nodes(Formatter *f, ostream& err);
map<int, Metadata> metadata;
/**
pending_metadata_rm.clear();
}
-int OSDMonitor::dump_osd_metadata(int osd, Formatter *f, ostream *err)
+int OSDMonitor::load_metadata(int osd, map<string, string>& m, ostream *err)
{
bufferlist bl;
int r = mon->store->get(OSD_METADATA_PREFIX, stringify(osd), bl);
if (r < 0)
return r;
- map<string,string> m;
try {
bufferlist::iterator p = bl.begin();
::decode(m, p);
*err << "osd." << osd << " metadata is corrupt";
return -EIO;
}
+ return 0;
+}
+
+int OSDMonitor::dump_osd_metadata(int osd, Formatter *f, ostream *err)
+{
+ map<string,string> m;
+ if (int r = load_metadata(osd, m, err))
+ return r;
for (map<string,string>::iterator p = m.begin(); p != m.end(); ++p)
f->dump_string(p->first.c_str(), p->second);
return 0;
}
+void OSDMonitor::print_nodes(Formatter *f)
+{
+ // group OSDs by their hosts
+ map<string, list<int> > osds; // hostname => osd
+ for (int osd = 0; osd <= osdmap.get_max_osd(); osd++) {
+ map<string, string> m;
+ if (load_metadata(osd, m, NULL)) {
+ continue;
+ }
+ map<string, string>::iterator hostname = m.find("hostname");
+ if (hostname == m.end()) {
+ // not likely though
+ continue;
+ }
+ osds[hostname->second].push_back(osd);
+ }
+
+ dump_services(f, osds, "osd");
+}
+
void OSDMonitor::share_map_with_random_osd()
{
if (osdmap.get_num_up_osds() == 0) {
bool preprocess_remove_snaps(struct MRemoveSnaps *m);
bool prepare_remove_snaps(struct MRemoveSnaps *m);
+ int load_metadata(int osd, map<string, string>& m, ostream *err);
+
public:
OSDMonitor(Monitor *mn, Paxos *p, string service_name)
: PaxosService(mn, p, service_name),
void dump_info(Formatter *f);
int dump_osd_metadata(int osd, Formatter *f, ostream *err);
+ void print_nodes(Formatter *f);
void check_subs();
void check_sub(Subscription *sub);