From 5f95ec4457059889bc4dbc2ad25cdc0537255f69 Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Fri, 27 Sep 2019 16:04:05 +0800 Subject: [PATCH] mgr/progress: estimated remaining time for events Fixes: https://tracker.ceph.com/issues/40419 Signed-off-by: xie xingguo --- src/mon/Monitor.cc | 9 -------- src/pybind/mgr/mgr_module.py | 6 +++-- src/pybind/mgr/progress/module.py | 37 +++++++++++++++++++++++++------ 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 1ed7d3f6f423a..f0754fa8d293f 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -3000,15 +3000,6 @@ void Monitor::get_cluster_status(stringstream &ss, Formatter *f) ss << "\n \n progress:\n"; for (auto& i : pem) { ss << " " << i.second.message << "\n"; - ss << " ["; - unsigned j; - for (j = 0; j < (unsigned)(i.second.progress * 30.0); ++j) { - ss << '='; - } - for (; j < 30; ++j) { - ss << '.'; - } - ss << "]\n"; } } ss << "\n "; diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index e6b74ef72f733..86db33703e571 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -1218,8 +1218,10 @@ class MgrModule(ceph_module.BaseMgrModule): return self._ceph_have_mon_connection() - def update_progress_event(self, evid, desc, progress, duration): - return self._ceph_update_progress_event(str(evid), str(desc+" "+duration), float(progress)) + def update_progress_event(self, evid, desc, progress): + return self._ceph_update_progress_event(str(evid), + str(desc), + float(progress)) def complete_progress_event(self, evid): return self._ceph_complete_progress_event(str(evid)) diff --git a/src/pybind/mgr/progress/module.py b/src/pybind/mgr/progress/module.py index 5b67b79ee3baa..a2c0b1dbdc8d0 100644 --- a/src/pybind/mgr/progress/module.py +++ b/src/pybind/mgr/progress/module.py @@ -30,13 +30,16 @@ class Event(object): self.started_at = started_at if started_at else time.time() self.id = None self.update_duration_event() + self._time_remaining_str = "(time remaining: N/A)" def _refresh(self): global _module _module.log.debug('refreshing mgr for %s (%s) at %f' % (self.id, self._message, self.progress)) self.update_duration_event() - _module.update_progress_event(self.id, self._message, self.progress, self._duration_str) + self.update_time_remaining() + _module.update_progress_event( + self.id, self.twoline_progress(6), self.progress) @property def message(self): @@ -75,16 +78,19 @@ class Event(object): return out - def twoline_progress(self): + def twoline_progress(self, indent=4): """ e.g. - - Eating my delicious strudel - [===============..............] + - Eating my delicious strudel (since: 00h 00m 30s) + [===============..............] (time remaining: 00h 03m 57s) """ - return "{0} {1}\n {2}".format( - self._message, self._duration_str, self._progress_str(30)) + return "{0} {1}\n{2}{3} {4}".format(self._message, + self._duration_str, + " " * indent, + self._progress_str(30), + self._time_remaining_str) def to_json(self): return { @@ -93,7 +99,8 @@ class Event(object): "duration": self.duration_str, "refs": self._refs, "progress": self.progress, - "started_at": self.started_at + "started_at": self.started_at, + "time_remaining": self.estimated_time_remaining() } def update_duration_event(self): @@ -102,6 +109,22 @@ class Event(object): duration = time.time() - self.started_at self._duration_str = time.strftime("(since %Hh %Mm %Ss)", time.gmtime(duration)) + + def estimated_time_remaining(self): + elapsed = time.time() - self.started_at + progress = self.progress + if progress == 0.0: + return None + return int(elapsed * (1 - progress) / progress) + + def update_time_remaining(self): + time_remaining = self.estimated_time_remaining() + if time_remaining: + self._time_remaining_str = time.strftime( + "(time remaining: %Hh %Mm %Ss)", time.gmtime(time_remaining)) + else: + self._time_remaining_str = "(time remaining: N/A)" + class GhostEvent(Event): """ The ghost of a completed event: these are the fields that we persist -- 2.39.5