]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
client: add 'node.uptime' to the stats we collect
authorBrian Warner <warner@allmydata.com>
Thu, 17 Apr 2008 18:13:39 +0000 (11:13 -0700)
committerBrian Warner <warner@allmydata.com>
Thu, 17 Apr 2008 18:13:39 +0000 (11:13 -0700)
src/allmydata/client.py
src/allmydata/test/test_client.py

index 71fd6f620748bf9f98fbc44447ecb719c3bd32a6..c654f27f0f51c782990dea153c46b325727f22eb 100644 (file)
@@ -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)
index 1a263f93c4c06da607a92f587b205b3723de705d..6c6c77bd16a6bcd1dffc6c44938431be7a090633 100644 (file)
@@ -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()