Changeset c9047b1 in trunk


Ignore:
Timestamp:
2016-04-28T00:40:04Z (9 years ago)
Author:
Brian Warner <warner@…>
Branches:
master
Children:
bde22ad1
Parents:
e187fba (diff), ea473cd (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch PR#242: switch stats-gatherer to JSON

Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified docs/stats.rst

    re187fba rc9047b1  
    310310as described in :doc:`configuration`.
    311311
    312 Once running, the stats gatherer will create a standard python "pickle" file
    313 in $BASEDIR/stats.pickle . Once a minute, the gatherer will pull stats
    314 information from every connected node and write them into the pickle. The
    315 pickle will contain a dictionary, in which node identifiers (known as "tubid"
     312Once running, the stats gatherer will create a standard JSON file in
     313``$BASEDIR/stats.json``. Once a minute, the gatherer will pull stats
     314information from every connected node and write them into the file. The file
     315will contain a dictionary, in which node identifiers (known as "tubid"
    316316strings) are the keys, and the values are a dict with 'timestamp',
    317317'nickname', and 'stats' keys. d[tubid][stats] will contain the stats
    318318dictionary as made available at http://localhost:3456/statistics?t=json . The
    319 pickle file will only contain the most recent update from each node.
     319file will only contain the most recent update from each node.
    320320
    321321Other tools can be built to examine these stats and render them into
     
    336336Most of the plugins are designed to pull stats from a single Tahoe node, and
    337337are configured with the e.g. http://localhost:3456/statistics?t=json URL. The
    338 "tahoe_stats" plugin is designed to read from the pickle file created by the
     338"tahoe_stats" plugin is designed to read from the JSON file created by the
    339339stats-gatherer. Some plugins are to be used with the disk watcher, and a few
    340340(like tahoe_nodememory) are designed to watch the node processes directly
  • TabularUnified misc/operations_helpers/munin/tahoe-stats.plugin-conf

    re187fba rc9047b1  
    11[tahoe_storage_allocated]
    2 env.statsfile /home/robk/trees/tahoe/stats_gatherer/stats.pickle
     2env.statsfile /home/robk/trees/tahoe/stats_gatherer/stats.json
    33[tahoe_storage_consumed]
    4 env.statsfile /home/robk/trees/tahoe/stats_gatherer/stats.pickle
     4env.statsfile /home/robk/trees/tahoe/stats_gatherer/stats.json
    55[tahoe_runtime_load_avg]
    6 env.statsfile /home/robk/trees/tahoe/stats_gatherer/stats.pickle
     6env.statsfile /home/robk/trees/tahoe/stats_gatherer/stats.json
    77[tahoe_runtime_load_peak]
    8 env.statsfile /home/robk/trees/tahoe/stats_gatherer/stats.pickle
     8env.statsfile /home/robk/trees/tahoe/stats_gatherer/stats.json
    99[tahoe_storage_bytes_added]
    10 env.statsfile /home/robk/trees/tahoe/stats_gatherer/stats.pickle
     10env.statsfile /home/robk/trees/tahoe/stats_gatherer/stats.json
    1111[tahoe_storage_bytes_freed]
    12 env.statsfile /home/robk/trees/tahoe/stats_gatherer/stats.pickle
     12env.statsfile /home/robk/trees/tahoe/stats_gatherer/stats.json
  • TabularUnified misc/operations_helpers/munin/tahoe_stats

    re187fba rc9047b1  
    22
    33import os
    4 import pickle
     4import json
    55import re
    66import sys
     
    429429def open_stats(fname):
    430430    f = open(fname, 'rb')
    431     stats = pickle.load(f)
     431    stats = json.load(f)
    432432    f.close()
    433433    return stats
  • TabularUnified src/allmydata/stats.py

    re187fba rc9047b1  
    11
     2import json
    23import os
    3 import pickle
    44import pprint
    55import time
     
    241241        pprint.pprint(stats)
    242242
    243 class PickleStatsGatherer(StdOutStatsGatherer):
     243class JSONStatsGatherer(StdOutStatsGatherer):
    244244    # inherit from StdOutStatsGatherer for connect/disconnect notifications
    245245
     
    247247        self.verbose = verbose
    248248        StatsGatherer.__init__(self, basedir)
    249         self.picklefile = os.path.join(basedir, "stats.pickle")
    250 
    251         if os.path.exists(self.picklefile):
    252             f = open(self.picklefile, 'rb')
     249        self.jsonfile = os.path.join(basedir, "stats.json")
     250
     251        if os.path.exists(self.jsonfile):
     252            f = open(self.jsonfile, 'rb')
    253253            try:
    254                 self.gathered_stats = pickle.load(f)
     254                self.gathered_stats = json.load(f)
    255255            except Exception:
    256                 print ("Error while attempting to load pickle file %s.\n"
    257                        "You may need to restore this file from a backup, or delete it if no backup is available.\n" %
    258                        quote_local_unicode_path(self.picklefile))
     256                print ("Error while attempting to load stats file %s.\n"
     257                       "You may need to restore this file from a backup,"
     258                       " or delete it if no backup is available.\n" %
     259                       quote_local_unicode_path(self.jsonfile))
    259260                raise
    260261            f.close()
     
    267268        s['nickname'] = nickname
    268269        s['stats'] = stats
    269         self.dump_pickle()
    270 
    271     def dump_pickle(self):
    272         tmp = "%s.tmp" % (self.picklefile,)
     270        self.dump_json()
     271
     272    def dump_json(self):
     273        tmp = "%s.tmp" % (self.jsonfile,)
    273274        f = open(tmp, 'wb')
    274         pickle.dump(self.gathered_stats, f)
     275        json.dump(self.gathered_stats, f)
    275276        f.close()
    276         if os.path.exists(self.picklefile):
    277             os.unlink(self.picklefile)
    278         os.rename(tmp, self.picklefile)
     277        if os.path.exists(self.jsonfile):
     278            os.unlink(self.jsonfile)
     279        os.rename(tmp, self.jsonfile)
    279280
    280281class StatsGathererService(service.MultiService):
     
    291292        self.tub.setOption("expose-remote-exception-types", False)
    292293
    293         self.stats_gatherer = PickleStatsGatherer(self.basedir, verbose)
     294        self.stats_gatherer = JSONStatsGatherer(self.basedir, verbose)
    294295        self.stats_gatherer.setServiceParent(self)
    295296
Note: See TracChangeset for help on using the changeset viewer.