Skip to content

Commit

Permalink
Make use of legacy functions as fallback for sysinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user committed Sep 26, 2024
1 parent 01a9a31 commit 2d885bf
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 28 deletions.
17 changes: 0 additions & 17 deletions src/deprecated/mod.rs

This file was deleted.

4 changes: 2 additions & 2 deletions src/deprecated/cpu_brand.rs → src/legacy/cpu_brand.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fs::File;
use std::io::{self, BufRead};

use crate::deprecated::helper::run_command;
use crate::legacy::helper::run_command;

/// Function to get processor information.
///
Expand Down Expand Up @@ -81,7 +81,7 @@ fn get_processor_info_windows(lib_path: &str) -> Result<String, &'static str> {
pub fn get_name() -> Option<String> {
let operating_system = std::env::consts::OS;
let result = match operating_system {
"darwin" => get_processor_info_darwin("/usr/sbin/sysctl"),
"macos" => get_processor_info_darwin("/usr/sbin/sysctl"),
"linux" => get_processor_info_linux("/proc/cpuinfo"),
"windows" => get_processor_info_windows("C:\\Windows\\System32\\wbem\\wmic.exe"),
_ => {
Expand Down
2 changes: 1 addition & 1 deletion src/deprecated/disks.rs → src/legacy/disks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::str;
use regex::Regex;
use serde_json::Value;

use crate::deprecated::helper::{run_command, size_converter};
use crate::legacy::helper::{run_command, size_converter};

/// Function to parse size string for Linux.
///
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions src/legacy/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/// This module contains functions that gathers CPU brand information.
pub mod cpu_brand;
/// This module contains disk related functions.
pub mod disks;
/// Helper for legacy functions.
pub mod helper;
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ mod squire;
mod templates;
/// Module for functions related to system resources.
mod resources;
/// Module for deprecated (but still useful for reference) functions
mod deprecated;
/// Module for legacy (but still useful for reference) functions
mod legacy;

/// Contains entrypoint and initializer settings to trigger the asynchronous `HTTPServer`
///
Expand Down
11 changes: 8 additions & 3 deletions src/resources/info.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{resources, squire};
use crate::{resources, squire, legacy};
use chrono::Utc;
use std::collections::HashMap;
use std::collections::HashSet;
Expand Down Expand Up @@ -56,8 +56,13 @@ fn get_cpu_brand(sys: &System) -> String {
cpu_brands.insert(cpu.brand().to_string());
}
if cpu_brands.is_empty() {
log::error!("Unable to get brand information for all {} CPUs", cpus.len());
return "Unknown".to_string()
log::warn!("Unable to get brand information for all {} CPUs", cpus.len());
let legacy_cpu_brand_name = legacy::cpu_brand::get_name();
return if legacy_cpu_brand_name.is_some() {
legacy_cpu_brand_name.unwrap()
} else {
"Unknown".to_string()
}
}
let mut cpu_brand_list: Vec<String> = cpu_brands.into_iter().collect();
cpu_brand_list.sort_by_key(|brand| brand.len());
Expand Down
12 changes: 9 additions & 3 deletions src/routes/monitor.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{constant, resources, routes, squire};
use crate::{constant, legacy, resources, routes, squire};
use actix_web::http::StatusCode;
use actix_web::{web, HttpRequest, HttpResponse};
use fernet::Fernet;
use sysinfo::Disks;
use std::sync::Arc;
use sysinfo::Disks;

/// Handles the monitor endpoint and rendering the appropriate HTML page.
///
Expand Down Expand Up @@ -39,7 +39,13 @@ pub async fn monitor(request: HttpRequest,
let disks = Disks::new_with_refreshed_list();

let sys_info_map = resources::info::get_sys_info(&disks);
let sys_info_disks = resources::info::get_disks(&disks);
let legacy_disk_info = legacy::disks::get_all_disks();

let sys_info_disks = if legacy_disk_info.is_empty() {
resources::info::get_disks(&disks)
} else {
legacy_disk_info
};

let sys_info_network = resources::network::get_network_info().await;

Expand Down

0 comments on commit 2d885bf

Please sign in to comment.