Skip to content

Instantly share code, notes, and snippets.

@alram
Last active August 29, 2015 14:24
Show Gist options
  • Save alram/3231174bc972dbacc918 to your computer and use it in GitHub Desktop.
Save alram/3231174bc972dbacc918 to your computer and use it in GitHub Desktop.
perf_dump_avg_latencies
import argparse
import os
import subprocess
import json
asock_path = '/var/run/ceph/'
data_type = ['osd', 'filestore']
def get_perf_values(output, type):
latency_data = {}
for key in output[type]:
if 'latency' in key:
if not output[type][key]['avgcount'] == 0:
latency_data[key] = output[type][key]['sum'] / output[type][key]['avgcount']
else:
latency_data[key] = 'N/A'
return latency_data
#TODO store data in array && figure output formatting
def get_socket_data(type):
for asock in os.listdir(asock_path):
if asock.startswith('ceph-osd'):
asock_full_path = os.path.join(asock_path, asock)
args = ['ceph', '--admin-daemon', asock_full_path, 'perf', 'dump']
try:
output = json.loads(subprocess.check_output(args))
except:
return
if type == 'all' or type == 'osd':
print get_perf_values(output, 'osd')
if type == 'all' or type == 'filestore':
print get_perf_values(output, 'filestore')
def parse_args():
parser = argparse.ArgumentParser(description='ceph-osd average latency.')
parser.add_argument(
'-t', '--type',
metavar='TYPE',
choices=['all', 'osd', 'filestore'],
required=True,
help='Display <TYPE> latencies',
)
args = parser.parse_args()
return args
if __name__ == '__main__':
args = parse_args()
get_socket_data(args.type)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment