summaryrefslogtreecommitdiff
path: root/misc/diskhealth
blob: 5cce07be0d22153f62fe24fbf72d151be879694f (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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)