-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnvme-usage.py
29 lines (24 loc) · 1.01 KB
/
nvme-usage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import subprocess
# Define the NVMe device
device = "/dev/nvme0"
# Get the data units written using the nvme command
try:
result = subprocess.run(["nvme", "smart-log", device], capture_output=True, text=True, check=True)
# Extract data_units_written from the output
for line in result.stdout.splitlines():
if "data_units_written" in line:
data_units_written = int(line.split()[2])
break
else:
raise ValueError("data_units_written not found in the output")
# Convert the data units written from 1MB units to GB and TB
gb_written = data_units_written * 1000 * 1000 / (1024**3) # GB
tb_written = data_units_written * 1000 * 1000 / (1024**4) # TB
# Display the results
print(f"\nTotal data written to {device}:")
print(f"Total GB Written: {gb_written:.3f} GB")
print(f"Total TB Written: {tb_written:.3f} TB\n")
except subprocess.CalledProcessError as e:
print(f"Error executing nvme command: {e}")
except ValueError as e:
print(f"Error: {e}")