pub trait Platform {
Show 18 methods
// Required methods
fn new() -> Self;
fn cpu_load(&self) -> Result<DelayedMeasurement<Vec<CPULoad>>>;
fn load_average(&self) -> Result<LoadAverage>;
fn memory(&self) -> Result<Memory>;
fn swap(&self) -> Result<Swap>;
fn battery_life(&self) -> Result<BatteryLife>;
fn on_ac_power(&self) -> Result<bool>;
fn mounts(&self) -> Result<Vec<Filesystem>>;
fn block_device_statistics(
&self,
) -> Result<BTreeMap<String, BlockDeviceStats>>;
fn networks(&self) -> Result<BTreeMap<String, Network>>;
fn network_stats(&self, interface: &str) -> Result<NetworkStats>;
fn cpu_temp(&self) -> Result<f32>;
fn socket_stats(&self) -> Result<SocketStats>;
// Provided methods
fn cpu_load_aggregate(&self) -> Result<DelayedMeasurement<CPULoad>> { ... }
fn memory_and_swap(&self) -> Result<(Memory, Swap)> { ... }
fn uptime(&self) -> Result<Duration> { ... }
fn boot_time(&self) -> Result<OffsetDateTime> { ... }
fn mount_at<P: AsRef<Path>>(&self, path: P) -> Result<Filesystem> { ... }
}
Expand description
The Platform trait declares all the functions for getting system information.
NOTE: any impl MUST override one of uptime
or boot_time
.
Required Methods§
fn new() -> Self
Sourcefn cpu_load(&self) -> Result<DelayedMeasurement<Vec<CPULoad>>>
fn cpu_load(&self) -> Result<DelayedMeasurement<Vec<CPULoad>>>
Returns a delayed vector of CPU load statistics, one object per CPU (core).
You need to wait some time (about a second is good) before unwrapping the
DelayedMeasurement
with .done()
.
Sourcefn load_average(&self) -> Result<LoadAverage>
fn load_average(&self) -> Result<LoadAverage>
Returns a load average object.
Sourcefn battery_life(&self) -> Result<BatteryLife>
fn battery_life(&self) -> Result<BatteryLife>
Returns a battery life information object.
Sourcefn on_ac_power(&self) -> Result<bool>
fn on_ac_power(&self) -> Result<bool>
Returns whether AC power is plugged in.
Sourcefn mounts(&self) -> Result<Vec<Filesystem>>
fn mounts(&self) -> Result<Vec<Filesystem>>
Returns a vector of filesystem mount information objects.
Sourcefn block_device_statistics(&self) -> Result<BTreeMap<String, BlockDeviceStats>>
fn block_device_statistics(&self) -> Result<BTreeMap<String, BlockDeviceStats>>
Returns a map of block device statistics objects
Sourcefn networks(&self) -> Result<BTreeMap<String, Network>>
fn networks(&self) -> Result<BTreeMap<String, Network>>
Returns a map of network intefrace information objects.
It’s a map because most operating systems return an object per IP address, not per interface, and we’re doing deduplication and packing everything into one object per interface. You can use the .values() iterator if you need to iterate over all of them.
Sourcefn network_stats(&self, interface: &str) -> Result<NetworkStats>
fn network_stats(&self, interface: &str) -> Result<NetworkStats>
Returns statistics for a given interface (bytes/packets sent/received)
Sourcefn cpu_temp(&self) -> Result<f32>
fn cpu_temp(&self) -> Result<f32>
Returns the current CPU temperature in degrees Celsius.
Depending on the platform, this might be core 0, package, etc.
Sourcefn socket_stats(&self) -> Result<SocketStats>
fn socket_stats(&self) -> Result<SocketStats>
Returns information about the number of sockets in use
Provided Methods§
Sourcefn cpu_load_aggregate(&self) -> Result<DelayedMeasurement<CPULoad>>
fn cpu_load_aggregate(&self) -> Result<DelayedMeasurement<CPULoad>>
Returns a delayed CPU load statistics object, average over all CPUs (cores).
You need to wait some time (about a second is good) before unwrapping the
DelayedMeasurement
with .done()
.
Sourcefn memory_and_swap(&self) -> Result<(Memory, Swap)>
fn memory_and_swap(&self) -> Result<(Memory, Swap)>
Returns a swap and a memory information object. On some platforms this is more efficient than calling memory() and swap() separately If memory() or swap() are not implemented for a platform, this function will fail.
Sourcefn boot_time(&self) -> Result<OffsetDateTime>
fn boot_time(&self) -> Result<OffsetDateTime>
Returns the system boot time.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl Platform for PlatformImpl
An implementation of Platform
for Linux.
See Platform
for documentation.