Skip to content

Instantly share code, notes, and snippets.

@Chippiewill
Created June 21, 2016 13:45
Show Gist options
  • Save Chippiewill/bd97f84c2549944dd9d8c03e2f669ff7 to your computer and use it in GitHub Desktop.
Save Chippiewill/bd97f84c2549944dd9d8c03e2f669ff7 to your computer and use it in GitHub Desktop.
import os
from subprocess import call
import sys
import time
if len(sys.argv) > 2 and sys.argv[2] == "cbstats":
def get_stats():
out = os.popen("/Applications/Couchbase\ Server.app/Contents/Resources/couchbase-core/bin/cbstats {} all -b {}".format(sys.argv[1], sys.argv[2])).read()
ret = []
for row in out.split("\n"):
if row:
k, v = row.split(":", 1)
ret.append((k, {"{}".format(sys.argv[1]): v}))
return ret
else:
import couchbase.bucket
default = couchbase.bucket.Bucket("couchbase://{}/{}".format(sys.argv[1], sys.argv[2]))
def get_stats():
return default.stats().items()
iostats_last = None
while True:
iostats = {}
for k, v in get_stats():
if 'ep_io' in k:
iostats[k] = v
if iostats_last:
for k, cluster in iostats_last.items():
print k
for node, v in cluster.items():
print node, (int(iostats[k][node]) - int(v)) / 1024, "KiB/s"
print
print
iostats_last = iostats
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment