Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion ferrix-lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
>
> **NOTE 2:** this crate is a part of [ferrix-app](https://crates.io/crates/ferrix-app) crate.

Crate to get information about PC's hardware and software. Only for Linux. Some features are requires `d-bus` and `systemd`. Supported features: get information about:
Crate to get information about PC's hardware and software. Only for Linux. Some features are requires `d-bus` and `systemd`. This crate can get information about:

- CPU (`/proc/cpuinfo`);
- RAM (`/proc/meminfo`) and swaps (`/proc/swaps`);
Expand Down Expand Up @@ -34,6 +34,38 @@ TODO:
- [ ] Get information about GUI (desktop environment, session type (Wayland or X.org), etc.);
- [ ] Backup and reset `gsettings` settins;

At this time, the API is stable, and changes between versions are very minor. All changes are made primarily to further the development of the FSM project (adding new data sources).

## Features

Now, `ferrix-lib` has a modular structure in which each module depends on a specific enabled feature. Since `ferrix-lib` is part of the [FSM](https://mskrasnov.github.io/fsm/) project by default, all features are enabled by default (`features.default`).

Features list:

- `battery`;
- `cpu`;
- `cpu_freq`;
- `desktop`;
- `dmi`;
- `drm`;
- `firmware`;
- `init` (DBus is needed);
- `mem`;
- `net`;
- `parts` (`glibc` is needed);
- `resources`;
- `soft`;
- `sys`;
- `vulnerabilities`;

Using `ferrix-lib` with specific features:

```bash
cargo add ferrix-lib \
--no-default-features \
--features=feature1,feature2,...,featuren
```

## License

`ferrix-lib` is distributed under the GNU GPL v3 license.
10 changes: 10 additions & 0 deletions ferrix-lib/src/battery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
*/

//! Get information about notebook's battery
//!
//! ## Example
//! ```no-test
//! use ferrix_lib::battery::BatInfo;
//! use ferrix_lib::traits::ToJson;
//!
//! let bat = BatInfo::new().unwrap();
//! let bat_json = bat.to_json().unwrap();
//! dbg!(bat_json);
//! ```

use anyhow::Result;
use serde::{Deserialize, Serialize};
Expand Down
16 changes: 16 additions & 0 deletions ferrix-lib/src/cpu_freq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
*/

//! Get information about CPU frequency
//!
//! ## Example
//! ```no-test
//! use ferrix_lib::cpu_freq::CpuFreq;
//!
//! let freqs = CpuFreq::new().unwrap();
//! dbg!(&freqs.policy);
//! ```

use anyhow::{Result, anyhow};
use serde::{Deserialize, Serialize};
Expand All @@ -31,9 +39,15 @@ use std::{

use crate::traits::ToJson;

/// Information about power management and frequencies
/// for the processors installed in the PC
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct CpuFreq {
/// Information on power and frequency management
/// for each processor core/thread
pub policy: Vec<Policy>,

/// Does the processor support Turbo Boost technology?
pub boost: Option<bool>,
}

Expand Down Expand Up @@ -68,6 +82,8 @@ impl CpuFreq {

impl ToJson for CpuFreq {}

/// Information about power management and the frequency
/// of a specific core/thread
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
pub struct Policy {
/// Maximum frequency from the BIOS
Expand Down
5 changes: 5 additions & 0 deletions ferrix-lib/src/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ use std::{env, fs, path::Path, process::Command};
/// Session info (desktop, window manager)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SessionInfo {
/// Desktop environment name
pub desktop: Option<String>,

/// DE version
pub desktop_ver: Option<String>,

/// Window manager/compositor name
pub window_manager: Option<String>,
}

Expand Down
10 changes: 10 additions & 0 deletions ferrix-lib/src/firmware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
*/

//! Get firmware settings (only for modern systems with UEFI)
//!
//! > **Note:** you need to be `root` for get this information.
//!
//! ## Example
//! ```no-test
//! use ferrix_lib::firmware::Firmware;
//! let f = Firmware::new().unwrap();
//! println!("WMI Driver: {}", &f.driver_name);
//! dbg!(&f.attributes);
//! ```

use anyhow::{Result, anyhow};
use serde::{Deserialize, Serialize};
Expand Down
26 changes: 26 additions & 0 deletions ferrix-lib/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
*/

//! Get information about `systemd` services
//!
//! ## Usage
//! ```no-test
//! use ferrix_lib::init::SystemdServices;
//! use zbus::Connection;
//!
//! let mut conn = Connection::system().await.unwrap();
//! let systemd = SystemdServices::new_from_connection(&conn)
//! .await
//! .unwrap();
//!
//! dbg!(systemd);
//! ```

use anyhow::{Result, anyhow};
use libc::{CLOCK_MONOTONIC, CLOCK_REALTIME, clock_gettime, timespec};
Expand All @@ -37,6 +50,19 @@ pub struct SystemdServices {
}

impl SystemdServices {
/// Get current systemd services
///
/// ## Usage
/// ```no-test
/// use ferrix_lib::init::SystemdServices;
/// use zbus::Connection;
///
/// let mut conn = Connection::system().await.unwrap();
/// let sysd = SystemdServices::new_from_connection(&conn)
/// .await
/// .unwrap();
/// dbg!(&sysd.units);
/// ```
pub async fn new_from_connection(conn: &Connection) -> Result<Self> {
let mgr = ManagerProxy::new(conn).await?;
let mut units = vec![];
Expand Down
19 changes: 7 additions & 12 deletions ferrix-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,6 @@
//! hardware and software of a PC running Linux OS.
//!
//! ## Examples
//! Get all information about hardware and software (NOTE: needed
//! `root` permissions!):
//! ```no-test
//! use ferrix_lib::Ferrix;
//!
//! let data = Ferrix::new()?; // get all data
//!
//! let json_str = data.to_json()?; // get machine-readable JSON from this data
//! let pjson_str = data.to_json_pretty()?; // get human-readable JSON
//! let xml_str = data.to_xml()?; // get XML
//! ```
//!
//! Get information about CPU:
//! ```no-test
//! use ferrix_lib::cpu::Processors;
Expand All @@ -42,6 +30,13 @@
//! let json_str = data.to_json()?;
//! let pjson_str = data.to_json_pretty()?;
//! ```
//!
//! Get information about DMI tables (note: `root` permissions is needed!):
//! ```no-test
//! use ferrix_lib::dmi::DMITable;
//! let dmi = DMITable::new().unwrap();
//! dbg!(dmi);
//! ```

#[cfg(feature = "battery")]
pub mod battery;
Expand Down
Loading