Skip to content

Commit

Permalink
Use sysinfo over sys-info
Browse files Browse the repository at this point in the history
sysinfo has more features

Signed-off-by: Patrick José Pereira <[email protected]>
  • Loading branch information
patrickelectric authored and joaoantoniocardoso committed Nov 29, 2023
1 parent 14b88f8 commit 21ba985
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ serde_json = "1.0"
validator = { version = "0.16", features = ["derive"] }

## FINAL
sys-info = "0.9.1"
sysinfo = "0.29"
chrono = "0.4.31"
lazy_static = "1.4.0"
include_dir = "0.7.3"
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#[macro_use]
extern crate lazy_static;
extern crate paperclip;
extern crate sys_info;
extern crate tracing;

#[macro_use]
Expand Down
28 changes: 15 additions & 13 deletions src/mavlink/sys_info.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use sysinfo::{DiskExt, System, SystemExt};
use tracing::*;

#[derive(Debug)]
Expand All @@ -14,24 +15,25 @@ pub fn sys_info() -> SysInfo {
let mut local_total_capacity = 0;
let mut local_available_capacity = 0;

match sys_info::disk_info() {
Ok(disk_info) => {
local_available_capacity = disk_info.free;
local_total_capacity = disk_info.total;
let mut system = System::new_all();
system.refresh_disks();

let main_disk = system
.disks()
.iter()
.find(|disk| disk.mount_point().as_os_str() == "/");
match main_disk {
Some(disk_info) => {
local_available_capacity = disk_info.available_space();
local_total_capacity = disk_info.total_space();
}

Err(error) => {
warn!("Failed to fetch disk info: {error:#?}.");
None => {
warn!("Failed to fetch main disk info.");
}
}

let boottime_ms = match sys_info::boottime() {
Ok(bootime) => bootime.tv_usec / 1000,
Err(error) => {
warn!("Failed to fetch boottime info: {error:#?}.");
0
}
};
let boottime_ms = system.boot_time() * 1000;

SysInfo {
time_boot_ms: boottime_ms as u32,
Expand Down

0 comments on commit 21ba985

Please sign in to comment.