Permalink
Browse files

implement different btrc commands

  • Loading branch information...
1 parent a45bc8d commit 4c57ecc0b83f99e8acf8fb6ff831d5fee16263e9 @pavel-paulau committed Jan 15, 2013
Showing with 33 additions and 11 deletions.
  1. +8 −2 README.md
  2. +25 −9 btrc.py
View
@@ -12,6 +12,12 @@ Installation
Usage
-------------
-Once you have pointed btrc to node it will collect view btree stats from all nodes in cluster and all design docs for specified bucket.
+Once you have pointed btrc to node it will collect stats from all nodes in cluster and all design docs for specified bucket:
- btrc -n 127.0.0.1:8091 -b default
+ btrc -n 127.0.0.1:8091 -b default -c btree_stats
+
+ btrc -n 127.0.0.1:8091 -b default -c util_stats
+
+You also can reset utilization stats:
+
+ btrc -n 127.0.0.1:8091 -b default -c reset
View
34 btrc.py
@@ -76,21 +76,27 @@ class CliArgs(object):
"""
def __init__(self):
- usage = 'usage: %prog -n node:port [-b bucket]\n\n' +\
- 'Example: %prog -n 127.0.0.1:8091 -b default'
+ usage = 'usage: %prog -n node:port [-b bucket] -c command \n\n' +\
+ 'Example: %prog -n 127.0.0.1:8091 -b default -c btree_stats'
parser = OptionParser(usage)
parser.add_option('-n', dest='node',
help='Node address', metavar='127.0.0.1:8091')
parser.add_option('-b', dest='bucket', default='default',
help='Bucket name', metavar='default')
+ parser.add_option('-c', dest='command',
+ help='Stats command', metavar='command')
self.options, self.args = parser.parse_args()
if not self.options.node:
- parser.print_help()
- sys.exit(1)
+ parser.error('Missing node address [-n]')
+ if not self.options.command:
+ parser.error('Missing command [-c]')
+ if self.options.command not in ('btree_stats', 'util_stats', 'reset'):
+ parser.error('Only "btree_stats", "util_stats" and "reset" '
+ 'commands supported')
class StatsReporter():
@@ -99,19 +105,29 @@ class StatsReporter():
def __init__(self, cb):
self.cb = cb
- def report_btree_stats(self):
- for node, ddoc, stat in self.cb.get_btree_stats():
- filename = node.replace(':', '_') + ddoc.replace('/', '_') + '.json'
+ def report_stats(self, stats_type):
+ if stats_type == 'btree_stats':
+ stats_generator = self.cb.get_btree_stats
+ else:
+ stats_generator = self.cb.get_utilization_stats
+
+ for node, ddoc, stat in stats_generator():
+ filename = '{0}_{1}{2}.json'.format(stats_type,
+ node.replace(':', '_'),
+ ddoc.replace('/', '_'))
with open(filename, 'w') as fh:
- print 'Saving btree stats to: ' + filename
+ print 'Saving {0} stats to: {1}'.format(stats_type, filename)
fh.write(json.dumps(stat, indent=4, sort_keys=True))
def main():
ca = CliArgs()
cb = CouchbaseClient(ca.options.node, ca.options.bucket)
reporter = StatsReporter(cb)
- reporter.report_btree_stats()
+ if ca.options.command in ('btree_stats', 'util_stats'):
+ reporter.report_stats(ca.options.command)
+ elif ca.options.command == 'reset':
+ cb.reset_utilization_stats()
if __name__ == '__main__':
main()

0 comments on commit 4c57ecc

Please sign in to comment.