Python library for monitoring / proc / diskstats?

I would like to track the loading of the IO system from a python program, referring to statistics similar to those presented in /proc/diskstatson linux (although obviously a cross-platform library would be great). Is there an existing python library that I could use to query IO statistics on disk in Linux?

+5
source share
4 answers

In case anyone tries to parse / proc / diskstats with Python, as Alex suggested:

def diskstats_parse(dev=None):
    file_path = '/proc/diskstats'
    result = {}

    # ref: http://lxr.osuosl.org/source/Documentation/iostats.txt
    columns_disk = ['m', 'mm', 'dev', 'reads', 'rd_mrg', 'rd_sectors',
                    'ms_reading', 'writes', 'wr_mrg', 'wr_sectors',
                    'ms_writing', 'cur_ios', 'ms_doing_io', 'ms_weighted']

    columns_partition = ['m', 'mm', 'dev', 'reads', 'rd_sectors', 'writes', 'wr_sectors']

    lines = open(file_path, 'r').readlines()
    for line in lines:
        if line == '': continue
        split = line.split()
        if len(split) == len(columns_disk):
            columns = columns_disk
        elif len(split) == len(columns_partition):
            columns = columns_partition
        else:
            # No match
            continue

        data = dict(zip(columns, split))
        if dev != None and dev != data['dev']:
            continue
        for key in data:
            if key != 'dev':
                data[key] = int(data[key])
        result[data['dev']] = data

    return result
+10
source

PSUtil provides several discs and fs features and is also cross-platform.

psutil.disk_io_counters(perdisk=True), :

read_count: number of reads
write_count: number of writes
read_bytes: number of bytes read
write_bytes: number of bytes written
read_time: time spent reading from disk (in milliseconds)
write_time: time spent writing to disk (in milliseconds)

/proc/diskstats ( Linux)

+5

/proc/diskstats, . sched, - ? Linux procfs , , ...!

+2

, Python "dstat" [1] Linux.

[1] - http://dag.wieers.com/home-made/dstat/

+1
source

All Articles