feat: alert on Sia hostd usage instead of df for /mnt/sia
Lint / Python (flake8) (push) Successful in 2m6s
Lint / Notify on failure (push) Skipped
Security / Python Security (bandit) (push) Failing after 2m8s
Lint / Python (flake8) (pull_request) Successful in 1m22s
Lint / Notify on failure (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Failing after 1m24s
Test / Python Tests (pytest) (pull_request) Successful in 1m21s
Test / Python Tests (pytest) (push) Successful in 1m19s
Lint / Python (flake8) (push) Successful in 2m6s
Lint / Notify on failure (push) Skipped
Security / Python Security (bandit) (push) Failing after 2m8s
Lint / Python (flake8) (pull_request) Successful in 1m22s
Lint / Notify on failure (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Failing after 1m24s
Test / Python Tests (pytest) (pull_request) Successful in 1m21s
Test / Python Tests (pytest) (push) Successful in 1m19s
hostd allocates its whole data.dat over time and then reuses freed slots, so df on the mount is expected to read nearly full and says nothing about real usage. Alert on hostd's used/total sectors for mounts listed in LXC_MANAGED_VOLUMES, and keep a critical free-space floor for a real out-of-space risk. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
86c7782b61
commit
d8f707ade7
3 files changed
+196
-10
No files matched your search
@@ -1,6 +1,7 @@
|
||||
"""Tests for SystemHealthMonitor pure methods — no external processes or filesystem."""
|
||||
import sys
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -605,3 +606,85 @@ class TestCpuSustainedGating:
|
||||
h = monitor._check_cpu_usage()
|
||||
assert h['status'] == 'WARNING'
|
||||
assert h['load15_per_core_percent'] is None
|
||||
|
||||
|
||||
# ── LXC managed volumes (Sia hostd) ──────────────────────────────────────────
|
||||
|
||||
TIB = 1024 ** 4
|
||||
GIB = 1024 ** 3
|
||||
SIA_DF = "mp0 storj-pool:vm-141-disk-0 15.5T 14.8T 700.0G 95.5 /mnt/sia\n"
|
||||
|
||||
|
||||
def _run_lxc_check(monitor, df_rows, hostd_stdout='1|2', hostd_returncode=0, hostd_error=None):
|
||||
"""Run _check_lxc_storage against canned pct output; return (health, pct exec calls)."""
|
||||
exec_calls = []
|
||||
|
||||
def fake_run(cmd, **kwargs):
|
||||
if cmd[:2] == ['pct', 'list']:
|
||||
return MagicMock(stdout="VMID Status Lock Name\n141 running sia-node\n")
|
||||
if cmd[:2] == ['pct', 'df']:
|
||||
return MagicMock(stdout="MP Volume Size Used Avail Use% Path\n" + df_rows)
|
||||
if cmd[:2] == ['pct', 'exec']:
|
||||
exec_calls.append(cmd)
|
||||
if hostd_error:
|
||||
raise hostd_error
|
||||
return MagicMock(stdout=hostd_stdout, stderr='boom', returncode=hostd_returncode)
|
||||
raise AssertionError(f"unexpected command: {cmd}")
|
||||
|
||||
with patch.dict(monitor._available_tools, {'pct': True}), \
|
||||
patch('subprocess.run', side_effect=fake_run):
|
||||
return monitor._check_lxc_storage(), exec_calls
|
||||
|
||||
|
||||
class TestManagedVolumes:
|
||||
def test_full_mount_with_low_hostd_usage_cuts_no_ticket(self, monitor):
|
||||
"""The mount reads 95.5% full but hostd only uses 3.4 of 15 TiB."""
|
||||
health, calls = _run_lxc_check(monitor, SIA_DF, hostd_stdout='895045|3932160\n')
|
||||
assert health['status'] == 'OK'
|
||||
assert health['issues'] == []
|
||||
fs = health['containers'][0]['filesystems'][0]
|
||||
assert fs['usage_percent'] == pytest.approx(22.76, abs=0.01)
|
||||
assert fs['total_space'] == 15 * TIB
|
||||
assert 'mode=ro' in calls[0][5]
|
||||
|
||||
def test_warns_when_hostd_usage_crosses_warning(self, monitor):
|
||||
health, _ = _run_lxc_check(monitor, SIA_DF, hostd_stdout='3342336|3932160\n')
|
||||
assert health['status'] == 'WARNING'
|
||||
assert health['issues'] == ['LXC 141 high storage usage: 85.0% on /mnt/sia']
|
||||
|
||||
def test_critical_when_hostd_usage_crosses_critical(self, monitor):
|
||||
health, _ = _run_lxc_check(monitor, SIA_DF, hostd_stdout='3800000|3932160\n')
|
||||
assert health['status'] == 'CRITICAL'
|
||||
assert health['issues'] == ['LXC 141 critical storage usage: 96.6% on /mnt/sia']
|
||||
|
||||
def test_critical_when_filesystem_is_nearly_out_of_space(self, monitor):
|
||||
"""A real out-of-space risk must alert even with low hostd usage."""
|
||||
df = "mp0 storj-pool:vm-141-disk-0 15.5T 15.4T 10.0G 99.9 /mnt/sia\n"
|
||||
health, _ = _run_lxc_check(monitor, df, hostd_stdout='895045|3932160\n')
|
||||
assert health['status'] == 'CRITICAL'
|
||||
assert health['issues'] == ['LXC 141 critical storage usage: filesystem nearly out of space on /mnt/sia']
|
||||
|
||||
@pytest.mark.parametrize('kwargs', [
|
||||
{'hostd_returncode': 1, 'hostd_stdout': ''},
|
||||
{'hostd_stdout': 'garbage'},
|
||||
{'hostd_stdout': '0|0\n'},
|
||||
{'hostd_error': subprocess.TimeoutExpired('pct', 30)},
|
||||
])
|
||||
def test_unreadable_hostd_usage_does_not_fall_back_to_df(self, monitor, kwargs):
|
||||
health, _ = _run_lxc_check(monitor, SIA_DF, **kwargs)
|
||||
assert health['status'] == 'OK'
|
||||
assert health['issues'] == []
|
||||
|
||||
def test_floor_still_applies_when_hostd_usage_is_unreadable(self, monitor):
|
||||
df = "mp0 storj-pool:vm-141-disk-0 15.5T 15.4T 10.0G 99.9 /mnt/sia\n"
|
||||
health, _ = _run_lxc_check(monitor, df, hostd_returncode=1, hostd_stdout='')
|
||||
assert health['status'] == 'CRITICAL'
|
||||
assert len(health['issues']) == 1
|
||||
|
||||
def test_other_mounts_still_use_df(self, monitor):
|
||||
"""The container's rootfs, and other containers, keep normal df alerting."""
|
||||
df = "rootfs sia-nvme:vm-141-disk-0 125.9G 115.0G 5.0G 91.3 /\n"
|
||||
health, calls = _run_lxc_check(monitor, df)
|
||||
assert health['status'] == 'CRITICAL'
|
||||
assert health['issues'] == ['LXC 141 critical storage usage: 91.3% on /']
|
||||
assert calls == []
|
||||
Reference in new issue
Block a user