Added filtering and renaming of temperature sensors
This commit is contained in:
22
src/main.rs
22
src/main.rs
@@ -67,7 +67,7 @@ struct SysInfo {
|
||||
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();
|
||||
sys.refresh_all();
|
||||
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 mut components_context = Vec::new();
|
||||
for component in &components {
|
||||
let component_name = component.label().to_string();
|
||||
|
||||
for temperature_sensor in temperature_sensors {
|
||||
if component_name == temperature_sensor[0] {
|
||||
components_context.push(ComponentInfo {
|
||||
name: component.label().to_string(),
|
||||
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();
|
||||
@@ -222,6 +234,7 @@ fn get_latest_twenty_blocks(json_rpc_url: &str, current_height: u64) -> Vec<Bloc
|
||||
struct Config {
|
||||
network_interfaces: Vec<String>,
|
||||
mount_names: Vec<String>,
|
||||
temperature_sensors: Vec<Vec<String>>,
|
||||
json_rpc_url: String,
|
||||
}
|
||||
|
||||
@@ -232,6 +245,7 @@ impl Default for Config {
|
||||
Self {
|
||||
network_interfaces: Vec::new(),
|
||||
mount_names: Vec::new(),
|
||||
temperature_sensors: Vec::new(),
|
||||
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 {
|
||||
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 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! {
|
||||
system: system_context,
|
||||
node_info: node_info,
|
||||
|
||||
Reference in New Issue
Block a user