client: add 'node.uptime' to the stats we collect

This commit is contained in:
Brian Warner 2008-04-17 11:13:39 -07:00
parent 90970f9447
commit 68527b25fc
2 changed files with 12 additions and 1 deletions

View File

@ -23,7 +23,7 @@ from allmydata.filenode import FileNode
from allmydata.dirnode import NewDirectoryNode from allmydata.dirnode import NewDirectoryNode
from allmydata.mutable import MutableFileNode, MutableWatcher from allmydata.mutable import MutableFileNode, MutableWatcher
from allmydata.stats import StatsProvider from allmydata.stats import StatsProvider
from allmydata.interfaces import IURI, INewDirectoryURI, \ from allmydata.interfaces import IURI, INewDirectoryURI, IStatsProducer, \
IReadonlyNewDirectoryURI, IFileURI, IMutableFileURI, RIStubClient IReadonlyNewDirectoryURI, IFileURI, IMutableFileURI, RIStubClient
KiB=1024 KiB=1024
@ -39,6 +39,8 @@ def _make_secret():
return base32.b2a(os.urandom(hashutil.CRYPTO_VAL_SIZE)) + "\n" return base32.b2a(os.urandom(hashutil.CRYPTO_VAL_SIZE)) + "\n"
class Client(node.Node, testutil.PollMixin): class Client(node.Node, testutil.PollMixin):
implements(IStatsProducer)
PORTNUMFILE = "client.port" PORTNUMFILE = "client.port"
STOREDIR = 'storage' STOREDIR = 'storage'
NODETYPE = "client" NODETYPE = "client"
@ -60,6 +62,7 @@ class Client(node.Node, testutil.PollMixin):
def __init__(self, basedir="."): def __init__(self, basedir="."):
node.Node.__init__(self, basedir) node.Node.__init__(self, basedir)
self.started_timestamp = time.time()
self.logSource="Client" self.logSource="Client"
self.nickname = self.get_config("nickname") self.nickname = self.get_config("nickname")
if self.nickname is None: if self.nickname is None:
@ -107,9 +110,13 @@ class Client(node.Node, testutil.PollMixin):
if gatherer_furl: if gatherer_furl:
self.stats_provider = StatsProvider(self, gatherer_furl) self.stats_provider = StatsProvider(self, gatherer_furl)
self.add_service(self.stats_provider) self.add_service(self.stats_provider)
self.stats_provider.register_producer(self)
else: else:
self.stats_provider = None self.stats_provider = None
def get_stats(self):
return { 'node.uptime': time.time() - self.started_timestamp }
def init_lease_secret(self): def init_lease_secret(self):
secret_s = self.get_or_create_private_config("secret", _make_secret) secret_s = self.get_or_create_private_config("secret", _make_secret)
self._lease_secret = base32.a2b(secret_s) self._lease_secret = base32.a2b(secret_s)

View File

@ -133,6 +133,10 @@ class Basic(unittest.TestCase):
all_versions = allmydata.get_package_versions_string() all_versions = allmydata.get_package_versions_string()
self.failUnless("allmydata" in all_versions) self.failUnless("allmydata" in all_versions)
log.msg("tahoe versions: %s" % 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): def flush_but_dont_ignore(res):
d = flushEventualQueue() d = flushEventualQueue()