Python怎样绘制Crushmap分布图
发表于:2025-02-08 作者:千家信息网编辑
千家信息网最后更新 2025年02月08日,Python怎样绘制Crushmap分布图,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。原理使用命令ceph report --form
千家信息网最后更新 2025年02月08日Python怎样绘制Crushmap分布图
Python怎样绘制Crushmap分布图,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
原理
使用命令ceph report --format=json > crush.json导出json格式数据文件,之后使用pydot和graphviz实现绘图。
使用说明
安装依赖
pip install pydotpip install graphviz
脚本代码
# -*- coding: utf-8 -*-import pydotfrom graphviz import Digraphimport jsonimport sysclass build_crushmap_graphviz(): """ 1. 使用命令ceph report --format=json > crush.json导出数据文件 2. 每种类型bucket一个颜色,不够自己去color_list里面添加,支持最多10级结构 3. 生成的文件默认问png格式,文件保存在当前目录的crushmap.png """ def __init__(self): self.graph = pydot.Dot('ceph_crushmap', graph_type='digraph') self.dot = Digraph(comment='CrushMap', node_attr={'shape': 'record', 'height': '.1'}) self.dot.graph_attr['size'] = '4096,2160' self.dot.graph_attr['resolution'] = '100' self.dot.graph_attr['bb'] = '0,0,4,8' self.dot.format = 'png' self.color_list = ["maroon", "pink", "khaki", "orange", "purple", "yellow", "cyan", "beige", "red"] self.save_name = "crushmap" def build(self, crushmap_file): try: with open(crushmap_file) as data_file: data = json.load(data_file) for i in range(len(data['crushmap']['devices'])): self.dot.node(str(data['crushmap']['devices'][i]['id']), 'device: ' + data['crushmap']['devices'][i]['name'], {'style': 'filled', 'fillcolor': 'green'}) tmp_list = [] color_dict = {} for i in range(len(data['crushmap']['buckets'])): if data['crushmap']['buckets'][i]['type_name'] in tmp_list: color_ = color_dict[data['crushmap']['buckets'][i]['type_name']] else: tmp_list.append(data['crushmap']['buckets'][i]['type_name']) color_ = self.color_list.pop() color_dict[data['crushmap']['buckets'][i]['type_name']] = color_ self.dot.node(str(data['crushmap']['buckets'][i]['id']), data['crushmap']['buckets'][i]['type_name'] + ': ' + data['crushmap']['buckets'][i]['name'], {'style': 'filled', 'fillcolor': color_}) edges_list = [] for i in range(len(data['crushmap']['buckets'])): for j in range(len(data['crushmap']['buckets'][i]['items'])): self.dot.edge(str(data['crushmap']['buckets'][i]['id']), str(data['crushmap']['buckets'][i]['items'][j]['id'])) edges_list.append( str(data['crushmap']['buckets'][i]['id']) + str(data['crushmap']['buckets'][i]['items'][j]['id'])) self.dot.render(self.save_name) print "Sucessful, File = {}.{}".format(self.save_name,self.dot.format) except: print "Faild!"if __name__ == '__main__': file_path = sys.argv[1] crush_make = build_crushmap_graphviz() crush_make.build(file_path)
用例
保存上面的脚本为build_crushmap.py,执行以下命令,成功会生成crushmap.png
user@demo$ python build_crushmap.py crush3.jsonSucessful, File = crushmap.png
看完上述内容,你们掌握Python怎样绘制Crushmap分布图的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!
文件
命令
分布图
内容
数据
方法
更多
格式
脚本
问题
生成
成功
束手无策
为此
不够
代码
使用说明
原因
原理
对此
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
新疆网络安全安全信息
网络安全认知升级数字化
数据库和引文索引的区别
软件开发是35
龙城飞将服务器
南京企业软件开发团队
代理服务器关闭后又自动打开
网络安全现场处置流程
数据库设计及规范化
网络安全团课应该表演什么
传奇私服攻击别人服务器
男生学会计好还是网络技术好
外网数据库安全
山东专业软件开发哪家实惠
怎么查db2数据库有没有开增量
北京服务器存储维保云空间
网络安全10月8号
客户端和服务器msdn不匹配
卜鸣网络技术有限公司
简述你的网络安全观
网络安全虚拟仿真实验项目建议
数据库和引文索引的区别
云南丽江网络安全
qq软件开发商怎么赚钱
佛山商城软件开发设计
戴尔服务器更改启动方式
网络安全方面政府信息
数据库等于
软件开发交付失败
网络安全监察系是干什么的