Expand description

Read data from /proc/diskstats into the struct ProcDiskStats. /proc/diskstats contains statistics of both block devices and partitions inside the blockdevices. A more comprehensive view of block devices only can be found in the module Block.

The documentation for /proc/diskstats is found here: https://www.kernel.org/doc/Documentation/iostats.txt And here: https://www.kernel.org/doc/Documentation/ABI/testing/procfs-diskstats.

Here is an example obtaining the data from /proc/diskstats:

use proc_sys_parser::{diskstats, diskstats::ProcDiskStats};

let proc_diskstats = diskstats::read();

println!("{:#?}", proc_diskstats);

Example output:

        DiskStats {
            block_major: 253,
            block_minor: 0,
            device_name: "vda",
            reads_completed_success: 13534,
            reads_merged: 4237,
            reads_sectors: 1645451,
            reads_time_spent_ms: 3763,
            writes_completed_success: 10172,
            writes_merged: 10577,
            writes_sectors: 1730555,
            writes_time_spent_ms: 12701,
            ios_in_progress: 0,
            ios_time_spent_ms: 23356,
            ios_weighted_time_spent_ms: 18881,
            discards_completed_success: Some(
                7179,
            ),
            discards_merged: Some(
                0,
            ),
            discards_sectors: Some(
                89620507,
            ),
            discards_time_spent_ms: Some(
                396,
            ),
            flush_requests_completed_success: Some(
                3929,
            ),
            flush_requests_time_spent_ms: Some(
                2019,
            ),
        },

(edited for readability)

If you want to change the path and/or file that is read for ProcDiskStats, which is /proc/diskstats by default, use:

use proc_sys_parser::{diskstats, diskstats::{ProcDiskStats, Builder}};

let proc_diskstats = Builder::new().file_name("/myproc/diskstats").read();

Structs

Functions

  • The main function for building a ProcDiskStats struct with current data. This uses the Builder pattern, which allows settings such as the filename to specified.