From: Brian Warner <warner@allmydata.com> Date: Thu, 17 Apr 2008 18:13:39 +0000 (-0700) Subject: client: add 'node.uptime' to the stats we collect X-Git-Url: https://git.rkrishnan.org/pf/content/en/service/FOOURL?a=commitdiff_plain;h=68527b25fc2d6f2a73f508804c6be71761810a22;p=tahoe-lafs%2Ftahoe-lafs.git client: add 'node.uptime' to the stats we collect --- diff --git a/src/allmydata/client.py b/src/allmydata/client.py index 71fd6f62..c654f27f 100644 --- a/src/allmydata/client.py +++ b/src/allmydata/client.py @@ -23,7 +23,7 @@ from allmydata.filenode import FileNode from allmydata.dirnode import NewDirectoryNode from allmydata.mutable import MutableFileNode, MutableWatcher from allmydata.stats import StatsProvider -from allmydata.interfaces import IURI, INewDirectoryURI, \ +from allmydata.interfaces import IURI, INewDirectoryURI, IStatsProducer, \ IReadonlyNewDirectoryURI, IFileURI, IMutableFileURI, RIStubClient KiB=1024 @@ -39,6 +39,8 @@ def _make_secret(): return base32.b2a(os.urandom(hashutil.CRYPTO_VAL_SIZE)) + "\n" class Client(node.Node, testutil.PollMixin): + implements(IStatsProducer) + PORTNUMFILE = "client.port" STOREDIR = 'storage' NODETYPE = "client" @@ -60,6 +62,7 @@ class Client(node.Node, testutil.PollMixin): def __init__(self, basedir="."): node.Node.__init__(self, basedir) + self.started_timestamp = time.time() self.logSource="Client" self.nickname = self.get_config("nickname") if self.nickname is None: @@ -107,9 +110,13 @@ class Client(node.Node, testutil.PollMixin): if gatherer_furl: self.stats_provider = StatsProvider(self, gatherer_furl) self.add_service(self.stats_provider) + self.stats_provider.register_producer(self) else: self.stats_provider = None + def get_stats(self): + return { 'node.uptime': time.time() - self.started_timestamp } + def init_lease_secret(self): secret_s = self.get_or_create_private_config("secret", _make_secret) self._lease_secret = base32.a2b(secret_s) diff --git a/src/allmydata/test/test_client.py b/src/allmydata/test/test_client.py index 1a263f93..6c6c77bd 100644 --- a/src/allmydata/test/test_client.py +++ b/src/allmydata/test/test_client.py @@ -133,6 +133,10 @@ class Basic(unittest.TestCase): all_versions = allmydata.get_package_versions_string() self.failUnless("allmydata" in all_versions) log.msg("tahoe versions: %s" % all_versions) + # also test stats + stats = c.get_stats() + self.failUnless("node.uptime" in stats) + self.failUnless(isinstance(stats["node.uptime"], float)) def flush_but_dont_ignore(res): d = flushEventualQueue()