Skip to content

Commit

Permalink
Implement low and crit parameters in hd_monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
limaanto committed May 28, 2024
1 parent 6c60eda commit 8eba67b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
])
Expand Down

0 comments on commit 8eba67b

Please sign in to comment.