summaryrefslogtreecommitdiff
path: root/misc/diskhealth
diff options
context:
space:
mode:
authorTimmy Keller <tjk@tjkeller.xyz>2024-09-02 08:44:38 -0500
committerTimmy Keller <tjk@tjkeller.xyz>2024-09-02 08:44:38 -0500
commita4373a898e65604f58299c947882f50294dd813f (patch)
treed07fd4eb4ccf9fef1fa8a73d1160b7174c7c317e /misc/diskhealth
parent988cadef2c2e51adbfa64da83ec7d25a8de3d924 (diff)
downloadscripts-a4373a898e65604f58299c947882f50294dd813f.tar.xz
scripts-a4373a898e65604f58299c947882f50294dd813f.zip
various changes over time
Diffstat (limited to 'misc/diskhealth')
-rwxr-xr-xmisc/diskhealth46
1 files changed, 46 insertions, 0 deletions
diff --git a/misc/diskhealth b/misc/diskhealth
new file mode 100755
index 0000000..5cce07b
--- /dev/null
+++ b/misc/diskhealth
@@ -0,0 +1,46 @@
+#!/usr/bin/env python3
+
+import subprocess
+import json
+from pprint import pprint
+
+smart_result = subprocess.run(["sudo", "smartctl", "-Aij", "/dev/sda"], capture_output=True, text=True)
+
+smart_result = json.loads(smart_result.stdout)
+
+sector_size = smart_result["logical_block_size"]
+
+from typing import NamedTuple
+class RawValue(NamedTuple):
+ value: int
+ string: str
+
+class Flags(NamedTuple):
+ value: int
+ string: str
+ prefailure: bool
+ updated_online: bool
+ performance: bool
+ error_rate: bool
+ event_count: bool
+ auto_keep: bool
+
+class SmartAttribute(NamedTuple):
+ id: int
+ name: str
+ value: int
+ worst: int
+ thresh: int
+ when_failed: str
+ flags: dict
+ raw: dict
+
+attributes = {}
+
+for attr in smart_result["ata_smart_attributes"]["table"]:
+ attr_l = SmartAttribute(**attr)
+ attributes[attr_l.id] = attr_l
+
+if 241 in attributes:
+ lbas_written = attributes[241].raw["value"]
+ print((lbas_written * sector_size) / 10**12)