Skip to content

Commit

Permalink
Merge pull request #3 from navidys/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
navidys authored Jul 13, 2024
2 parents d0027bc + 2d8eadd commit d5d4562
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 260 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ use procsys::sysfs::class_watchdog;
let watchdog_devices = class_watchdog::collect();
for wdev in &watchdog_devices {
println!("name: {}", wdev.name());
println!("boot status: {}", wdev.boot_status().unwrap_or_default());
println!("timeout: {}", wdev.timeout().unwrap_or_default());
println!("min_timeout: {}", wdev.min_timeout().unwrap_or_default());
println!("max_timeout: {}", wdev.max_timeout().unwrap_or_default());
println!("name: {}", wdev.name);
println!("boot status: {}", wdev.boot_status.unwrap_or_default());
println!("timeout: {}", wdev.timeout.unwrap_or_default());
println!("min_timeout: {}", wdev.min_timeout.unwrap_or_default());
println!("max_timeout: {}", wdev.max_timeout.unwrap_or_default());
}
// print all watchdog devices information in json output
Expand Down
6 changes: 3 additions & 3 deletions examples/clocksource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ fn main() {
let clocksources = sysfs::clocksource::collect();

for clock_src in &clocksources {
println!("name: {}", clock_src.name());
println!("name: {}", clock_src.name);
println!(
"available clocksource: {}",
clock_src.available_clocksource().join(" "),
clock_src.available_clocksource.join(" "),
);
println!("current clocksource: {}", clock_src.current_clocksource());
println!("current clocksource: {}", clock_src.current_clocksource);
}

// print all clocksources information in json output
Expand Down
10 changes: 0 additions & 10 deletions examples/dmi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ fn main() {

let dmi_info = sysfs::class_dmi::collect();

println!(
"bios date: {}",
dmi_info.bios_date().to_owned().unwrap_or_default(),
);

println!(
"bios release: {}",
dmi_info.bios_release().to_owned().unwrap_or_default(),
);

// print all DMI information in json output
match serde_json::to_string_pretty(&dmi_info) {
Ok(output) => println!("{}", output),
Expand Down
8 changes: 4 additions & 4 deletions examples/thermal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ fn main() {
let thermal_devices = class_thermal::collect();

for tdev in &thermal_devices {
println!("name: {}", tdev.name());
println!("temperature: {}", tdev.temp());
println!("type: {}", tdev.zone_type());
println!("policy: {}", tdev.zone_type());
println!("name: {}", tdev.name);
println!("temperature: {}", tdev.temp);
println!("type: {}", tdev.zone_type);
println!("policy: {}", tdev.zone_type);
}

// print all thermal devices information in json output
Expand Down
10 changes: 5 additions & 5 deletions examples/watchdog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ fn main() {
let watchdog_devices = class_watchdog::collect();

for wdev in &watchdog_devices {
println!("name: {}", wdev.name());
println!("boot status: {}", wdev.boot_status().unwrap_or_default());
println!("timeout: {}", wdev.timeout().unwrap_or_default());
println!("min_timeout: {}", wdev.min_timeout().unwrap_or_default());
println!("max_timeout: {}", wdev.max_timeout().unwrap_or_default());
println!("name: {}", wdev.name);
println!("boot status: {}", wdev.boot_status.unwrap_or_default());
println!("timeout: {}", wdev.timeout.unwrap_or_default());
println!("min_timeout: {}", wdev.min_timeout.unwrap_or_default());
println!("max_timeout: {}", wdev.max_timeout.unwrap_or_default());
}

// print all watchdog devices information in json output
Expand Down
39 changes: 16 additions & 23 deletions src/sysfs/class_cooling.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::path::{Path, PathBuf};

use getset::Getters;
use serde::Serialize;
use walkdir::WalkDir;

Expand All @@ -24,29 +23,13 @@ impl CoolingInfo {
}
}

/// Cooling contains a cooling device information.
/// # Example
/// ```
/// use procsys::sysfs::class_cooling;
///
/// let cooling_devices = class_cooling::collect();
/// let json_output = serde_json::to_string_pretty(&cooling_devices).unwrap();
/// println!("{}", json_output);
///
/// ```
#[derive(Debug, Serialize, Clone, Getters)]
/// Cooling contains a cooling device information from files in /sys/class/thermal/cooling_device[0-9]*
#[derive(Debug, Serialize, Clone)]
pub struct Cooling {
#[getset(get = "pub")]
name: String,

#[getset(get = "pub")]
cooling_type: String,

#[getset(get = "pub")]
max_state: i64,

#[getset(get = "pub")]
cur_state: i64,
pub name: String,
pub cooling_type: String,
pub max_state: i64,
pub cur_state: i64,
}

impl Cooling {
Expand All @@ -60,6 +43,16 @@ impl Cooling {
}
}

/// collects cooling devices information
/// # Example
/// ```
/// use procsys::sysfs::class_cooling;
///
/// let cooling_devices = class_cooling::collect();
/// let json_output = serde_json::to_string_pretty(&cooling_devices).unwrap();
/// println!("{}", json_output);
///
/// ```
pub fn collect() -> Vec<Cooling> {
let mut cooling_devs = Vec::new();
let cooling_class_path = Path::new("/sys/class/thermal/");
Expand Down
115 changes: 35 additions & 80 deletions src/sysfs/class_dmi.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::{error::MetricError, utils};
use getset::Getters;
use serde::Serialize;
use std::path::Path;

Expand Down Expand Up @@ -55,85 +54,30 @@ impl DMIType {
}
}

/// The DMI contains the content of Desktop Management Interface.
/// # Example
/// ```
/// use procsys::sysfs::class_dmi;
///
/// let dmi_info = class_dmi::collect();
///
/// println!("bios date: {}", dmi_info.bios_date().to_owned().unwrap_or_default());
/// println!("board serial: {}", dmi_info.board_serial().to_owned().unwrap_or_default());
///
/// // print all dmi information in json format
/// let json_output = serde_json::to_string_pretty(&dmi_info).unwrap();
/// println!("{}", json_output);
///
/// ```
#[derive(Debug, Serialize, Clone, Getters)]
/// The DMI contains the content of Desktop Management Interface from files in in /sys/class/dmi/id
#[derive(Debug, Serialize, Clone)]
pub struct DMI {
#[getset(get = "pub")]
bios_date: Option<String>,

#[getset(get = "pub")]
bios_release: Option<String>,

#[getset(get = "pub")]
bios_vendor: Option<String>,

#[getset(get = "pub")]
bios_version: Option<String>,

#[getset(get = "pub")]
board_asset_tag: Option<String>,

#[getset(get = "pub")]
board_name: Option<String>,

#[getset(get = "pub")]
board_serial: Option<String>,

#[getset(get = "pub")]
board_vendor: Option<String>,

#[getset(get = "pub")]
board_version: Option<String>,

#[getset(get = "pub")]
chassis_asset_tag: Option<String>,

#[getset(get = "pub")]
chassis_serial: Option<String>,

#[getset(get = "pub")]
chassis_type: Option<String>,

#[getset(get = "pub")]
chassis_vendor: Option<String>,

#[getset(get = "pub")]
chassis_version: Option<String>,

#[getset(get = "pub")]
product_family: Option<String>,

#[getset(get = "pub")]
product_name: Option<String>,

#[getset(get = "pub")]
product_serial: Option<String>,

#[getset(get = "pub")]
product_sku: Option<String>,

#[getset(get = "pub")]
product_uuid: Option<String>,

#[getset(get = "pub")]
product_version: Option<String>,

#[getset(get = "pub")]
system_vendor: Option<String>,
pub bios_date: Option<String>,
pub bios_release: Option<String>,
pub bios_vendor: Option<String>,
pub bios_version: Option<String>,
pub board_asset_tag: Option<String>,
pub board_name: Option<String>,
pub board_serial: Option<String>,
pub board_vendor: Option<String>,
pub board_version: Option<String>,
pub chassis_asset_tag: Option<String>,
pub chassis_serial: Option<String>,
pub chassis_type: Option<String>,
pub chassis_vendor: Option<String>,
pub chassis_version: Option<String>,
pub product_family: Option<String>,
pub product_name: Option<String>,
pub product_serial: Option<String>,
pub product_sku: Option<String>,
pub product_uuid: Option<String>,
pub product_version: Option<String>,
pub system_vendor: Option<String>,
}

impl DMI {
Expand Down Expand Up @@ -164,7 +108,18 @@ impl DMI {
}
}

/// attempts to collect dmi information.
/// attempts to collect dmi information
/// # Example
/// ```
/// use procsys::sysfs::class_dmi;
///
/// let dmi_info = class_dmi::collect();
///
/// // print all dmi information in json format
/// let json_output = serde_json::to_string_pretty(&dmi_info).unwrap();
/// println!("{}", json_output);
///
/// ```
pub fn collect() -> DMI {
let mut dmi = DMI::new();

Expand Down
65 changes: 27 additions & 38 deletions src/sysfs/class_thermal.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::path::{Path, PathBuf};

use getset::Getters;
use serde::Serialize;
use walkdir::WalkDir;

Expand Down Expand Up @@ -29,43 +28,14 @@ impl ThermalZoneInfo {
}

/// ThermalZone contains info from files in /sys/class/thermal/thermal_zoneX.
/// #Example
/// ```
/// use procsys::sysfs::class_thermal;
///
///let thermal_devices = class_thermal::collect();
///
/// for tdev in &thermal_devices {
/// println!("name: {}", tdev.name());
/// println!("temperature: {}", tdev.temp());
/// println!("type: {}", tdev.zone_type());
/// println!("policy: {}", tdev.zone_type());
/// }
///
/// // print all thermal devices information in json format
/// let json_output = serde_json::to_string_pretty(&thermal_devices).unwrap();
/// println!("{}", json_output);
///
/// ```
#[derive(Debug, Serialize, Clone, Getters)]
#[derive(Debug, Serialize, Clone)]
pub struct ThermalZone {
#[getset(get = "pub")]
name: String,

#[getset(get = "pub")]
zone_type: String,

#[getset(get = "pub")]
policy: String,

#[getset(get = "pub")]
temp: i64,

#[getset(get = "pub")]
mode: Option<bool>,

#[getset(get = "pub")]
passive: Option<i64>,
pub name: String,
pub zone_type: String,
pub policy: String,
pub temp: i64,
pub mode: Option<bool>,
pub passive: Option<u64>,
}

impl ThermalZone {
Expand All @@ -81,6 +51,25 @@ impl ThermalZone {
}
}

/// collects thermal devices information.
/// #Example
/// ```
/// use procsys::sysfs::class_thermal;
///
///let thermal_devices = class_thermal::collect();
///
/// for tdev in &thermal_devices {
/// println!("name: {}", tdev.name);
/// println!("temperature: {}", tdev.temp);
/// println!("type: {}", tdev.zone_type);
/// println!("policy: {}", tdev.zone_type);
/// }
///
/// // print all thermal devices information in json format
/// let json_output = serde_json::to_string_pretty(&thermal_devices).unwrap();
/// println!("{}", json_output);
///
/// ```
pub fn collect() -> Vec<ThermalZone> {
let mut thermal_zone_devices = Vec::new();
let thermal_zone_class_path = Path::new("/sys/class/thermal/");
Expand Down Expand Up @@ -121,7 +110,7 @@ pub fn collect() -> Vec<ThermalZone> {
}
ThermalZoneInfo::Passive => {
thermal_device.passive =
utils::collect_info_i64(&tdev_info_name, tdev_path.as_path());
utils::collect_info_u64(&tdev_info_name, tdev_path.as_path());
}
ThermalZoneInfo::Policy => {
if let Some(c) =
Expand Down
Loading

0 comments on commit d5d4562

Please sign in to comment.