Skip to content

Commit

Permalink
Restructure disk information in the monitoring page
Browse files Browse the repository at this point in the history
Merge memory and swap info into system level information
Fix a bug in log statements for subprocess errors
  • Loading branch information
dormant-user committed Nov 28, 2024
1 parent 0db5f72 commit 6e5c728
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 41 deletions.
6 changes: 3 additions & 3 deletions pyninja/features/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def get_service_pid_linux(service_name: str) -> Optional[int]:
if line.startswith("MainPID="):
return int(line.split("=")[1].strip())
except subprocess.CalledProcessError as error:
LOGGER.error("{} - {}", error.returncode, error.stderr)
LOGGER.error("%s - %s", error.returncode, error.stderr)


def get_service_pid_macos(service_name: str) -> Optional[int]:
Expand All @@ -198,7 +198,7 @@ def get_service_pid_macos(service_name: str) -> Optional[int]:
if service_name in line:
return int(line.split()[0]) # Assuming PID is the first column
except subprocess.CalledProcessError as error:
LOGGER.error("{} - {}", error.returncode, error.stderr)
LOGGER.error("%s - %s", error.returncode, error.stderr)


def get_service_pid_windows(service_name: str) -> Optional[int]:
Expand All @@ -217,4 +217,4 @@ def get_service_pid_windows(service_name: str) -> Optional[int]:
if "PID" in line:
return int(line.split(":")[1].strip())
except subprocess.CalledProcessError as error:
LOGGER.error("{} - {}", error.returncode, error.stderr)
LOGGER.error("%s - %s", error.returncode, error.stderr)
23 changes: 8 additions & 15 deletions pyninja/monitor/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
import platform
import re
import shutil
import subprocess
import time
from datetime import timedelta
Expand Down Expand Up @@ -36,28 +35,25 @@ def landing_page() -> Dict[str, Any]:
timedelta(seconds=time.time() - psutil.boot_time())
),
}
if processor_name := cpu.get_name():
LOGGER.info("Processor: %s", processor_name)
sys_info_basic["CPU"] = processor_name
if gpu_names := gpu.get_names():
LOGGER.info(gpu_names)
sys_info_basic["GPU"] = ", ".join(
[gpu_info.get("model") for gpu_info in gpu_names]
)
if processor_name := cpu.get_name():
LOGGER.info("Processor: %s", processor_name)
sys_info_basic["CPU"] = processor_name
sys_info_mem_storage = {
"Memory": squire.size_converter(psutil.virtual_memory().total),
"Disk": squire.size_converter(shutil.disk_usage("/").total),
}

sys_info_basic["Memory"] = squire.size_converter(psutil.virtual_memory().total)
if swap := psutil.swap_memory().total:
sys_info_mem_storage["Swap"] = squire.size_converter(swap)
sys_info_basic["Swap"] = squire.size_converter(swap)
sys_info_network = {
"Private IP address": squire.private_ip_address(),
"Public IP address": squire.public_ip_address(),
}
return dict(
logout="/logout",
sys_info_basic=dict(sorted(sys_info_basic.items())),
sys_info_mem_storage=dict(sorted(sys_info_mem_storage.items())),
sys_info_basic=sys_info_basic,
sys_info_network=sys_info_network,
sys_info_disks=disks.get_all_disks(),
)
Expand Down Expand Up @@ -237,10 +233,7 @@ async def system_resources() -> Dict[str, dict]:
Dict[str, dict]:
Returns a nested dictionary.
"""
# todo: Redo disk charts entirely
# 1. Change "Disk Information" collapsible section similar to docker/service/process stats table
# 2. Remove "Disk" from "Memory and Storage" and move the remaining under "System Information"
# 3. Create a 4th section for disk usage - that includes PIE charts for all the attached disks
# todo: Create a 4th section for disk usage - that includes PIE charts for all the attached disks
system_metrics_task = asyncio.create_task(get_system_metrics())
docker_stats_task = asyncio.create_task(get_docker_stats())
service_stats_task = asyncio.create_task(
Expand Down
50 changes: 27 additions & 23 deletions pyninja/monitor/templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,23 @@
.center-container {
display: flex;
flex-direction: column;
justify-content: center;
margin-left: 40%;
text-align: left;
align-items: center; /* Keeps child elements centered horizontally */
text-align: left; /* Aligns text inside the container to the left */
margin: 0 auto; /* Centers the container horizontally */
}

.center-container details {
width: 40%;
text-align: center;
width: fit-content; /* Adapts to the content width */
max-width: 30%; /* Restricts the width to a maximum of 30% */
min-width: 25%; /* Restricts the width to a minimum of 25% */
text-align: left; /* Aligns text inside the details to the left */
margin: 0 auto; /* Ensures the details section stays centered */
box-sizing: border-box; /* Includes padding and borders in the width calculation */
}

.center-container summary {
text-align: center; /* Keeps the title aligned to the left */
cursor: pointer; /* Optional: Makes the summary text more interactive */
}

.collapsible-table {
Expand Down Expand Up @@ -317,19 +326,6 @@ <h1>PyNinja - System Monitor</h1>
</div>
</details>
<br>
<details>
<summary><strong>Memory and Storage</strong></summary>
<br>
<div class="collapsible-table">
{% for key, value in sys_info_mem_storage.items() %}
<div class="collapsible-table-row">
<div class="collapsible-table-cell"><strong>{{ key }}</strong></div>
<div class="collapsible-table-cell">{{ value }}</div>
</div>
{% endfor %}
</div>
</details>
<br>
<details>
<summary><strong>Network Information</strong></summary>
<br>
Expand All @@ -348,14 +344,22 @@ <h1>PyNinja - System Monitor</h1>
<summary><strong>Disk Information</strong></summary>
<br>
<div class="collapsible-table">
<!-- Header Row -->
<div class="collapsible-table-row">
{% if sys_info_disks|length > 0 %}
{% for key in sys_info_disks[0].keys() %}
<div class="collapsible-table-cell"><strong>{{ key }}</strong></div>
{% endfor %}
{% endif %}
</div>
<!-- Data Rows -->
{% for disk_info in sys_info_disks %}
{% for key, value in disk_info.items() %}
<div class="collapsible-table-row">
<div class="collapsible-table-cell"><strong>{{ key }}</strong></div>
{% for value in disk_info.values() %}
<div class="collapsible-table-cell">{{ value }}</div>
{% endfor %}
</div>
{% endfor %}
{% endfor %}
</div>
</details>
{% endif %}
Expand All @@ -376,7 +380,7 @@ <h3>Memory Usage</h3>
</div>
<p id="memoryUsageText">Memory: 0%</p>

{% if 'Swap' in sys_info_mem_storage.keys() %}
{% if 'Swap' in sys_info_basic.keys() %}
<h3>Swap Usage</h3>
<div class="progress">
<div id="swapUsage" class="progress-bar"></div>
Expand All @@ -402,7 +406,7 @@ <h5 id="memoryTotal"></h5>
<div class="chart-container">
<canvas id="memoryChart"></canvas>
</div>
{% if 'Swap' in sys_info_mem_storage.keys() %}
{% if 'Swap' in sys_info_basic.keys() %}
<h3>Swap Usage</h3>
<h5 id="swapTotal"></h5>
<div class="chart-container">
Expand Down

0 comments on commit 6e5c728

Please sign in to comment.