iops簡介
iops主要用在數(shù)據(jù)方面,這個(gè)指標(biāo)是數(shù)據(jù)庫性能評(píng)定的一個(gè)重要參考,iops的是每秒進(jìn)行讀寫(I/O)操作的次數(shù),主要看隨機(jī)訪問的性能,一般為了iops增高都要依靠磁盤陣列,實(shí)際線上的數(shù)據(jù)庫基本都是raid10的配置,raid5在實(shí)際生產(chǎn)環(huán)境中如果壓力上來是抗不住的,當(dāng)然也要開具體業(yè)務(wù)壓力情況,如果是用物理機(jī)就要看iops在實(shí)際中能跑到多少值,現(xiàn)在云也普遍了,如果你用的RDS云數(shù)據(jù)庫,這個(gè)iops是可以根據(jù)業(yè)務(wù)情況自己選擇的,基本是個(gè)參數(shù),可以按需進(jìn)行修改,當(dāng)然數(shù)值越大費(fèi)用越高
python獲得系統(tǒng)iops代碼如下:
#!/usr/bin/python
import os, time, math
run_tests = 3
devices = os.listdir('/sys/block/')
check_devices = []
reads = {}
writes = {}
for dev in devices:
if dev.startswith('md') or dev.startswith('sd') or dev.startswith('hd'):
check_devices.append(dev)
reads[dev] = []
writes[dev] = []
check_devices = sorted(check_devices)
for t in range(run_tests + 1):
for dev in check_devices:
file_data = open('/sys/block/%s/stat' % dev).readline().strip().split(' ')
clean = []
for num in file_data:
if num != '':
clean.append(int(num))
reads[dev].append(clean[0])
writes[dev].append(clean[4])
print reads[dev]
print writes[dev]
time.sleep(1)
print "Device Read Write"
print "--------------------------------------"
for dev in check_devices:
clean_reads = []
reads[dev].reverse()
for test, result in enumerate(reads[dev]):
if test > 0:
clean_reads.append(float(reads[dev][test - 1] - result))
rops = int(math.ceil(sum(clean_reads) / len(clean_reads)))
clean_writes = []
writes[dev].reverse()
for test, result in enumerate(writes[dev]):
if test > 0:
clean_writes.append(float(writes[dev][test - 1] - result))
wops = int(math.ceil(sum(clean_writes) / len(clean_writes)))
print "%s %s %s" % (dev.ljust(13), repr(rops).ljust(11), repr(wops))
總結(jié)
以上就是Python獲得系統(tǒng)iops的全部內(nèi)容,希望這篇文章對(duì)大家學(xué)習(xí)和使用python能有一定的幫助,如果有疑問大家可以留言交流。
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元

