working with live dashboard

This commit is contained in:
2025-12-06 17:42:26 -08:00
parent 4096f7165c
commit 94c31f4be3
7 changed files with 168 additions and 84 deletions

View File

@ -65,7 +65,7 @@ def get_host_stats(as_json=False):
cpu_temp = run_command(cpu_temp_command, zero_only=True)
cpu_temp_stripped = re.sub(r'\u00b0C', '', cpu_temp)
cpu_temp_fixed = f"{cpu_temp_stripped} C"
ip_address_command = "ip -o -4 ad | grep -e eth -e tun | awk '{print $2\": \" $4}'"
ip_address_command = "ip -o -4 ad | grep -v -e docker -e 127.0.0.1 | awk '{print $2\": \" $4}'"
ip_addresses = run_command(ip_address_command, zero_only=True)
time_now_command = "date +%r"
time_now = run_command(time_now_command, zero_only=True)
@ -79,6 +79,19 @@ def get_host_stats(as_json=False):
"ip_addresses": ip_addresses,
"time": time_now
}]
if check_for_battery():
battery_level_command = "acpi | grep Battery | awk {print'$3 \" \" $4'}"
battery_level = run_command(battery_level_command, zero_only=True)
stats = [{
"memory_total": total_memory,
"memory_used": used_memory,
"memory_free": free_memory,
"cpu_load": cpu_load,
"cpu_temp": cpu_temp_fixed,
"ip_addresses": ip_addresses,
"battery_level": battery_level,
"time": time_now
}]
if debug_output:
print("=== Current Host Stats ===")
print(json.dumps(stats, indent=2))
@ -192,7 +205,10 @@ def run_command(cmd, zero_only=False):
# Split the output into lines and store it in an array
output_lines = [line for line in output.split('\n') if line]
# Return result
return output_lines[0] if zero_only else output_lines
try:
return output_lines[0] if zero_only else output_lines
except:
return output_lines
# Function to return all drive records in database
def get_all_drive_records(as_json=True):
@ -234,6 +250,14 @@ def check_serial_exists(serial):
print(serial_check)
return bool(query_db(serial_check))
def check_for_battery():
battery_check_command = "acpi | grep Battery | awk {print'$1'}"
battery_check = run_command(battery_check_command, zero_only=True)
if battery_check == 'Battery':
return True
else:
return False
####################################################
### Flask Routes
####################################################