Expand description

Read data from /proc/pressure/cpu, /proc/pressure/io, /proc/pressure/memory into the struct ProcPressure.

The processor of /proc/pressure takes the values from the files, and puts them in the struct ProcPressure. The files are cpu, io and memory as topics for pressure information. Inside the files, these are divided between some and full, meaning some tasks were affected or full, meaning all tasks were. For both some and full, the fields are a percentage of ? for 10 seconds, 60 seconds and 300 seconds, and total time spent waiting in microseconds. (the linux kernel is not consistent with time units, having jiffies, nanoseconds and milliseconds as units).

Documentation: https://docs.kernel.org/accounting/psi.html

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

use proc_sys_parser::pressure;

let proc_pressure = pressure::read();

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

Example output:

ProcPressure {
            psi: Some(
                Psi {
                    cpu_some_avg10: 1.0,
                    cpu_some_avg60: 2.0,
                    cpu_some_avg300: 3.0,
                    cpu_some_total: 373300065,
                    cpu_full_avg10: Some( 4.0 ),
                    cpu_full_avg60: Some( 5.0 ),
                    cpu_full_avg300: Some( 6.0 ),
                    cpu_full_total: Some( 0 ),
                    io_some_avg10: 7.0,
                    io_some_avg60: 8.0,
                    io_some_avg300: 9.0,
                    io_some_total: 55345502,
                    io_full_avg10: 10.0,
                    io_full_avg60: 11.0,
                    io_full_avg300: 12.0,
                    io_full_total: 53895423,
                    memory_some_avg10: 13.0,
                    memory_some_avg60: 14.0,
                    memory_some_avg300: 15.0,
                    memory_some_total: 5425111,
                    memory_full_avg10: 16.0,
                    memory_full_avg60: 17.0,
                    memory_full_avg300: 18.0,
                    memory_full_total: 5390695,
                }
            )
        }

(edited for readability)

If you want to change the path that is read for ProcPressure, which is /proc/pressure by default, use:

use proc_sys_parser::{pressure, pressure::Builder};

let proc_pressure = Builder::new().path("/myproc/pressure").read();

If the /proc/pressure entry is not available because it didn’t exist in that linux version, or because it’s not enabled The ProcPressure.psi entry is set to None.

Structs§

Functions§

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