Added disk filtering
Updated the Rocket.toml example
This commit is contained in:
12
src/main.rs
12
src/main.rs
@@ -67,7 +67,7 @@ struct SysInfo {
|
||||
restart_needed: bool,
|
||||
}
|
||||
|
||||
fn get_system_info(network_if_names: &Vec<String>) -> SysInfo {
|
||||
fn get_system_info(network_if_names: &Vec<String>, mount_names: &Vec<String>) -> SysInfo {
|
||||
let mut sys = System::new_all();
|
||||
sys.refresh_all();
|
||||
let cpu_load = System::load_average();
|
||||
@@ -80,6 +80,10 @@ fn get_system_info(network_if_names: &Vec<String>) -> SysInfo {
|
||||
let disks = Disks::new_with_refreshed_list();
|
||||
let mut disks_context = Vec::new();
|
||||
for disk in disks.list() {
|
||||
let mount_point = disk.mount_point().display().to_string();
|
||||
if mount_names.len() != 0 && !mount_names.contains(&mount_point) {
|
||||
continue;
|
||||
}
|
||||
let ts = disk.total_space();
|
||||
let ass = disk.available_space();
|
||||
disks_context.push(DiskInfo {
|
||||
@@ -89,7 +93,7 @@ fn get_system_info(network_if_names: &Vec<String>) -> SysInfo {
|
||||
available_space: Byte::from(ass).to_string(),
|
||||
available_space_bytes: ass,
|
||||
consumed_space_bytes: ts - ass,
|
||||
mount_point: disk.mount_point().display().to_string(),
|
||||
mount_point: mount_point,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -217,6 +221,7 @@ fn get_latest_twenty_blocks(json_rpc_url: &str, current_height: u64) -> Vec<Bloc
|
||||
#[serde(crate = "rocket::serde")]
|
||||
struct Config {
|
||||
network_interfaces: Vec<String>,
|
||||
mount_names: Vec<String>,
|
||||
json_rpc_url: String,
|
||||
}
|
||||
|
||||
@@ -226,6 +231,7 @@ impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
network_interfaces: Vec::new(),
|
||||
mount_names: Vec::new(),
|
||||
json_rpc_url: "http://127.0.0.1:18081/json_rpc".to_string(),
|
||||
}
|
||||
}
|
||||
@@ -235,7 +241,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);
|
||||
let system_context = get_system_info(&config.network_interfaces, &config.mount_names);
|
||||
let context = context! {
|
||||
system: system_context,
|
||||
node_info: node_info,
|
||||
|
||||
Reference in New Issue
Block a user