网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

Ceph自动reweight脚本

Ceph的数据分布是由CRUSH Map解决定的,而CRUSH算法是伪HASH的,所以在一定时间内,数据会存在倾斜,这就需要我们用脚本来进行定期的reweight:

专注于为中小企业提供成都网站建设、成都网站设计服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业尧都免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上千家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

#authorjesse.js.lyu@gmail.com

#reweight for ceph osds

 

 

import hashlib

import commands

import threading

import sys

from time import ctime,sleep

import urllib2

import json

def doReweight(osdMaxUtilId, osdTargetReweight):

    print 'ceph osd reweight ' + str(osdMaxUtilId) + ' ' + str(osdTargetReweight)

    (status,output) = commands.getstatusoutput('ceph osd reweight '+ str(osdMaxUtilId) +' ' + str(osdTargetReweight))

    print status,output

def  canOSDReweight():

    #

    canDoReweight = False

    pgStateIsOk = False

    osdUtilDiffEnough = False

    #determine pg status

    (status,output) = commands.getstatusoutput('ceph -s --format=json-pretty')

    pgMapJson = json.loads(output)

    #print pgMapJson['pgmap']['pgs_by_state']

    numPGS = pgMapJson['pgmap']['num_pgs']

    for pgState in pgMapJson['pgmap']['pgs_by_state']:

        if pgState['state_name'] == 'active+clean' and pgState['count'] == numPGS:

            pgStateIsOk = True

    if pgStateIsOk == False:

        print "pg is reweighting or can't do reweight right now...."

        exit

    #determine OSD util diff

    (status,output) = commands.getstatusoutput('ceph osd df --format=json-pretty')

    #print status,output

    osdMaxUtil=0

    osdMaxUtilId=-1

    osdMaxReweight=1

    osdMinUtil=100

    osdMinUtilId=-1

    osdReweightStep=0.01

    if status == 0:

        osdDictJson = json.loads(output)

        for node in osdDictJson['nodes']:

                if node['utilization'] > osdMaxUtil:

                        osdMaxUtilId = node['id']

                        osdMaxUtil = node['utilization']

                        osdMaxReweight = node['reweight']

                if node['utilization'] < osdMinUtil:

                        osdMinUtilId = node['id']

                        osdMinUtil = node['utilization']

        osdTargetReweight = osdMaxReweight - osdReweightStep

        osdUtilDiff = (osdMaxUtil - osdMinUtil)/osdMinUtil*100

        if osdUtilDiff > 10:

            osdUtilDiffEnough = True

            print "Max and Min OSD's utilization diff is " + str(osdUtilDiff)

        else:

            print "Max and Min OSD's utilization diff is " + str(osdUtilDiff) + ",less then 10%, give up..."

            exit

    if  pgStateIsOk == True and osdUtilDiffEnough == True and osdTargetReweight > 0: 

        print "================ doing reweight ==============="

        print osdMaxUtilId,osdMaxUtil,osdMaxReweight

        print osdMinUtilId,osdMinUtil

        doReweight(osdMaxUtilId, osdTargetReweight)

def invokeOSDReweight():

    while True:

        sleep(30)

        canOSDReweight()

if __name__ == '__main__':

    invokeOSDReweight()


文章标题:Ceph自动reweight脚本
分享网址:http://bjjierui.cn/article/igpejg.html

其他资讯