Skip to content

Add error percentage to cpu and ram monitor#548

Open
sangteak601 wants to merge 5 commits intoros:ros2from
sangteak601:add_configuration
Open

Add error percentage to cpu and ram monitor#548
sangteak601 wants to merge 5 commits intoros:ros2from
sangteak601:add_configuration

Conversation

@sangteak601
Copy link
Copy Markdown

At the moment, it is not possible to configure cpu_monitor or ram_monitor to publish ERROR status. It would be good to have ERROR state. It would allow us to take actions before program exhibits unexpected behaviour.

Also, cpu_monitor was updated to compare threshold to average cpu usage rather than individual cpu usage. This is aligned with how ram_monitor works and makes more sense, as in most cases users are more interested in average usage than individual usage.

@mergify mergify bot added the ros2 PR tackling a ROS2 branch label Dec 17, 2025
@sangteak601
Copy link
Copy Markdown
Author

@ct2034
It seems I can't add a reviewer. Would you be able to take a look at this?

if cpu_average > self._error_percentage:
stat.summary(DiagnosticStatus.ERROR,
f'CPU Average exceeds {self._error_percentage} percent')
elif cpu_average > self._warning_percentage:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the behavior, because previously this warning was done per individual cpu. This is not bad per se. But the default behaviour should stay as it was previously


# Declare and get parameters
node.declare_parameter('warning_percentage', 90)
node.declare_parameter('error_percentage', 100)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100 is a weird default value. I suggest 95

Comment on lines 16 to +17
* warning_percentage: If the CPU usage is > warning_percentage, a WARN status will be publised.
* error_percentage: If the CPU usage is > error_percentage, an ERROR status will be published.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also make the this more precise in terms of average vs single cpu

class CpuTask(DiagnosticTask):

def __init__(self, warning_percentage=90, window=1):
def __init__(self, warning_percentage=90, error_percentage=100, window=1):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def __init__(self, warning_percentage=90, error_percentage=100, window=1):
def __init__(self, warning_percentage, error_percentage, window):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this way its closer to the ram implementation and there are not too many place where defaults are set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ros2 PR tackling a ROS2 branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants