From e35a3d2b8dafe4eb94675c0e979fcdde471f3554 Mon Sep 17 00:00:00 2001 From: Arthur Date: Sun, 26 May 2024 17:20:34 +0100 Subject: [PATCH] Added most node_info information That I've found relevant or interesting at least --- Rocket.toml | 2 +- src/main.rs | 10 ++++++++-- src/monero_rpc.rs | 18 +++++++++--------- templates/index.html.tera | 36 ++++++++++++++++++++++-------------- 4 files changed, 40 insertions(+), 26 deletions(-) diff --git a/Rocket.toml b/Rocket.toml index 8688b82..baec26d 100644 --- a/Rocket.toml +++ b/Rocket.toml @@ -1,3 +1,3 @@ [default] template_dir = "templates" -#address = "0.0.0.0" +address = "0.0.0.0" diff --git a/src/main.rs b/src/main.rs index 159e902..c198ace 100644 --- a/src/main.rs +++ b/src/main.rs @@ -129,12 +129,18 @@ fn get_node_info() -> NodeInfoInner { let node_info = task::block_in_place(move || { let client = reqwest::blocking::Client::new(); // TODO: Properly handle this unwrap - half the point of this is to capture - // when the node is down + // when the node is down - don't want it crashing when let resp = client.post("http://127.0.0.1:18081/json_rpc").json(&map).send().unwrap(); // TODO: Figure out _why_ this part needs to be inside this closure resp.json::() }).unwrap(); - node_info.result + let mut node_info = node_info.result; + // TODO: Put this into a Serialize method + let approx_uptime = node_info.adjusted_time - node_info.start_time; + 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 } #[get("/")] diff --git a/src/monero_rpc.rs b/src/monero_rpc.rs index 57275e9..c8c25be 100644 --- a/src/monero_rpc.rs +++ b/src/monero_rpc.rs @@ -9,7 +9,7 @@ pub struct NodeInfo { #[derive(Serialize, Deserialize, Debug)] pub struct NodeInfoInner { - adjusted_time: u64, + pub adjusted_time: u64, alt_blocks_count: u64, block_size_limit: u64, block_size_median: u64, @@ -20,10 +20,10 @@ pub struct NodeInfoInner { credits: u64, cumulative_difficulty: u64, cumulative_difficulty_top64: u64, - database_size: u64, + pub database_size: u64, difficulty: u64, difficulty_top64: u64, - free_space: u64, + pub free_space: u64, grey_peerlist_size: u64, height: u64, height_without_bootstrap: u64, @@ -35,7 +35,7 @@ pub struct NodeInfoInner { restricted: bool, rpc_connections_count: u64, stagenet: bool, - start_time: u64, + pub start_time: u64, status: String, synchronized: bool, target: u64, @@ -53,13 +53,13 @@ pub struct NodeInfoInner { wide_cumulative_difficulty: String, wide_difficulty: String, #[serde(skip_deserializing, default = "none")] - time_up_pretty: Option, + pub time_up_pretty: String, #[serde(skip_deserializing, default = "none")] - space_left_pretty: Option, + pub free_space_pretty: String, #[serde(skip_deserializing, default = "none")] - db_size_pretty: Option, + pub db_size_pretty: String, } -fn none() -> Option { - None +fn none() -> String { + "".to_string() } diff --git a/templates/index.html.tera b/templates/index.html.tera index 5aeab9f..52cd063 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -24,6 +24,7 @@ } .warning { color: yellow; + } .node_data { font-family: monospace, monospace; } @@ -77,31 +78,38 @@ {% endfor %}

+

Monerod Status

-
-
+
+
{% if node_info.synchronized %}

Synchronised to {{ node_info.nettype }}

{% else %}

Synchronising to {{ node_info.nettype }}

{% endif %} -

Running version {{ node_info.version }} +

Running version {{ node_info.version }} {% if node_info.update_available %} -

Which can be updated

+ Which can be updated {% endif %} +

+

Monerod Time Up: {{ node_info.time_up_pretty }}

-
-

Txs in pool: {{ node_info.tx_pool_size }}

-

Total Txs: {{ node_info.tx_count }}

+
+

Txs in pool: {{ node_info.tx_pool_size }}

+

Total Txs: {{ node_info.tx_count }}

-
-

Incoming Connections: {{ node_info.incoming_connections_count }}

-

Outgoing Connections: {{ node_info.outgoing_connections_count }}

-

RPC Connections: {{ node_info.rpc_connections_count }}

+
+

Incoming Connections: {{ node_info.incoming_connections_count }}

+

Outgoing Connections: {{ node_info.outgoing_connections_count }}

+

RPC Connections: {{ node_info.rpc_connections_count }}

-
-

Blockheight: {{ node_info.height }}

-

Latest block hash: {{ node_info.top_block_hash }}

+
+

Blockheight: {{ node_info.height }}

+

Latest block hash: {{ node_info.top_block_hash }}

+
+
+

Free Space: {{ node_info.free_space_pretty }}

+

Database Size: {{ node_info.db_size_pretty }}