Ceph 自動reweight指令碼
Ceph的資料分佈是由CRUSH Map解決定的,而CRUSH演算法是偽HASH的,所以在一定時間內,資料會存在傾斜,這就需要我們用指令碼來進行定期的reweight:
#author
#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()
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30088583/viewspace-2140370/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 自動ftp指令碼FTP指令碼
- specjvm自動化指令碼JVM指令碼
- 自動備份指令碼指令碼
- docker指令碼自動化Docker指令碼
- LNMP自動部署指令碼LNMP指令碼
- awr自動收集指令碼指令碼
- 自動化RMAN指令碼指令碼
- Ubuntu自動啟動配置指令碼Ubuntu指令碼
- 網路卡自動啟動指令碼指令碼
- Dockerfile---指令碼自動化Docker指令碼
- Linux自啟動指令碼Linux指令碼
- hadoop自動提交指令碼Hadoop指令碼
- MySQL自動備份指令碼MySql指令碼
- 自動生成Statspack的指令碼指令碼
- vue自動化部署指令碼Vue指令碼
- Linux管理指令碼之自動執行指令碼Linux指令碼
- centos 自動啟動指令碼和自啟動服務CentOS指令碼
- windows下oracle自動啟動指令碼WindowsOracle指令碼
- iOS自動打包指令碼+自動上傳到firiOS指令碼
- 自動化指令碼安裝mysql shell指令碼範例指令碼MySql
- 解剖Nginx·自動指令碼篇(4)工具型指令碼系列Nginx指令碼
- iOS —— 兩套自動打包指令碼iOS指令碼
- 實現指令碼自動部署docker指令碼Docker
- Python——自動簽到指令碼Python指令碼
- oracle自動冷備份指令碼Oracle指令碼
- mydumper自動化安裝指令碼指令碼
- 自動生成ASH報告指令碼指令碼
- 開機自啟動Powershell指令碼指令碼
- oracle 巡檢指令碼(自動化)Oracle指令碼
- ORACLE自動備份shell指令碼Oracle指令碼
- svn and maven 自動部署shell指令碼Maven指令碼
- UNIX crontab自動執行指令碼指令碼
- AWR報告自動生成指令碼指令碼
- securt crt 自動登陸指令碼指令碼
- oracle報表自動FTP指令碼OracleFTP指令碼
- rman 自動備份指令碼-windows指令碼Windows
- 自動生成awr報告指令碼指令碼
- ssh自動輸入密碼指令碼 切換目錄指令碼密碼指令碼