In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
Python how to draw Crushmap distribution map, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
Principle
Use the command ceph report-- format=json > crush.json to export the json format data file, and then use pydot and graphviz to implement the drawing.
Use instructions to install dependent pip install pydotpip install graphviz script code #-*-coding: utf-8-*-import pydotfrom graphviz import Digraphimport jsonimport sysclass build_crushmap_graphviz (): "" 1. Use the command ceph report-- format=json > crush.json to export the data file 2. 0. Each type of bucket one color, not enough to add their own color_list, support up to 10 levels of structure 3. The generated file is in png format by default. The file is saved in the crushmap.png "" def _ _ init__ (self) of the current directory: 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 self.dot.graph_attr 2160 'self.dot.graph_attr [' resolution'] = '100' self.dot.graph_attr [' bb'] = '0pime 4pia 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 (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 (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 (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 (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) use case
Save the above script as build_crushmap.py, execute the following command, and crushmap.png will be generated successfully.
User@demo$ python build_crushmap.py crush3.jsonSucessful, File = crushmap.png after reading the above, have you mastered how Python draws the Crushmap distribution map? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.