]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: send host/kernel metadata to mon on boot
authorSage Weil <sage@inktank.com>
Sat, 9 Nov 2013 13:41:54 +0000 (05:41 -0800)
committerSage Weil <sage@inktank.com>
Sat, 9 Nov 2013 14:10:14 +0000 (06:10 -0800)
Send a bunch of interesting information about the host we are running on
to the monitor on startup.

Signed-off-by: Sage Weil <sage@inktank.com>
src/messages/MOSDBoot.h
src/osd/OSD.cc
src/osd/OSD.h

index d18d56c66f0e034133c54a5d2654bc4133b644f1..bfe7775768f96e92b3b61725d9a872823a99fb28 100644 (file)
@@ -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<string,string> 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);
   }
 };
 
index d63a0a1c11578abf782886bd6926a468f1a51a72..bd79df6c5b4b970ad2978c88c2999275f79371de 100644 (file)
@@ -16,6 +16,7 @@
 #include <iostream>
 #include <errno.h>
 #include <sys/stat.h>
+#include <sys/utsname.h>
 #include <signal.h>
 #include <ctype.h>
 #include <boost/scoped_ptr.hpp>
@@ -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<string,string> *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();
index 11ad2b89399be1c7b5be2e060e24e6b0440b67b2..80794d636b47ec7a8ec2c06bdaaee908f0541a2f 100644 (file)
@@ -1254,6 +1254,7 @@ protected:
   void start_boot();
   void _maybe_boot(epoch_t oldest, epoch_t newest);
   void _send_boot();
+  void _collect_metadata(map<string,string> *pmeta);
 
   void start_waiting_for_healthy();
   bool _is_healthy();