mirror of
https://codeberg.org/privacy1st/de-p1st-monitor
synced 2024-12-24 23:26:04 +01:00
feat: device by-id
This commit is contained in:
parent
d6b4af9d6a
commit
b2de44b26f
@ -2,11 +2,11 @@
|
||||
dir = /var/log/de-p1st-monitor/
|
||||
|
||||
[filesystem.1]
|
||||
; NVME
|
||||
; 256GB2
|
||||
mountpoint = /
|
||||
warn_if_above = 0.75
|
||||
[filesystem.2]
|
||||
; NVME
|
||||
; 256GB2
|
||||
mountpoint = /boot
|
||||
warn_if_above = 0.75
|
||||
[filesystem.3]
|
||||
@ -14,8 +14,8 @@ warn_if_above = 0.75
|
||||
uuid = c385a436-0288-486f-a2b9-c64c2db667e7
|
||||
warn_if_above = 0.66
|
||||
[filesystem.4]
|
||||
; 3TB1 and 3TB2
|
||||
uuid = a454430b-dee3-4b6b-8325-f7bdb9435ed1
|
||||
; 3TB1, 3TB2 and 4TB1
|
||||
uuid = 1f560eeb-a375-457b-84a6-93d771a5ba5f
|
||||
warn_if_above = 0.85
|
||||
unmounted_ok = true
|
||||
|
||||
@ -54,25 +54,28 @@ warn_if_above = 60
|
||||
network_interface = enp0s31f6
|
||||
|
||||
[drive.1]
|
||||
; NVME /dev/nvme0n1p3
|
||||
; TODO NVME 49 warn, 55 limit
|
||||
uuid = b8ef1da9-d76d-44b4-86d4-71c82c888b6f
|
||||
; NVMe 256GB2
|
||||
; TODO NVMe 49 warn, 55 limit
|
||||
id = nvme-WDC_PC_SN520_SDAPNUW-256G-1002_183873801941
|
||||
warn_if_above = 50
|
||||
[drive.2]
|
||||
; HDD 12TB1
|
||||
; TODO HDD 39 warn, 45 limit
|
||||
uuid = 68c349e8-5118-4773-9fd5-5dbad9acee4e
|
||||
id = ata-TOSHIBA_MG07ACA12TE_X1E0A0WKF95G
|
||||
warn_if_above = 40
|
||||
[drive.3]
|
||||
; HDD 3TB1
|
||||
uuid = 20d86155-30d4-404c-95e8-c701cfb16ca5
|
||||
id = ata-WDC_WD30EFRX-68EUZN0_WD-WCC4N1173157
|
||||
warn_if_above = 40
|
||||
[drive.4]
|
||||
; HDD 3TB2
|
||||
uuid = 4651c3f1-e4b8-45aa-a823-df762530a307
|
||||
id = ata-WDC_WD30EFRX-68EUZN0_WD-WMC4N0564095
|
||||
warn_if_above = 40
|
||||
; HDD 4TB1
|
||||
id = ata-WDC_WD40EFRX-68N32N0_WD-WCC7K0CPF0N1
|
||||
warn_if_above = 40
|
||||
|
||||
[sensor_script.1]
|
||||
cmd = ["digitemp_DS9097", "-q", "-c", "/home/yoda/.digitemprc", "-t", "0"]
|
||||
name = room-temp
|
||||
warn_if_above = 32
|
||||
; [sensor_script.1]
|
||||
; cmd = ["digitemp_DS9097", "-q", "-c", "/home/yoda/.digitemprc", "-t", "0"]
|
||||
; name = room-temp
|
||||
; warn_if_above = 32
|
||||
|
@ -79,11 +79,12 @@ def get_loggers() -> tuple[list[Logger], list[LoggerArgEx]]:
|
||||
|
||||
def drive(cfg_: configparser.SectionProxy) -> Logger:
|
||||
uuid = cfg_.get('uuid', None)
|
||||
id_ = cfg_.get('id', None)
|
||||
device = Path(cfg_.get('device')) if 'device' in cfg_ else None
|
||||
warn_if_above = int(cfg_['warn_if_above']) if 'warn_if_above' in cfg_ else None
|
||||
warn_threshold = int(cfg_.get('warn_threshold', '1'))
|
||||
warn_data_range = int(cfg_.get('warn_data_range', '1'))
|
||||
return DriveLogger(uuid, device, warn_if_above, warn_threshold, warn_data_range)
|
||||
return DriveLogger(uuid, id_, device, warn_if_above, warn_threshold, warn_data_range)
|
||||
|
||||
def memory(cfg_: configparser.SectionProxy) -> Logger:
|
||||
warn_if_above = float(cfg_.get('warn_if_above', '1.0'))
|
||||
|
@ -16,7 +16,9 @@ class BlkidException(Exception):
|
||||
|
||||
|
||||
class DriveLogger(Logger):
|
||||
def __init__(self, uuid: str = None,
|
||||
def __init__(self,
|
||||
uuid: str = None,
|
||||
id_: str = None,
|
||||
device: Path = None,
|
||||
warn_if_above: int = None,
|
||||
warn_threshold: int = 1,
|
||||
@ -30,21 +32,22 @@ class DriveLogger(Logger):
|
||||
critical_if_above
|
||||
)
|
||||
|
||||
if uuid is None and device is None:
|
||||
raise LoggerArgEx('uuid or device required')
|
||||
|
||||
if uuid is None and id_ is None and device is None:
|
||||
raise LoggerArgEx('uuid, id_ or device required')
|
||||
# `device` might be `None`.
|
||||
if uuid is not None:
|
||||
device = self.get_partition_from_uuid(uuid)
|
||||
if id_ is not None:
|
||||
device = self.get_partition_from_id(id_)
|
||||
# `device` is not `None`, `uuid` might be `None`.
|
||||
if uuid is None:
|
||||
try:
|
||||
self.uuid = self.get_partition_uuid(device)
|
||||
self.uuid = self.get_uuid_from_partition(device)
|
||||
except BlkidException as e:
|
||||
raise LoggerArgEx(getattr(e, 'message', e))
|
||||
else:
|
||||
self.uuid = uuid
|
||||
|
||||
if device is None:
|
||||
self.device = self.get_partition_path(uuid)
|
||||
else:
|
||||
self.device = device
|
||||
# Store as attributes.
|
||||
self.uuid = uuid
|
||||
self.device = device
|
||||
|
||||
self.warn_if_above = warn_if_above
|
||||
|
||||
@ -72,17 +75,24 @@ class DriveLogger(Logger):
|
||||
#
|
||||
|
||||
@classmethod
|
||||
def get_partition_path(cls, uuid: str) -> Path:
|
||||
def get_partition_from_uuid(cls, uuid: str) -> Path:
|
||||
"""
|
||||
:return: Partition path, e.g. /dev/sda1
|
||||
"""
|
||||
return Path(f'/dev/disk/by-uuid/{uuid}').resolve()
|
||||
|
||||
@classmethod
|
||||
def get_partition_uuid(cls, device: Path) -> str:
|
||||
def get_partition_from_id(cls, id_: str) -> Path:
|
||||
"""
|
||||
:param device: E.g. /dev/sda1
|
||||
:return: UUID of e.g. partition /dev/sda1
|
||||
:return: Partition path, e.g. /dev/sda1
|
||||
"""
|
||||
return Path(f'/dev/disk/by-id/{id_}').resolve()
|
||||
|
||||
@classmethod
|
||||
def get_uuid_from_partition(cls, device: Path) -> str:
|
||||
"""
|
||||
:param device: Partition path, e.g. /dev/sda1
|
||||
:return: UUID of given partition
|
||||
:raise BlkidException: If UUID could not be determined.
|
||||
"""
|
||||
returncode, stdout, stderr = execute_capture(['blkid', '-s', 'UUID', '-o', 'value', f'{device}'])
|
||||
@ -95,7 +105,7 @@ class DriveLogger(Logger):
|
||||
@classmethod
|
||||
def get_temp_from_device(cls, device: Path) -> int:
|
||||
"""
|
||||
:param device: For example `/dev/sda` or `/dev/disk/by-uuid/<uuid>`
|
||||
:param device: Partition path, e.g. `/dev/sda`
|
||||
:return: Temperature in celsius
|
||||
"""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user