Skip to content

Commit

Permalink
Merge 04c4e1a into 28f2a0f
Browse files Browse the repository at this point in the history
  • Loading branch information
MostAwesomeDude committed Feb 26, 2016
2 parents 28f2a0f + 04c4e1a commit 6f65717
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
11 changes: 6 additions & 5 deletions docs/stats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,14 @@ given port. The portnum file is actually a "strports specification string",
as described in configuration.rst_.

Once running, the stats gatherer will create a standard python "pickle" file
in $BASEDIR/stats.pickle . Once a minute, the gatherer will pull stats
in ``$BASEDIR/stats.pickle``, and a standard JSON file in
``$BASEDIR/stats.json``. Once a minute, the gatherer will pull stats
information from every connected node and write them into the pickle. The
pickle will contain a dictionary, in which node identifiers (known as "tubid"
strings) are the keys, and the values are a dict with 'timestamp',
'nickname', and 'stats' keys. d[tubid][stats] will contain the stats
dictionary as made available at http://localhost:3456/statistics?t=json . The
pickle file will only contain the most recent update from each node.
strings) are the keys, and the values are a dict with 'timestamp', 'nickname',
and 'stats' keys. d[tubid][stats] will contain the stats dictionary as made
available at http://localhost:3456/statistics?t=json . The pickle file will
only contain the most recent update from each node.

Other tools can be built to examine these stats and render them into
something useful. For example, a tool could sum the
Expand Down
13 changes: 13 additions & 0 deletions src/allmydata/stats.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

import json
import os
import pickle
import pprint
Expand Down Expand Up @@ -250,6 +251,7 @@ def __init__(self, basedir=u".", verbose=True):
self.verbose = verbose
StatsGatherer.__init__(self, basedir)
self.picklefile = os.path.join(basedir, "stats.pickle")
self.jsonfile = os.path.join(basedir, "stats.json")

if os.path.exists(self.picklefile):
f = open(self.picklefile, 'rb')
Expand All @@ -270,6 +272,7 @@ def got_stats(self, stats, tubid, nickname):
s['nickname'] = nickname
s['stats'] = stats
self.dump_pickle()
self.dump_json()

def dump_pickle(self):
tmp = "%s.tmp" % (self.picklefile,)
Expand All @@ -280,6 +283,16 @@ def dump_pickle(self):
os.unlink(self.picklefile)
os.rename(tmp, self.picklefile)

def dump_json(self):
# Same logic as pickle, but using JSON instead.
tmp = "%s.tmp" % (self.jsonfile,)
f = open(tmp, 'wb')
json.dump(self.gathered_stats, f)
f.close()
if os.path.exists(self.jsonfile):
os.unlink(self.jsonfile)
os.rename(tmp, self.jsonfile)

class StatsGathererService(service.MultiService):
furl_file = "stats_gatherer.furl"

Expand Down

0 comments on commit 6f65717

Please sign in to comment.