Added disk filtering
Updated the Rocket.toml example
This commit is contained in:
@@ -2,3 +2,5 @@
|
|||||||
template_dir = "templates"
|
template_dir = "templates"
|
||||||
address = "0.0.0.0"
|
address = "0.0.0.0"
|
||||||
network_interface = [ "eth0", "eth1" ]
|
network_interface = [ "eth0", "eth1" ]
|
||||||
|
mount_names = [] # All disks and mount points
|
||||||
|
json_rpc_url = "http://127.0.0.1:18081/json_rpc"
|
||||||
|
|||||||
12
src/main.rs
12
src/main.rs
@@ -67,7 +67,7 @@ struct SysInfo {
|
|||||||
restart_needed: bool,
|
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();
|
let mut sys = System::new_all();
|
||||||
sys.refresh_all();
|
sys.refresh_all();
|
||||||
let cpu_load = System::load_average();
|
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 disks = Disks::new_with_refreshed_list();
|
||||||
let mut disks_context = Vec::new();
|
let mut disks_context = Vec::new();
|
||||||
for disk in disks.list() {
|
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 ts = disk.total_space();
|
||||||
let ass = disk.available_space();
|
let ass = disk.available_space();
|
||||||
disks_context.push(DiskInfo {
|
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: Byte::from(ass).to_string(),
|
||||||
available_space_bytes: ass,
|
available_space_bytes: ass,
|
||||||
consumed_space_bytes: ts - 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")]
|
#[serde(crate = "rocket::serde")]
|
||||||
struct Config {
|
struct Config {
|
||||||
network_interfaces: Vec<String>,
|
network_interfaces: Vec<String>,
|
||||||
|
mount_names: Vec<String>,
|
||||||
json_rpc_url: String,
|
json_rpc_url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,6 +231,7 @@ impl Default for Config {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
network_interfaces: Vec::new(),
|
network_interfaces: Vec::new(),
|
||||||
|
mount_names: 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(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -235,7 +241,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);
|
let system_context = get_system_info(&config.network_interfaces, &config.mount_names);
|
||||||
let context = context! {
|
let context = context! {
|
||||||
system: system_context,
|
system: system_context,
|
||||||
node_info: node_info,
|
node_info: node_info,
|
||||||
|
|||||||
Reference in New Issue
Block a user