]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: use prettified durations for life expectancy
authorSage Weil <sage@redhat.com>
Fri, 8 Jun 2018 02:48:19 +0000 (21:48 -0500)
committerSage Weil <sage@redhat.com>
Mon, 11 Jun 2018 12:29:04 +0000 (07:29 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/mgr/DaemonServer.cc
src/mgr/DaemonState.cc
src/mgr/DaemonState.h

index 777c84db845c9743d975b40e4ee7f9a08e622a46..7f1e1cfb9513781520621a72d657c02edd662d5d 100644 (file)
@@ -1671,7 +1671,8 @@ bool DaemonServer::handle_command(MCommand *m)
       tbl.define_column("HOST:DEV", TextTable::LEFT, TextTable::LEFT);
       tbl.define_column("DAEMONS", TextTable::LEFT, TextTable::LEFT);
       tbl.define_column("LIFE EXPECTANCY", TextTable::LEFT, TextTable::LEFT);
-      daemon_state.with_devices([&tbl](const DeviceState& dev) {
+      auto now = ceph_clock_now();
+      daemon_state.with_devices([&tbl, now](const DeviceState& dev) {
          string h;
          for (auto& i : dev.devnames) {
            if (h.size()) {
@@ -1689,7 +1690,7 @@ bool DaemonServer::handle_command(MCommand *m)
          tbl << dev.devid
              << h
              << d
-             << dev.get_life_expectancy_str()
+             << dev.get_life_expectancy_str(now)
              << TextTable::endrow;
        });
       cmdctx->odata.append(stringify(tbl));
@@ -1721,8 +1722,10 @@ bool DaemonServer::handle_command(MCommand *m)
          tbl.define_column("HOST:DEV", TextTable::LEFT, TextTable::LEFT);
          tbl.define_column("EXPECTED FAILURE", TextTable::LEFT,
                            TextTable::LEFT);
+         auto now = ceph_clock_now();
          for (auto& i : dm->devices) {
-           daemon_state.with_device(i.first, [&tbl] (const DeviceState& dev) {
+           daemon_state.with_device(
+             i.first, [&tbl, now] (const DeviceState& dev) {
                string h;
                for (auto& i : dev.devnames) {
                  if (h.size()) {
@@ -1732,7 +1735,7 @@ bool DaemonServer::handle_command(MCommand *m)
                }
                tbl << dev.devid
                    << h
-                   << dev.get_life_expectancy_str()
+                   << dev.get_life_expectancy_str(now)
                    << TextTable::endrow;
              });
          }
@@ -1765,9 +1768,10 @@ bool DaemonServer::handle_command(MCommand *m)
       tbl.define_column("DEV", TextTable::LEFT, TextTable::LEFT);
       tbl.define_column("DAEMONS", TextTable::LEFT, TextTable::LEFT);
       tbl.define_column("EXPECTED FAILURE", TextTable::LEFT, TextTable::LEFT);
+      auto now = ceph_clock_now();
       for (auto& devid : devids) {
        daemon_state.with_device(
-         devid, [&tbl, &host] (const DeviceState& dev) {
+         devid, [&tbl, &host, now] (const DeviceState& dev) {
            string n;
            for (auto& j : dev.devnames) {
              if (j.first == host) {
@@ -1787,7 +1791,7 @@ bool DaemonServer::handle_command(MCommand *m)
            tbl << dev.devid
                << n
                << d
-               << dev.get_life_expectancy_str()
+               << dev.get_life_expectancy_str(now)
                << TextTable::endrow;
          });
       }
index 1e1ebdb67ccfe2d441dee9cb96d0e76e0eebbc0b..d8f36d0be018052f9ce96f015542518e6027e663 100644 (file)
@@ -57,13 +57,25 @@ void DeviceState::rm_life_expectancy()
   metadata.erase("life_expectancy_stamp");
 }
 
-string DeviceState::get_life_expectancy_str() const
+string DeviceState::get_life_expectancy_str(utime_t now) const
 {
   if (life_expectancy.first == utime_t()) {
     return string();
   }
-  return stringify(life_expectancy.first) + " to " +
-    stringify(life_expectancy.second);
+  if (now >= life_expectancy.first) {
+    return "now";
+  }
+  utime_t min = life_expectancy.first - now;
+  utime_t max = life_expectancy.second - now;
+  if (life_expectancy.second == utime_t()) {
+    return string(">") + timespan_str(make_timespan(min));
+  }
+  string a = timespan_str(make_timespan(min));
+  string b = timespan_str(make_timespan(max));
+  if (a == b) {
+    return a;
+  }
+  return a + " to " + b;
 }
 
 void DeviceState::dump(Formatter *f) const
index 6f9f4f3d93d994706e42b9a87ea5b2c2bcef198a..0a083ac5617d35d52a9784ad77808f10511b0cf6 100644 (file)
@@ -208,7 +208,7 @@ struct DeviceState : public RefCountedObject
   void set_life_expectancy(utime_t from, utime_t to, utime_t now);
   void rm_life_expectancy();
 
-  string get_life_expectancy_str() const;
+  string get_life_expectancy_str(utime_t now) const;
 
   /// true of we can be safely forgotten/removed from memory
   bool empty() const {