From 8eba67b61df3f41468bbebcc025cd42078203f0f Mon Sep 17 00:00:00 2001 From: Antoine Lima Date: Wed, 29 May 2024 01:26:55 +0200 Subject: [PATCH] Implement low and crit parameters in hd_monitor --- .../diagnostic_common_diagnostics/hd_monitor.py | 15 +++++++++++---- .../test/systemtest/test_hd_monitor_launchtest.py | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/diagnostic_common_diagnostics/diagnostic_common_diagnostics/hd_monitor.py b/diagnostic_common_diagnostics/diagnostic_common_diagnostics/hd_monitor.py index 59e26633..c4746ce2 100755 --- a/diagnostic_common_diagnostics/diagnostic_common_diagnostics/hd_monitor.py +++ b/diagnostic_common_diagnostics/diagnostic_common_diagnostics/hd_monitor.py @@ -69,6 +69,8 @@ def __init__(self): self.add_on_set_parameters_callback(self.callback_config) self.declare_parameter("path", "~") + self.declare_parameter("free_percent_low", 0.05) + self.declare_parameter("free_percent_crit", 0.01) self._updater = Updater(self) self._updater.setHardwareID(hostname) @@ -76,8 +78,13 @@ def __init__(self): def callback_config(self, params: List[rclpy.Parameter]): for param in params: - if param.name == "path": - self._path = str(Path(param.value).expanduser().resolve(strict=True)) + match param.name: + case "path": + self._path = str(Path(param.value).expanduser().resolve(strict=True)) + case "free_percent_low": + self._free_percent_low = param.value + case "free_percent_crit": + self._free_percent_crit = param.value return SetParametersResult(successful=True) def check_disk_usage(self, diag: DiagnosticStatus) -> DiagnosticStatus: @@ -86,9 +93,9 @@ def check_disk_usage(self, diag: DiagnosticStatus) -> DiagnosticStatus: total, used, free = disk_usage(self._path) percent = free / total - if percent > FREE_PERCENT_LOW: + if percent > self._free_percent_low: diag.level = DiagnosticStatus.OK - elif percent > FREE_PERCENT_CRIT: + elif percent > self._free_percent_crit: diag.level = DiagnosticStatus.WARN else: diag.level = DiagnosticStatus.ERROR diff --git a/diagnostic_common_diagnostics/test/systemtest/test_hd_monitor_launchtest.py b/diagnostic_common_diagnostics/test/systemtest/test_hd_monitor_launchtest.py index 89e0792a..b038963c 100644 --- a/diagnostic_common_diagnostics/test/systemtest/test_hd_monitor_launchtest.py +++ b/diagnostic_common_diagnostics/test/systemtest/test_hd_monitor_launchtest.py @@ -58,7 +58,7 @@ def generate_test_description(): executable='hd_monitor.py', name='hd_monitor', output='screen', - arguments=[] + ros_arguments=["free_percent_low", "0.20", "free_percent_crit", "0.05"], ), launch_testing.actions.ReadyToTest() ])