Struct Rsys

Source
pub struct Rsys(/* private fields */);
Expand description

Main interface that allows for os-agnostic api.

Implementations§

Source§

impl Rsys

Source

pub fn new() -> Self

Creates a new instance of Rsys

Source

pub fn hostname(&self) -> Result<String>

Returns a hostname.

  • linux
    • by reading /proc/sys/kernel/hostname
  • macos
    • by calling sysctl("kern.hostname")
  • windows
    • by calling win32 api GetComputerNameA
Source

pub fn uptime(&self) -> Result<u64>

Returns time since boot in seconds.

  • linux
    • by reading /proc/uptime
  • macos
    • by calling sysctl("kern.boottime")
  • windows
    • by calling win32 api GetTickCount64
Source

pub fn os(&self) -> String

Returns operating system. Reexported env::consts::OS for convenience.

Source

pub fn arch(&self) -> Result<String>

Returns cpu architecture.

  • linux and macos
    • by calling uname -m
  • windows
    • by calling win32 api GetSystemInfo
Source

pub fn cpu(&self) -> Result<String>

Returns a cpu model name.

  • linux
    • by reading /proc/cpuinfo
  • macos
    • by calling sysctl("machdep.cpu.brand_string")
Source

pub fn cpu_clock(&self) -> Result<f32>

Returns clock speed of cpu.

  • linux
    • by reading /proc/cpuinfo
  • macos
    • by calling sysctl("hw.cpufrequency")
Source

pub fn cpu_cores(&self) -> Result<u16>

Returns cpu cores.

  • linux
    • by reading /proc/cpuinfo
  • macos
    • by calling sysctl("hw.physicalcpu")
  • windows
    • by determining if cpu is hyperthreaded and calculating from logical cores.
Source

pub fn logical_cores(&self) -> Result<u16>

Returns logical cpu cores.

  • linux
    • by reading /proc/cpuinfo
  • macos
    • by calling sysctl("hw.logicalcpu")
  • windows
    • by calling win32 api GetSystemInfo
Source

pub fn memory_total(&self) -> Result<usize>

Returns total ram memory.

  • linux
    • by reading /proc/meminfo
  • macos
    • by calling sysctl("hw.memsize")
  • windows
    • by calling win32 api GlobalMemoryStatusEx
Source

pub fn memory_free(&self) -> Result<usize>

Returns free ram memory.

  • linux
    • by reading /proc/meminfo
Source

pub fn swap_total(&self) -> Result<usize>

Returns total swap size.

  • linux
    • by reading /proc/meminfo
  • macos
    • by calling sysctl("hw.swapusage")
  • windows
    • by calling win32 api GlobalMemoryStatusEx
Source

pub fn swap_free(&self) -> Result<usize>

Returns free swap size.

  • linux
    • by reading /proc/meminfo
  • macos
    • by calling sysctl("hw.swapusage")
  • windows
    • by calling win32 api GlobalMemoryStatusEx
Source

pub fn default_iface(&self) -> Result<String>

Returns a default internet interface.

  • linux
    • by calling route and determining default route
  • macos
    • by calling route get default
Source

pub fn ipv4(&self, iface: &str) -> Result<String>

Returns IP address version 4 of interface iface.

  • linux
    • by calling ip address show <iface>
  • macos
    • by calling ipconfig getifaddr <iface>
Source

pub fn ipv6(&self, iface: &str) -> Result<String>

Returns IP address version 6 of interface iface.

Source

pub fn mac(&self, iface: &str) -> Result<String>

Returns a MAC address of interface iface.

  • linux
    • by calling ip address show <iface>
Source

pub fn interfaces(&self) -> Result<Vec<String>>

Returns a vector of names of network interfaces that are available.

  • linux
    • by calling ip address show
Source

pub fn domainname(&self) -> Result<String>

Returns a domain name.

  • linux
    • by reading /proc/sys/kernel/domainname
  • windows
    • by calling win32 api NetWkstaGetInfo
Source

pub fn stat_block_device(&self, name: &str) -> Result<StorageDevice>

Parses a StorageDevice object from system. If the provided name doesn’t start with sd returns an error.

Source

pub fn stat_scsi_cdrom(&self, name: &str) -> Result<ScsiCdrom>

Parses a DeviceMapper object from system. If the provided name doesn’t start with dm returns an error.

Source

pub fn stat_device_mapper(&self, name: &str) -> Result<DeviceMapper>

Parses a ScsiCdrom object from system. If the provided name doesn’t start with sr returns an error.

Source

pub fn stat_multiple_device_storage( &self, name: &str, ) -> Result<MultipleDeviceStorage>

Parses a MultipleDeviceStorage object from system. If the provided name doesn’t start with md returns an error.

Source

pub fn block_size(&self, name: &str) -> Result<i64>

Returns block size of device in bytes

Source

pub fn memory(&self) -> Result<Memory>

Returns detailed information about memory

Source

pub fn stat_process(&self, pid: i32) -> Result<Process>

Returns detailed Process information parsed from /proc/[pid]/stat

Source

pub fn pids(&self) -> Result<Vec<i32>>

Returns a list of pids read from /proc

Source

pub fn processes(&self) -> Result<Processes>

Returns all processes currently seen in /proc parsed as Processes

Source

pub fn kernel_version(&self) -> Result<String>

Returns kernel version of host os.

Source

pub fn mounts(&self) -> Result<MountPoints>

Returns MountPoints read from /proc/mounts

Source

pub fn cores(&self) -> Result<Cores>

Returns virtual Cores of host cpu

Source

pub fn processor(&self) -> Result<Processor>

Returns a Processor object containing gathered information about host cpu

Source

pub fn ifaces(&self) -> Result<Interfaces>

Returns network interfaces on host os

Trait Implementations§

Source§

impl Default for Rsys

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Rsys

§

impl !RefUnwindSafe for Rsys

§

impl !Send for Rsys

§

impl !Sync for Rsys

§

impl Unpin for Rsys

§

impl !UnwindSafe for Rsys

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.