Last active
September 9, 2024 02:21
-
-
Save yinheli/e636d9927f4ed71d3af6bd2dbabf356f to your computer and use it in GitHub Desktop.
My mini desk PC, state
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SMART Information for /dev/nvme0n1 | |
-------------------------------------------------- | |
| Metric | Value | | |
| -------------------- | ------------------------- | | |
| Temperature | 46 | | |
| Data Written | 4.38 TB | | |
| Data Read | 30.9 TB | | |
| Power On Hours | 19 | | |
-------------------------------------------------- | |
Temperature Sensors: 50, 51, 52, 53, 54, 55, 56, 57 | |
Average Temp: 53.5°C, Max Temp: 57°C | |
Sensors Information | |
-------------------------------------------------- | |
| Metric | Value | | |
| -------------------- | ------------------------- | | |
| CPU Temperature | 42.9°C | | |
| GPU Temperature | 39.0°C | | |
| NVMe Temperature | 45.9°C | | |
| Fan2 Speed | 1618 RPM | | |
-------------------------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import subprocess | |
import re | |
def smart_info(dev: str): | |
cmd = f"smartctl -a {dev}" | |
output = subprocess.check_output(cmd, shell=True).decode('utf-8') | |
# Extract required information | |
temperature = re.search(r'Temperature:\s+(\d+) Celsius', output) | |
data_written = re.search(r'Data Units Written:\s+([\d,]+) \[([\d.]+) ([TGMK])B\]', output) | |
data_read = re.search(r'Data Units Read:\s+([\d,]+) \[([\d.]+) ([TGMK])B\]', output) | |
power_on_hours = re.search(r'Power On Hours:\s+(\d+)', output) | |
# Extract temperature sensors | |
temp_sensors = re.findall(r'Temperature Sensor \d+:\s+(\d+) Celsius', output) | |
# Prepare data for printing | |
temp = temperature.group(1) if temperature else 'N/A' | |
written = f"{data_written.group(2)} {data_written.group(3)}B" if data_written else 'N/A' | |
read = f"{data_read.group(2)} {data_read.group(3)}B" if data_read else 'N/A' | |
hours = power_on_hours.group(1) if power_on_hours else 'N/A' | |
# Print table | |
print(f"SMART Information for {dev}") | |
print("-" * 50) | |
print(f"| {'Metric':<20} | {'Value':<25} |") | |
print(f"| {'-'*20} | {'-'*25} |") | |
print(f"| {'Temperature':<20} | {temp:<25} |") | |
print(f"| {'Data Written':<20} | {written:<25} |") | |
print(f"| {'Data Read':<20} | {read:<25} |") | |
print(f"| {'Power On Hours':<20} | {hours:<25} |") | |
print("-" * 50) | |
# Print temperature sensors outside the table | |
if temp_sensors: | |
sensor_temps = [int(t) for t in temp_sensors] | |
avg_temp = sum(sensor_temps) / len(sensor_temps) | |
max_temp = max(sensor_temps) | |
print(f"Temperature Sensors: {', '.join(temp_sensors)}") | |
print(f"Average Temp: {avg_temp:.1f}°C, Max Temp: {max_temp}°C") | |
def sensors_info(): | |
cmd = "sensors" | |
output = subprocess.check_output(cmd, shell=True).decode('utf-8') | |
# Extract required information | |
cpu_temp = re.search(r'Tctl:\s+\+(\d+\.\d+)°C', output) | |
gpu_temp = re.search(r'edge:\s+\+(\d+\.\d+)°C', output) | |
nvme_temp = re.search(r'Composite:\s+\+(\d+\.\d+)°C', output) | |
fan2_speed = re.search(r'fan2:\s+(\d+) RPM', output) | |
# Prepare data for printing | |
cpu_temp = f"{cpu_temp.group(1)}°C" if cpu_temp else 'N/A' | |
gpu_temp = f"{gpu_temp.group(1)}°C" if gpu_temp else 'N/A' | |
nvme_temp = f"{nvme_temp.group(1)}°C" if nvme_temp else 'N/A' | |
fan2_speed = f"{fan2_speed.group(1)} RPM" if fan2_speed else 'N/A' | |
# Print table | |
print("Sensors Information") | |
print("-" * 50) | |
print(f"| {'Metric':<20} | {'Value':<25} |") | |
print(f"| {'-'*20} | {'-'*25} |") | |
print(f"| {'CPU Temperature':<20} | {cpu_temp:<25} |") | |
print(f"| {'GPU Temperature':<20} | {gpu_temp:<25} |") | |
print(f"| {'NVMe Temperature':<20} | {nvme_temp:<25} |") | |
print(f"| {'Fan2 Speed':<20} | {fan2_speed:<25} |") | |
print("-" * 50) | |
if __name__ == "__main__": | |
smart_info('/dev/nvme0n1') | |
print("\n") | |
sensors_info() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment