From: Sage Weil Date: Sat, 9 Nov 2013 13:41:54 +0000 (-0800) Subject: osd: send host/kernel metadata to mon on boot X-Git-Tag: v0.74~37^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6d40e941aa8b37a48992d2b4bce700de98424b06;p=ceph.git osd: send host/kernel metadata to mon on boot Send a bunch of interesting information about the host we are running on to the monitor on startup. Signed-off-by: Sage Weil --- diff --git a/src/messages/MOSDBoot.h b/src/messages/MOSDBoot.h index d18d56c66f0e..bfe7775768f9 100644 --- a/src/messages/MOSDBoot.h +++ b/src/messages/MOSDBoot.h @@ -22,7 +22,7 @@ class MOSDBoot : public PaxosServiceMessage { - static const int HEAD_VERSION = 4; + static const int HEAD_VERSION = 5; static const int COMPAT_VERSION = 2; public: @@ -30,6 +30,7 @@ class MOSDBoot : public PaxosServiceMessage { entity_addr_t hb_back_addr, hb_front_addr; entity_addr_t cluster_addr; epoch_t boot_epoch; // last epoch this daemon was added to the map (if any) + map metadata; ///< misc metadata about this osd MOSDBoot() : PaxosServiceMessage(MSG_OSD_BOOT, 0, HEAD_VERSION, COMPAT_VERSION), @@ -63,6 +64,7 @@ public: ::encode(cluster_addr, payload); ::encode(boot_epoch, payload); ::encode(hb_front_addr, payload); + ::encode(metadata, payload); } void decode_payload() { bufferlist::iterator p = payload.begin(); @@ -75,6 +77,8 @@ public: ::decode(boot_epoch, p); if (header.version >= 4) ::decode(hb_front_addr, p); + if (header.version >= 5) + ::decode(metadata, p); } }; diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index d63a0a1c1157..bd79df6c5b4b 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -3567,9 +3568,79 @@ void OSD::_send_boot() << ", hb_back_addr " << hb_back_addr << ", hb_front_addr " << hb_front_addr << dendl; + _collect_metadata(&mboot->metadata); monc->send_mon_message(mboot); } +void OSD::_collect_metadata(map *pm) +{ + (*pm)["ceph_version"] = pretty_version_to_str(); + + // kernel info + struct utsname u; + int r = uname(&u); + if (r >= 0) { + (*pm)["os"] = u.sysname; + (*pm)["kernel_version"] = u.release; + (*pm)["kernel_description"] = u.version; + (*pm)["hostname"] = u.nodename; + (*pm)["arch"] = u.machine; + } + + // memory + FILE *f = fopen("/proc/meminfo", "r"); + if (f) { + char buf[100]; + while (!feof(f)) { + char *line = fgets(buf, sizeof(buf), f); + if (!line) + break; + char key[40]; + long long value; + int r = sscanf(line, "%s %lld", key, &value); + if (r == 2) { + if (strcmp(key, "MemTotal:") == 0) + (*pm)["mem_total_kb"] = stringify(value); + else if (strcmp(key, "SwapTotal:") == 0) + (*pm)["mem_swap_kb"] = stringify(value); + } + } + fclose(f); + } + + // distro info + f = fopen("/etc/lsb-release", "r"); + if (f) { + char buf[100]; + while (!feof(f)) { + char *line = fgets(buf, sizeof(buf), f); + if (!line) + break; + char *eq = strchr(buf, '='); + if (!eq) + break; + *eq = '\0'; + ++eq; + while (*eq == '\"') + ++eq; + while (*eq && (eq[strlen(eq)-1] == '\n' || + eq[strlen(eq)-1] == '\"')) + eq[strlen(eq)-1] = '\0'; + if (strcmp(buf, "DISTRIB_ID") == 0) + (*pm)["distro"] = eq; + else if (strcmp(buf, "DISTRIB_RELEASE") == 0) + (*pm)["distro_version"] = eq; + else if (strcmp(buf, "DISTRIB_CODENAME") == 0) + (*pm)["distro_codename"] = eq; + else if (strcmp(buf, "DISTRIB_DESCRIPTION") == 0) + (*pm)["distro_description"] = eq; + } + fclose(f); + } + + dout(10) << __func__ << " " << *pm << dendl; +} + void OSD::queue_want_up_thru(epoch_t want) { map_lock.get_read(); diff --git a/src/osd/OSD.h b/src/osd/OSD.h index 11ad2b89399b..80794d636b47 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -1254,6 +1254,7 @@ protected: void start_boot(); void _maybe_boot(epoch_t oldest, epoch_t newest); void _send_boot(); + void _collect_metadata(map *pmeta); void start_waiting_for_healthy(); bool _is_healthy();