Added elided hash
And a couple of bits cleaned up
This commit is contained in:
47
src/main.rs
47
src/main.rs
@@ -1,9 +1,8 @@
|
||||
extern crate rocket;
|
||||
use readable::byte::Byte;
|
||||
use readable::up::UptimeFull;
|
||||
use readable::date::Date;
|
||||
use readable::time::{secs_to_clock, unix_clock};
|
||||
use reqwest;
|
||||
use readable::up::UptimeFull;
|
||||
use rocket::serde::{Deserialize, Serialize};
|
||||
use rocket::{fairing::AdHoc, get, launch, routes, State};
|
||||
use rocket_dyn_templates::{context, Template};
|
||||
@@ -14,7 +13,7 @@ use tokio::task;
|
||||
use vnstat_parse::Vnstat;
|
||||
|
||||
mod monero_rpc;
|
||||
use monero_rpc::{NodeInfoOuter, NodeInfo, BlockHeaderInfosOuter, BlockHeaderInfo};
|
||||
use monero_rpc::{BlockHeaderInfo, BlockHeaderInfosOuter, NodeInfo, NodeInfoOuter};
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
struct ComponentInfo {
|
||||
@@ -67,7 +66,11 @@ struct SysInfo {
|
||||
restart_needed: bool,
|
||||
}
|
||||
|
||||
fn get_system_info(network_if_names: &Vec<String>, mount_names: &Vec<String>, temperature_sensors: &Vec<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();
|
||||
@@ -167,11 +170,7 @@ fn get_node_info(json_rpc_url: &str) -> NodeInfo {
|
||||
let client = reqwest::blocking::Client::new();
|
||||
// TODO: Properly handle this unwrap - half the point of this is to capture
|
||||
// when the node is down - don't want it crashing when
|
||||
let resp = client
|
||||
.post(json_rpc_url)
|
||||
.json(&map)
|
||||
.send()
|
||||
.unwrap();
|
||||
let resp = client.post(json_rpc_url).json(&map).send().unwrap();
|
||||
resp.json::<NodeInfoOuter>()
|
||||
})
|
||||
.unwrap();
|
||||
@@ -181,6 +180,16 @@ fn get_node_info(json_rpc_url: &str) -> NodeInfo {
|
||||
node_info.time_up_pretty = UptimeFull::from(approx_uptime).to_string();
|
||||
node_info.db_size_pretty = Byte::from(node_info.database_size).to_string();
|
||||
node_info.free_space_pretty = Byte::from(node_info.free_space).to_string();
|
||||
node_info.top_block_hash_elided = format!(
|
||||
"{}...{}",
|
||||
node_info.top_block_hash.chars().take(8).collect::<String>(),
|
||||
node_info
|
||||
.top_block_hash
|
||||
.chars()
|
||||
.skip(56)
|
||||
.take(8)
|
||||
.collect::<String>()
|
||||
);
|
||||
node_info
|
||||
}
|
||||
|
||||
@@ -213,18 +222,18 @@ fn get_latest_twenty_blocks(json_rpc_url: &str, current_height: u64) -> Vec<Bloc
|
||||
let client = reqwest::blocking::Client::new();
|
||||
// TODO: Properly handle this unwrap - half the point of this is to capture
|
||||
// when the node is down - don't want it crashing when
|
||||
let resp = client
|
||||
.post(json_rpc_url)
|
||||
.json(&rpc_call)
|
||||
.send()
|
||||
.unwrap();
|
||||
let resp = client.post(json_rpc_url).json(&rpc_call).send().unwrap();
|
||||
resp.json::<BlockHeaderInfosOuter>()
|
||||
}).unwrap();
|
||||
})
|
||||
.unwrap();
|
||||
let mut latest_twenty_blocks = blocks.result.headers;
|
||||
for i in 0..latest_twenty_blocks.len() {
|
||||
let clock_time = secs_to_clock(unix_clock(latest_twenty_blocks[i].timestamp));
|
||||
let date = Date::from_unix(latest_twenty_blocks[i].timestamp).unwrap();
|
||||
latest_twenty_blocks[i].timestamp_pretty = format!("{} {:02}-{:02}-{:02}", date, clock_time.0, clock_time.1, clock_time.2);
|
||||
latest_twenty_blocks[i].timestamp_pretty = format!(
|
||||
"{} {:02}-{:02}-{:02}",
|
||||
date, clock_time.0, clock_time.1, clock_time.2
|
||||
);
|
||||
}
|
||||
latest_twenty_blocks
|
||||
}
|
||||
@@ -255,7 +264,11 @@ 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, &config.temperature_sensors);
|
||||
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,
|
||||
|
||||
@@ -41,7 +41,7 @@ pub struct NodeInfo {
|
||||
target: u64,
|
||||
target_height: u64,
|
||||
testnet: bool,
|
||||
top_block_hash: String,
|
||||
pub top_block_hash: String,
|
||||
top_hash: String,
|
||||
tx_count: u64,
|
||||
tx_pool_size: u64,
|
||||
@@ -58,6 +58,8 @@ pub struct NodeInfo {
|
||||
pub free_space_pretty: String,
|
||||
#[serde(skip_deserializing, default = "none")]
|
||||
pub db_size_pretty: String,
|
||||
#[serde(skip_deserializing, default = "none")]
|
||||
pub top_block_hash_elided: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
@@ -101,10 +103,9 @@ pub struct BlockHeaderInfo {
|
||||
wide_cumulative_difficulty: String,
|
||||
wide_difficulty: String,
|
||||
#[serde(skip_deserializing, default = "none")]
|
||||
pub timestamp_pretty: String
|
||||
pub timestamp_pretty: String,
|
||||
}
|
||||
|
||||
|
||||
fn none() -> String {
|
||||
"".to_string()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user