iops简介
iops主要用在数据方面,这个指标是数据库性能评定的一个重要参考,iops的是每秒进行读写(I/O)操作的次数,主要看随机访问的性能,一般为了iops增高都要依靠磁盘阵列,实际线上的数据库基本都是raid10的配置,raid5在实际生产环境中如果压力上来是抗不住的,当然也要开具体业务压力情况,如果是用物理机就要看iops在实际中能跑到多少值,现在云也普遍了,如果你用的RDS云数据库,这个iops是可以根据业务情况自己选择的,基本是个参数,可以按需进行修改,当然数值越大费用越高
python获得系统iops代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#!/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))
|
总结
以上就是Python获得系统iops的全部内容,希望这篇文章对大家学习和使用python能有一定的帮助,如果有疑问大家可以留言交流。