Python如何获取系统iops示例代码

yipeiwu_com5年前Python基础

iops简介

iops主要用在数据方面,这个指标是数据库性能评定的一个重要参考,iops的是每秒进行读写(I/O)操作的次数,主要看随机访问的性能,一般为了iops增高都要依靠磁盘阵列,实际线上的数据库基本都是raid10的配置,raid5在实际生产环境中如果压力上来是抗不住的,当然也要开具体业务压力情况,如果是用物理机就要看iops在实际中能跑到多少值,现在云也普遍了,如果你用的RDS云数据库,这个iops是可以根据业务情况自己选择的,基本是个参数,可以按需进行修改,当然数值越大费用越高

python获得系统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))

总结

以上就是Python获得系统iops的全部内容,希望这篇文章对大家学习和使用python能有一定的帮助,如果有疑问大家可以留言交流。

相关文章

Python模块结构与布局操作方法实例分析

本文实例讲述了Python模块结构与布局操作方法。分享给大家供大家参考,具体如下: #coding=utf8 #起始行 #!/usr/bin/env python #模块文档 '''...

用实例详解Python中的Django框架中prefetch_related()函数对数据库查询的优化

用实例详解Python中的Django框架中prefetch_related()函数对数据库查询的优化

实例的背景说明 假定一个个人信息系统,需要记录系统中各个人的故乡、居住地、以及到过的城市。数据库设计如下: Models.py 内容如下:   from django...

pytorch的batch normalize使用详解

torch.nn.BatchNorm1d() 1、BatchNorm1d(num_features, eps = 1e-05, momentum=0.1, affine=True) 对于...

Python Grid使用和布局详解

Python Grid使用和布局详解

本文实例为大家分享了Python Grid使用和布局的具体代码,供大家参考,具体内容如下 #!/usr/bin/env python import vtk # 这个示例主要用...

win10系统中安装scrapy-1.1

win10系统中安装scrapy-1.1

0.环境说明 win10 64bit,电脑也是64bit的处理器,电脑装有vs2010 64bit,但是为了保险起见,只试验了32位的安装,等有时间了,再试下64位的安装。如无特殊说明,...