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;
|
extern crate rocket;
|
||||||
use readable::byte::Byte;
|
use readable::byte::Byte;
|
||||||
use readable::up::UptimeFull;
|
|
||||||
use readable::date::Date;
|
use readable::date::Date;
|
||||||
use readable::time::{secs_to_clock, unix_clock};
|
use readable::time::{secs_to_clock, unix_clock};
|
||||||
use reqwest;
|
use readable::up::UptimeFull;
|
||||||
use rocket::serde::{Deserialize, Serialize};
|
use rocket::serde::{Deserialize, Serialize};
|
||||||
use rocket::{fairing::AdHoc, get, launch, routes, State};
|
use rocket::{fairing::AdHoc, get, launch, routes, State};
|
||||||
use rocket_dyn_templates::{context, Template};
|
use rocket_dyn_templates::{context, Template};
|
||||||
@@ -14,7 +13,7 @@ use tokio::task;
|
|||||||
use vnstat_parse::Vnstat;
|
use vnstat_parse::Vnstat;
|
||||||
|
|
||||||
mod monero_rpc;
|
mod monero_rpc;
|
||||||
use monero_rpc::{NodeInfoOuter, NodeInfo, BlockHeaderInfosOuter, BlockHeaderInfo};
|
use monero_rpc::{BlockHeaderInfo, BlockHeaderInfosOuter, NodeInfo, NodeInfoOuter};
|
||||||
|
|
||||||
#[derive(Serialize, Debug)]
|
#[derive(Serialize, Debug)]
|
||||||
struct ComponentInfo {
|
struct ComponentInfo {
|
||||||
@@ -67,7 +66,11 @@ struct SysInfo {
|
|||||||
restart_needed: bool,
|
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();
|
let mut sys = System::new_all();
|
||||||
sys.refresh_all();
|
sys.refresh_all();
|
||||||
let cpu_load = System::load_average();
|
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();
|
let client = reqwest::blocking::Client::new();
|
||||||
// TODO: Properly handle this unwrap - half the point of this is to capture
|
// TODO: Properly handle this unwrap - half the point of this is to capture
|
||||||
// when the node is down - don't want it crashing when
|
// when the node is down - don't want it crashing when
|
||||||
let resp = client
|
let resp = client.post(json_rpc_url).json(&map).send().unwrap();
|
||||||
.post(json_rpc_url)
|
|
||||||
.json(&map)
|
|
||||||
.send()
|
|
||||||
.unwrap();
|
|
||||||
resp.json::<NodeInfoOuter>()
|
resp.json::<NodeInfoOuter>()
|
||||||
})
|
})
|
||||||
.unwrap();
|
.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.time_up_pretty = UptimeFull::from(approx_uptime).to_string();
|
||||||
node_info.db_size_pretty = Byte::from(node_info.database_size).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.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
|
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();
|
let client = reqwest::blocking::Client::new();
|
||||||
// TODO: Properly handle this unwrap - half the point of this is to capture
|
// TODO: Properly handle this unwrap - half the point of this is to capture
|
||||||
// when the node is down - don't want it crashing when
|
// when the node is down - don't want it crashing when
|
||||||
let resp = client
|
let resp = client.post(json_rpc_url).json(&rpc_call).send().unwrap();
|
||||||
.post(json_rpc_url)
|
|
||||||
.json(&rpc_call)
|
|
||||||
.send()
|
|
||||||
.unwrap();
|
|
||||||
resp.json::<BlockHeaderInfosOuter>()
|
resp.json::<BlockHeaderInfosOuter>()
|
||||||
}).unwrap();
|
})
|
||||||
|
.unwrap();
|
||||||
let mut latest_twenty_blocks = blocks.result.headers;
|
let mut latest_twenty_blocks = blocks.result.headers;
|
||||||
for i in 0..latest_twenty_blocks.len() {
|
for i in 0..latest_twenty_blocks.len() {
|
||||||
let clock_time = secs_to_clock(unix_clock(latest_twenty_blocks[i].timestamp));
|
let clock_time = secs_to_clock(unix_clock(latest_twenty_blocks[i].timestamp));
|
||||||
let date = Date::from_unix(latest_twenty_blocks[i].timestamp).unwrap();
|
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
|
latest_twenty_blocks
|
||||||
}
|
}
|
||||||
@@ -255,7 +264,11 @@ 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, &config.temperature_sensors);
|
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,
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ pub struct NodeInfo {
|
|||||||
target: u64,
|
target: u64,
|
||||||
target_height: u64,
|
target_height: u64,
|
||||||
testnet: bool,
|
testnet: bool,
|
||||||
top_block_hash: String,
|
pub top_block_hash: String,
|
||||||
top_hash: String,
|
top_hash: String,
|
||||||
tx_count: u64,
|
tx_count: u64,
|
||||||
tx_pool_size: u64,
|
tx_pool_size: u64,
|
||||||
@@ -58,6 +58,8 @@ pub struct NodeInfo {
|
|||||||
pub free_space_pretty: String,
|
pub free_space_pretty: String,
|
||||||
#[serde(skip_deserializing, default = "none")]
|
#[serde(skip_deserializing, default = "none")]
|
||||||
pub db_size_pretty: String,
|
pub db_size_pretty: String,
|
||||||
|
#[serde(skip_deserializing, default = "none")]
|
||||||
|
pub top_block_hash_elided: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
@@ -101,10 +103,9 @@ pub struct BlockHeaderInfo {
|
|||||||
wide_cumulative_difficulty: String,
|
wide_cumulative_difficulty: String,
|
||||||
wide_difficulty: String,
|
wide_difficulty: String,
|
||||||
#[serde(skip_deserializing, default = "none")]
|
#[serde(skip_deserializing, default = "none")]
|
||||||
pub timestamp_pretty: String
|
pub timestamp_pretty: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn none() -> String {
|
fn none() -> String {
|
||||||
"".to_string()
|
"".to_string()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,7 +124,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="infocard">
|
<div class="infocard">
|
||||||
<p>Blockheight: <span class="node_data">{{ node_info.height }}</span></p>
|
<p>Blockheight: <span class="node_data">{{ node_info.height }}</span></p>
|
||||||
<p>Latest block hash: <span class="node_data">{{ node_info.top_block_hash }}</span></p>
|
<p>Latest block hash: <span class="node_data">{{ node_info.top_block_hash_elided }}</span></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="infocard">
|
<div class="infocard">
|
||||||
<p>Free Space: <span class="node_data">{{ node_info.free_space_pretty }}</span></p>
|
<p>Free Space: <span class="node_data">{{ node_info.free_space_pretty }}</span></p>
|
||||||
@@ -138,7 +138,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">Height</th>
|
<th scope="col">Height</th>
|
||||||
<th scope="col">Size</th>
|
<th scope="col">Size (Bytes)</th>
|
||||||
<th scope="col">Transactions</th>
|
<th scope="col">Transactions</th>
|
||||||
<th scope="col">Timestamp (UTC)</th>
|
<th scope="col">Timestamp (UTC)</th>
|
||||||
<th scope="col">Hash</th>
|
<th scope="col">Hash</th>
|
||||||
|
|||||||
Reference in New Issue
Block a user