From: Brian Warner Date: Thu, 27 Mar 2008 22:55:32 +0000 (-0700) Subject: helper: add stats for the gatherer, show some on the webish welcome page X-Git-Url: https://git.rkrishnan.org/vdrive/%22file:/frontends/htmlfontify-example.html?a=commitdiff_plain;h=36f5c025a6e94f14201f19e8df1c23368bc0899e;p=tahoe-lafs%2Ftahoe-lafs.git helper: add stats for the gatherer, show some on the webish welcome page --- diff --git a/src/allmydata/offloaded.py b/src/allmydata/offloaded.py index 5b624604..a7bde89e 100644 --- a/src/allmydata/offloaded.py +++ b/src/allmydata/offloaded.py @@ -456,7 +456,7 @@ class LocalCiphertextReader(AskUntilSuccessMixin): class Helper(Referenceable, service.MultiService): - implements(interfaces.RIHelper) + implements(interfaces.RIHelper, interfaces.IStatsProducer) # this is the non-distributed version. When we need to have multiple # helpers, this object will become the HelperCoordinator, and will query # the farm of Helpers to see if anyone has the storage_index of interest, @@ -473,14 +473,45 @@ class Helper(Referenceable, service.MultiService): fileutil.make_dirs(self._chk_incoming) fileutil.make_dirs(self._chk_encoding) self._active_uploads = {} + self._stats = {"CHK_upload_requests": 0, + "CHK_upload_already_present": 0, + "CHK_upload_need_upload": 0, + } service.MultiService.__init__(self) + def setServiceParent(self, parent): + service.MultiService.setServiceParent(self, parent) + stats = parent.stats_provider + if stats: + stats.register_producer(self) + + def get_stats(self): + chk_incoming_files, chk_incoming_size = 0,0 + chk_encoding_files, chk_encoding_size = 0,0 + for fn in os.listdir(self._chk_incoming): + size = os.stat(os.path.join(self._chk_incoming, fn))[stat.ST_SIZE] + chk_incoming_files += 1 + chk_incoming_size += 1 + for fn in os.listdir(self._chk_encoding): + size = os.stat(os.path.join(self._chk_encoding, fn))[stat.ST_SIZE] + chk_encoding_files += 1 + chk_encoding_size += 1 + stats = {"CHK_active_uploads": len(self._active_uploads), + "CHK_incoming_files": chk_incoming_files, + "CHK_incoming_size": chk_incoming_size, + "CHK_encoding_files": chk_encoding_files, + "CHK_encoding_size": chk_encoding_size, + } + stats.update(self._stats) + return {"helper": stats} + def log(self, *args, **kwargs): if 'facility' not in kwargs: kwargs['facility'] = "tahoe.helper" return self.parent.log(*args, **kwargs) def remote_upload_chk(self, storage_index): + self._stats["CHK_upload_requests"] += 1 r = upload.UploadResults() started = time.time() si_s = storage.si_b2a(storage_index) @@ -498,9 +529,11 @@ class Helper(Referenceable, service.MultiService): r.timings['existence_check'] = elapsed if already_present: # the necessary results are placed in the UploadResults + self._stats["CHK_upload_already_present"] += 1 self.log("file already found in grid", parent=lp) return (r, None) + self._stats["CHK_upload_need_upload"] += 1 # the file is not present in the grid, by which we mean there are # less than 'N' shares available. self.log("unable to find file in the grid", parent=lp, diff --git a/src/allmydata/test/test_helper.py b/src/allmydata/test/test_helper.py index 9470a0dc..d72b9514 100644 --- a/src/allmydata/test/test_helper.py +++ b/src/allmydata/test/test_helper.py @@ -58,6 +58,7 @@ class FakeClient(service.MultiService): "n": 100, "max_segment_size": 1*MiB, } + stats_provider = None def log(self, *args, **kwargs): return log.msg(*args, **kwargs) def get_encoding_parameters(self): diff --git a/src/allmydata/web/welcome.xhtml b/src/allmydata/web/welcome.xhtml index 9bb24580..be608bee 100644 --- a/src/allmydata/web/welcome.xhtml +++ b/src/allmydata/web/welcome.xhtml @@ -20,7 +20,7 @@ Downloads
My nodeid:
My versions:
Tahoe code imported from:
-
My Storage Server:
+
Services Running:

diff --git a/src/allmydata/webish.py b/src/allmydata/webish.py index 8bda3d49..7748a749 100644 --- a/src/allmydata/webish.py +++ b/src/allmydata/webish.py @@ -1452,17 +1452,30 @@ class Root(rend.Page): return str(allmydata) def data_my_nodeid(self, ctx, data): return idlib.nodeid_b2a(IClient(ctx).nodeid) - def data_storage(self, ctx, data): + + def render_services(self, ctx, data): + ul = T.ul() client = IClient(ctx) try: ss = client.getServiceNamed("storage") + allocated_s = abbreviate_size(ss.allocated_size()) + allocated = "about %s allocated" % allocated_s + sizelimit = "no size limit" + if ss.sizelimit is not None: + sizelimit = "size limit is %s" % abbreviate_size(ss.sizelimit) + ul[T.li["Storage Server: %s, %s" % (allocated, sizelimit)]] except KeyError: - return "Not running" - allocated = "about %s allocated" % abbreviate_size(ss.allocated_size()) - sizelimit = "no size limit" - if ss.sizelimit is not None: - sizelimit = "size limit is %s" % abbreviate_size(ss.sizelimit) - return "%s, %s" % (allocated, sizelimit) + ul[T.li["Not running storage server"]] + + try: + h = client.getServiceNamed("helper") + stats = h.get_stats() + active_uploads = stats["helper"]["CHK_active_uploads"] + ul[T.li["Helper: %d active uploads" % (active_uploads,)]] + except KeyError: + ul[T.li["Not running helper"]] + + return ctx.tag[ul] def data_introducer_furl(self, ctx, data): return IClient(ctx).introducer_furl