[关闭]
@tony-yin 2017-10-10T21:16:40.000000Z 字数 2313 阅读 724

Enable Osd Profile Script

Magicloud Script


docprofile.py:提供cprofiler的装饰器接口

  1. import cProfile
  2. import pstats
  3. import os
  4. def do_cprofile(filename):
  5. """
  6. Decorator for function profiling.
  7. """
  8. def wrapper(func):
  9. def profiled_func(*args, **kwargs):
  10. print filename
  11. # Flag for do profiling or not.
  12. DO_PROF = os.getenv("PROFILING")
  13. if DO_PROF:
  14. profile = cProfile.Profile()
  15. profile.enable()
  16. result = func(*args, **kwargs)
  17. profile.disable()
  18. # Sort stat by internal time.
  19. sortby = "cum"
  20. ps = pstats.Stats(profile).sort_stats(sortby)
  21. ps.dump_stats(filename)
  22. else:
  23. result = func(*args, **kwargs)
  24. return result
  25. return profiled_func
  26. return wrapper

create_osd.py:批量创建osd的脚本,目前支持批量创建20个或者以下数量的osd,默认/dev/sda/dev/sdb10个,并且journal分区采用预设分区,分区类型为单一分区,缓存为空,参数较为简单,仅供测试使用,如果有其他需求,需要适当修改代码

使用方法: python create_osd.py osd1 20 // 起始osd, 数量

  1. from mcs3 import storage
  2. import sys
  3. first_osd = sys.argv[1]
  4. num = sys.argv[2]
  5. first_number = int(first_osd[3:])
  6. count = 1
  7. for osd in range(first_number, int(num) + first_number)
  8. sv_name = 'osd' + str(osd)
  9. data_dev = '/dev/sda' + str(osd) if count <=10 else '/dev/sdb' + str(osd - 10)
  10. journal_dev = ''
  11. cache_dev = ''
  12. host = '10.16.100.99'
  13. storage.add_storage_volume_single(sv_name, data_dev, journal_dev, cache_dev, _host=host)
  14. count += 1

enable_osd.pyadmin层启用osd的后端脚本,一些参数都是默认设置好的,所以有需要改变的要修改部分hardcode

需要注意的是这段代码不会等待后端所有启用工作执行完毕才结束,而是调用后就直接结束脚本执行了

  1. import mcs3.config
  2. from mcs3.cluster import ClusterManager, IfaceRoleChangeInUse, IfaceRoleNotDefined
  3. from mcs3.license import *
  4. from mcs3.node_management import prepare_enable_osd, enable_osd
  5. from mcs3.remote import TASK_TICKET, ASYNC_MODE
  6. import sys
  7. from docprofile import do_cprofile
  8. @do_cprofile('./enable_osd.out')
  9. def test():
  10. ip = '10.16.100.99'
  11. cluster_if = ''
  12. public_if = 'eth0'
  13. first_osd = sys.argv[1]
  14. num = sys.argv[2]
  15. svs = []
  16. for osd in range(int(first_osd[3:]), int(num)+int(first_osd[3:])):
  17. svs.append('osd' + str(osd))
  18. print svs
  19. mgr = ClusterManager()
  20. all_osds = mgr.list_hosts_in_pool("default")
  21. cluster_ip = mcs3.config.Mcs3CephConfig().get_storage_ip()
  22. lic_str = get_license_key(cluster_ip)
  23. if not lic_str:
  24. lic_str = get_pre_license()
  25. if not lic_str:
  26. raise LicenseNotFound()
  27. set_license_key(lic_str, ip)
  28. prepare_enable_osd(cluster_if, public_if, svs, _host=ip)
  29. enable_osd(svs, True,
  30. _host=ip,
  31. _async=ASYNC_MODE.WAIT_UPDATED,
  32. _ticket=TASK_TICKET.ENABLE_OSD)
  33. if __name__ == '__main__':
  34. test()

pstat.py:用于处理生成的cprofiler文件,做一些排序,截取和打印等工作,默认按culativetime排序,打印前100条记录,有其他需求的可以适当修改参数

  1. import pstats, sys
  2. file = sys.argv[1]
  3. p = pstats.Stats(file)
  4. p.strip_dirs().sort_stats('cum').print_stats(100)
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注