Python获取系统iops Python怎样获取系统iops代码实例

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Python获取系统iops Python怎样获取系统iops代码实例

  2021-03-22 我要评论
想了解Python怎样获取系统iops代码实例的相关内容吗,在本文为您仔细讲解Python获取系统iops的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:python获取系统盘,python,获取系统信息,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能有一定的帮助,如果有疑问大家可以留言交流。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们