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,
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)
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,
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