Added filtering and renaming of temperature sensors

This commit is contained in:
2024-05-27 18:26:41 +01:00
parent 9a92facb18
commit f668fbe30b

View File

@@ -67,7 +67,7 @@ struct SysInfo {
restart_needed: bool, restart_needed: bool,
} }
fn get_system_info(network_if_names: &Vec<String>, mount_names: &Vec<String>) -> SysInfo { fn get_system_info(network_if_names: &Vec<String>, mount_names: &Vec<String>, temperature_sensors: &Vec<Vec<String>>) -> SysInfo {
let mut sys = System::new_all(); let mut sys = System::new_all();
sys.refresh_all(); sys.refresh_all();
let cpu_load = System::load_average(); let cpu_load = System::load_average();
@@ -100,10 +100,22 @@ fn get_system_info(network_if_names: &Vec<String>, mount_names: &Vec<String>) ->
let components = Components::new_with_refreshed_list(); let components = Components::new_with_refreshed_list();
let mut components_context = Vec::new(); let mut components_context = Vec::new();
for component in &components { for component in &components {
components_context.push(ComponentInfo { let component_name = component.label().to_string();
name: component.label().to_string(),
temperature: component.temperature() as u8, for temperature_sensor in temperature_sensors {
}) if component_name == temperature_sensor[0] {
components_context.push(ComponentInfo {
name: temperature_sensor[1].clone(),
temperature: component.temperature() as u8,
});
}
}
if temperature_sensors.len() == 0 {
components_context.push(ComponentInfo {
name: component_name,
temperature: component.temperature() as u8,
});
}
} }
let mut network_ifs = Vec::new(); let mut network_ifs = Vec::new();
@@ -222,6 +234,7 @@ fn get_latest_twenty_blocks(json_rpc_url: &str, current_height: u64) -> Vec<Bloc
struct Config { struct Config {
network_interfaces: Vec<String>, network_interfaces: Vec<String>,
mount_names: Vec<String>, mount_names: Vec<String>,
temperature_sensors: Vec<Vec<String>>,
json_rpc_url: String, json_rpc_url: String,
} }
@@ -232,6 +245,7 @@ impl Default for Config {
Self { Self {
network_interfaces: Vec::new(), network_interfaces: Vec::new(),
mount_names: Vec::new(), mount_names: Vec::new(),
temperature_sensors: Vec::new(),
json_rpc_url: "http://127.0.0.1:18081/json_rpc".to_string(), json_rpc_url: "http://127.0.0.1:18081/json_rpc".to_string(),
} }
} }
@@ -241,7 +255,7 @@ impl Default for Config {
fn index(config: &State<Config>) -> Template { fn index(config: &State<Config>) -> Template {
let node_info = get_node_info(&config.json_rpc_url); let node_info = get_node_info(&config.json_rpc_url);
let latest_twenty_blocks = get_latest_twenty_blocks(&config.json_rpc_url, node_info.height); let latest_twenty_blocks = get_latest_twenty_blocks(&config.json_rpc_url, node_info.height);
let system_context = get_system_info(&config.network_interfaces, &config.mount_names); let system_context = get_system_info(&config.network_interfaces, &config.mount_names, &config.temperature_sensors);
let context = context! { let context = context! {
system: system_context, system: system_context,
node_info: node_info, node_info: node_info,