I was researching which kernel counters where available for disks, when I bumped into sysfs. Sysfs exposes kernel data structures, the relationship between those structures is represented as directory structure
block/ bus/ class/ dev/ devices/ firmware/ net/ fs/
As I was interested in disk metrics I just drilled down to block, and found stats /sys/block/<disk>/stat
What: /sys/block/<disk>/stat Date: February 2008 Contact: Jerome MarchandDescription: The /sys/block/ /stat files displays the I/O statistics of disk . They contain 11 fields: == ============================================== 1 reads completed successfully 2 reads merged 3 sectors read 4 time spent reading (ms) 5 writes completed 6 writes merged 7 sectors written 8 time spent writing (ms) 9 I/Os currently in progress 10 time spent doing I/Os (ms) 11 weighted time spent doing I/Os (ms) 12 discards completed 13 discards merged 14 sectors discarded 15 time spent discarding (ms) 16 flush requests completed 17 time spent flushing (ms) == ============================================== For more details refer Documentation/admin-guide/iostats.rst
So just reading the stat file returns the counters:
neirac@alma nvme0n1]$ cat /sys/block/nvme0n1/stat 13534 11 683573 3185 14941 17536 2731548 58278 0 14339 61464 0 0 0 0 0 0
References