disk_io_counters() is broken on Linux 2.4 #767

Closed
giampaolo opened this Issue Feb 14, 2016 · 1 comment

Comments

Projects
None yet
1 participant
@giampaolo
Owner

giampaolo commented Feb 14, 2016

Because /proc/diskstats has a different format, as explained here:
https://www.kernel.org/doc/Documentation/iostats.txt
Right now we fail with:

    ret = psutil.disk_io_counters()
  File "/home/giampaolo/svn/psutil/psutil/__init__.py", line 1799, in disk_io_counters
    rawdict = _psplatform.disk_io_counters()
  File "/home/giampaolo/svn/psutil/psutil/_pslinux.py", line 833, in disk_io_counters
    wbytes, wtime) = map(int, fields[3:11])
ValueError: invalid literal for int() with base 10: 'sda'
@giampaolo

This comment has been minimized.

Show comment
Hide comment
@giampaolo

giampaolo Feb 14, 2016

Owner

It turns out the situation is even more confusing, and not currently properly handled by psutil parser.
The format of /proc/diskstats can have 3 variations. On Linux 2.4 each line has always 15 fields, e.g.:

3     0   8 hda 8 8 8 8 8 8 8 8 8 8 8

On Linux 2.6+ each line usually has 14 fields, and the disk name is in another position, like this:

3    0   hda 8 8 8 8 8 8 8 8 8 8 8

...unless (Linux 2.6) the line refers to a partition instead of a disk, in which case the line has less fields (7):

3    1   hda1 8 8 8 8

See:
https://www.kernel.org/doc/Documentation/iostats.txt
https://bugs.launchpad.net/percona-toolkit/+bug/897029

Owner

giampaolo commented Feb 14, 2016

It turns out the situation is even more confusing, and not currently properly handled by psutil parser.
The format of /proc/diskstats can have 3 variations. On Linux 2.4 each line has always 15 fields, e.g.:

3     0   8 hda 8 8 8 8 8 8 8 8 8 8 8

On Linux 2.6+ each line usually has 14 fields, and the disk name is in another position, like this:

3    0   hda 8 8 8 8 8 8 8 8 8 8 8

...unless (Linux 2.6) the line refers to a partition instead of a disk, in which case the line has less fields (7):

3    1   hda1 8 8 8 8

See:
https://www.kernel.org/doc/Documentation/iostats.txt
https://bugs.launchpad.net/percona-toolkit/+bug/897029

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment