Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port hd_monitor to ROS2 #334

Merged
merged 10 commits into from
Jul 3, 2024
Prev Previous commit
Next Next commit
Implement low and crit parameters in hd_monitor
limaanto committed Jun 27, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 145bb41950d322367f4a8d8b412e09ea80daaaef
Original file line number Diff line number Diff line change
@@ -69,15 +69,22 @@ 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)
self._updater.add(f"{hostname} HD Usage", self.check_disk_usage)

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)
limaanto marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
@@ -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()
])