python如何實(shí)現(xiàn)統(tǒng)計(jì)osd-pg并導(dǎo)出到csv,針對(duì)這個(gè)問(wèn)題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問(wèn)題的小伙伴找到更簡(jiǎn)單易行的方法。
創(chuàng)新互聯(lián)公司專注于企業(yè)成都全網(wǎng)營(yíng)銷(xiāo)、網(wǎng)站重做改版、甘孜州網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、成都h5網(wǎng)站建設(shè)、電子商務(wù)商城網(wǎng)站建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為甘孜州等各大城市提供網(wǎng)站開(kāi)發(fā)制作服務(wù)。
分析當(dāng)前集群各個(gè)OSD的pg分布情況
import json from collections import OrderedDict import csv import subprocess def get_pg_dump(): cmd = "ceph pg dump --format=json" out = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) result = out.stdout.readlines()[1].split('\n')[0] return result csv_file = './demo.csv' #生成的csv文件路徑 pg_data = json.loads(get_pg_dump()) pg_dict = {} osd_pg_dict = {} for i in pg_data: for j in pg_data['pg_stats']: pg_dict[j['pgid']] = j['up'] pool_pg_total = {} osd_pg_num_dict = {} tmp_pool_list = {} tmp_osd_list = {} start_osd = 0 start_pool_id = 0 all_result = {} for i in pg_dict: pool_id = int(i.split('.')[0]) for osd_id in pg_dict[i]: tmp_pool_list[pool_id] = pool_id tmp_osd_list[osd_id] = osd_id num_pool = max(tmp_pool_list.iterkeys(), key=lambda k: tmp_pool_list[k]) + 1 num_osd = max(tmp_osd_list.iterkeys(), key=lambda k: tmp_osd_list[k]) + 1 pool_totol_pg = [0] * num_pool max_osd_list = [0] * num_pool min_osd_list = [999] * num_pool max_osdid_list = ['No_OSD'] * num_pool min_osdid_list = ['No_OSD'] * num_pool ave_osd_list = [0] * num_pool ave_osd_list_result = [0] * num_pool min_osd_per_list = [0] * num_pool max_osd_per_list = [0] * num_pool for i in range(0,num_osd): keyname = str(i) all_result[keyname] = [0] * num_pool for i in pg_dict: pool_id = int(i.split('.')[0]) for osd_id in pg_dict[i]: tmp_keyname = str(osd_id) tmp_list = all_result[tmp_keyname] tmp_list[pool_id] = tmp_list[pool_id] +1 for i in all_result: tmp_num = 0 for j in all_result[i]: if j < min_osd_list[tmp_num] and j != 0: min_osd_list[tmp_num] = j min_osdid_list[tmp_num] = i if j > max_osd_list[tmp_num]: max_osd_list[tmp_num] = j max_osdid_list[tmp_num] = i if j != 0: ave_osd_list[tmp_num] = ave_osd_list[tmp_num] + 1 pool_totol_pg[tmp_num] = pool_totol_pg[tmp_num] + j tmp_num = tmp_num + 1 for i in range(0,len(ave_osd_list)): if ave_osd_list[i] != 0: ave_osd_list_result[i] = pool_totol_pg[i]/ave_osd_list[i] all_result = OrderedDict(sorted(all_result.items(), key=lambda t: int(t[0]))) for i in range(0,num_pool): if max_osd_list[i] != 0: max_osd_per_list[i] = round(100*(max_osd_list[i]-ave_osd_list_result[i])/float(ave_osd_list_result[i]),2) for i in range(0, num_pool): if min_osd_list[i] != 999: min_osd_per_list[i] = round(100 * (min_osd_list[i] - ave_osd_list_result[i])/float(ave_osd_list_result[i]),2) with open(csv_file, 'w') as csvfile: pool_list = [] for i in range(0,num_pool): pool_list.append('pool-'+str(i)) fieldnames = ['osd_name'] + pool_list + ['total'] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() for i in all_result: tmp_dict = {'osd_name': i,'total':sum(all_result[i])} tmp_num = 0 for j in all_result[i]: keyname = 'pool-' + str(tmp_num) tmp_num = tmp_num + 1 tmp_dict[keyname] = j writer.writerow(tmp_dict) fieldnames = ['SUM'] + pool_totol_pg + [sum(pool_totol_pg)] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() fieldnames = ['AVE'] + ave_osd_list_result + [sum(ave_osd_list_result)] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() fieldnames = ['MAX'] + max_osd_list + [sum(max_osd_list)] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() fieldnames = ['MAX-OSD-ID'] + max_osdid_list writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() fieldnames = ['MAX-PER'] + max_osd_per_list + [sum(max_osd_per_list)] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() fieldnames = ['MIN'] + min_osd_list + [sum(min_osd_list)] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() fieldnames = ['MIN-OSD-ID'] + min_osdid_list writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() fieldnames = ['MIN-PER'] + min_osd_per_list + [sum(min_osd_per_list)] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() print '---------------------------------------------------------------------------' for i in all_result: print i,all_result[i],sum(all_result[i]) print '---------------------------------------------------------------------------' print 'SUM',pool_totol_pg print 'MAX',max_osd_list print 'MIN-OSD-ID',max_osdid_list print 'MIN',min_osd_list print 'MIN-OSD-ID',min_osdid_list print 'AVE',ave_osd_list_result print 'MIN-PER',min_osd_per_list print 'MAX-PER',max_osd_per_list
關(guān)于python如何實(shí)現(xiàn)統(tǒng)計(jì)osd-pg并導(dǎo)出到csv問(wèn)題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒(méi)有解開(kāi),可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識(shí)。
分享文章:python如何實(shí)現(xiàn)統(tǒng)計(jì)osd-pg并導(dǎo)出到csv
分享鏈接:http://muchs.cn/article22/joodcc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、網(wǎng)站改版、網(wǎng)站設(shè)計(jì)公司、網(wǎng)站建設(shè)、面包屑導(dǎo)航、商城網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)