From a5c501090b137eee0d60291be7093ea1f1afa6b8 Mon Sep 17 00:00:00 2001 From: Taylor Helsper Date: Tue, 31 May 2022 18:32:02 -0500 Subject: [PATCH] Add drive usage details --- rootfs/standard/var/www/mynode/settings.py | 4 +++ .../templates/includes/status_table.html | 26 ++++++++++++-- .../var/www/mynode/templates/settings.html | 20 +++++++++++ .../var/www/mynode/templates/status.html | 20 +++++++++++ .../var/www/mynode/thread_functions.py | 35 +++++++++++++++++++ 5 files changed, 103 insertions(+), 2 deletions(-) diff --git a/rootfs/standard/var/www/mynode/settings.py b/rootfs/standard/var/www/mynode/settings.py index f693e04a..71aa20f2 100644 --- a/rootfs/standard/var/www/mynode/settings.py +++ b/rootfs/standard/var/www/mynode/settings.py @@ -106,7 +106,9 @@ def page_settings(): "oom_error": has_oom_error(), "oom_info": get_oom_error_info(), "data_drive_usage": get_data_drive_usage(), + "data_drive_usage_details": Markup(get_data_drive_usage_details()), "os_drive_usage": get_os_drive_usage(), + "os_drive_usage_details": Markup(get_os_drive_usage_details()), "cpu_usage": get_cpu_usage(), "ram_usage": get_ram_usage(), "device_temp": get_device_temp(), @@ -299,7 +301,9 @@ def page_status(): "oom_error": has_oom_error(), "oom_info": get_oom_error_info(), "data_drive_usage": get_data_drive_usage(), + "data_drive_usage_details": Markup(get_data_drive_usage_details()), "os_drive_usage": get_os_drive_usage(), + "os_drive_usage_details": Markup(get_os_drive_usage_details()), "cpu_usage": get_cpu_usage(), "ram_usage": get_ram_usage(), "device_temp": get_device_temp(), diff --git a/rootfs/standard/var/www/mynode/templates/includes/status_table.html b/rootfs/standard/var/www/mynode/templates/includes/status_table.html index f73fa6d0..d6433d19 100644 --- a/rootfs/standard/var/www/mynode/templates/includes/status_table.html +++ b/rootfs/standard/var/www/mynode/templates/includes/status_table.html @@ -25,11 +25,33 @@ Data Disk Usage - {{data_drive_usage}} + + {{data_drive_usage}} + {% set data_drive_usage_num = data_drive_usage | replace("%", "") | int %} + {% if data_drive_usage_num >= 90 %} + + {% endif %} + + + OS Disk Usage - {{os_drive_usage}} + + {{os_drive_usage}} + {% set os_drive_usage_num = os_drive_usage | replace("%", "") | int %} + {% if os_drive_usage_num >= 90 %} + + {% endif %} + + + CPU diff --git a/rootfs/standard/var/www/mynode/templates/settings.html b/rootfs/standard/var/www/mynode/templates/settings.html index 725fd22b..14bebb1f 100644 --- a/rootfs/standard/var/www/mynode/templates/settings.html +++ b/rootfs/standard/var/www/mynode/templates/settings.html @@ -240,6 +240,26 @@ $("#product_key").show(); }); + $("#show_os_drive_usage_details").on("click", function() { + if($("#os_drive_usage_details").is(":visible")){ + $("#show_os_drive_usage_details").text("Show Details") + $("#os_drive_usage_details").hide(); + } else { + $("#show_os_drive_usage_details").text("Hide Details") + $("#os_drive_usage_details").show(); + } + }); + + $("#show_data_drive_usage_details").on("click", function() { + if($("#data_drive_usage_details").is(":visible")){ + $("#show_data_drive_usage_details").text("Show Details") + $("#data_drive_usage_details").hide(); + } else { + $("#show_data_drive_usage_details").text("Hide Details") + $("#data_drive_usage_details").show(); + } + }); + $("#show_mynode_changelog").on("click", function() { if (showChangelog) { diff --git a/rootfs/standard/var/www/mynode/templates/status.html b/rootfs/standard/var/www/mynode/templates/status.html index 45102304..f903ebca 100644 --- a/rootfs/standard/var/www/mynode/templates/status.html +++ b/rootfs/standard/var/www/mynode/templates/status.html @@ -25,6 +25,26 @@ $("#product_key").show(); }); + $("#show_os_drive_usage_details").on("click", function() { + if($("#os_drive_usage_details").is(":visible")){ + $("#show_os_drive_usage_details").text("Show Details") + $("#os_drive_usage_details").hide(); + } else { + $("#show_os_drive_usage_details").text("Hide Details") + $("#os_drive_usage_details").show(); + } + }); + + $("#show_data_drive_usage_details").on("click", function() { + if($("#data_drive_usage_details").is(":visible")){ + $("#show_data_drive_usage_details").text("Show Details") + $("#data_drive_usage_details").hide(); + } else { + $("#show_data_drive_usage_details").text("Hide Details") + $("#data_drive_usage_details").show(); + } + }); + $("#glances").on("click", function() { port="61208"; if (location.protocol == "https:") { diff --git a/rootfs/standard/var/www/mynode/thread_functions.py b/rootfs/standard/var/www/mynode/thread_functions.py index 5ae36372..cfbca112 100644 --- a/rootfs/standard/var/www/mynode/thread_functions.py +++ b/rootfs/standard/var/www/mynode/thread_functions.py @@ -19,6 +19,8 @@ has_updated_btc_info = False cpu_usage = "..." ram_usage = "..." swap_usage = "..." +os_drive_usage_details = "..." +data_drive_usage_details = "..." public_ip = "not_detected" # Getters @@ -28,13 +30,23 @@ def get_has_updated_btc_info(): def get_cpu_usage(): global cpu_usage return cpu_usage +def get_os_drive_usage_details(): + global os_drive_usage_details + return os_drive_usage_details +def get_data_drive_usage_details(): + global data_drive_usage_details + return data_drive_usage_details def get_public_ip(): global public_ip return public_ip # Updates device info every 60 seconds +device_info_call_count = 0 def update_device_info(): global cpu_usage + global os_drive_usage_details + global data_drive_usage_details + global device_info_call_count # Get drive info try: @@ -45,10 +57,33 @@ def update_device_info(): cpu_info = psutil.cpu_times_percent(interval=10.0, percpu=False) cpu_usage = "{:.1f}%".format(100.0 - cpu_info.idle) + # Update every 24 hrs + if device_info_call_count % 60*24 == 0: + os_drive_usage_details = "" + os_drive_usage_details += "" + os_drive_usage_details += "App Storage
" + os_drive_usage_details += "
" + run_linux_cmd("du -h -d1 /opt/mynode/", ignore_failure=True) + "

" + os_drive_usage_details += "User Storage
" + os_drive_usage_details += "
" + run_linux_cmd("du -h -d1 /home/", ignore_failure=True) + "

" + os_drive_usage_details += "Rust Toolchain Storage
" + if os.path.isdir("/root/.cargo/"): + os_drive_usage_details += "
" + run_linux_cmd("du -h -d1 /root/.cargo/", ignore_failure=True) + "

" + if os.path.isdir("/home/admin/.cargo/"): + os_drive_usage_details += "
" + run_linux_cmd("du -h -d1 /home/admin/.cargo/", ignore_failure=True) + "

" + os_drive_usage_details += "
" + + data_drive_usage_details = "" + data_drive_usage_details += "" + data_drive_usage_details += "Data Storage
" + data_drive_usage_details += "
" + run_linux_cmd("du -h -d1 /mnt/hdd/mynode/", ignore_failure=True) + "

" + data_drive_usage_details += "
" + except Exception as e: log_message("CAUGHT update_device_info EXCEPTION: " + str(e)) return + device_info_call_count = device_info_call_count + 1 + # Updates main bitcoin info every 30 seconds def update_bitcoin_main_info_thread(): global has_updated_btc_info