-
Notifications
You must be signed in to change notification settings - Fork 203
Add error percentage to cpu and ram monitor #548
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
base: ros2
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -51,10 +51,11 @@ | |||||
|
|
||||||
| class CpuTask(DiagnosticTask): | ||||||
|
|
||||||
| def __init__(self, warning_percentage=90, window=1): | ||||||
| def __init__(self, warning_percentage=90, error_percentage=100, window=1): | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||
| DiagnosticTask.__init__(self, 'CPU Information') | ||||||
|
|
||||||
| self._warning_percentage = int(warning_percentage) | ||||||
| self._error_percentage = int(error_percentage) | ||||||
| self._readings = deque(maxlen=window) | ||||||
|
|
||||||
| def _get_average_reading(self): | ||||||
|
|
@@ -71,15 +72,15 @@ def run(self, stat): | |||||
|
|
||||||
| stat.add('CPU Load Average', f'{cpu_average:.2f}') | ||||||
|
|
||||||
| warn = False | ||||||
| for idx, cpu_percentage in enumerate(cpu_percentages): | ||||||
| stat.add(f'CPU {idx} Load', f'{cpu_percentage:.2f}') | ||||||
| if cpu_percentage > self._warning_percentage: | ||||||
| warn = True | ||||||
|
|
||||||
| if warn: | ||||||
| if cpu_average > self._error_percentage: | ||||||
| stat.summary(DiagnosticStatus.ERROR, | ||||||
| f'CPU Average exceeds {self._error_percentage} percent') | ||||||
| elif cpu_average > self._warning_percentage: | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||
| stat.summary(DiagnosticStatus.WARN, | ||||||
| f'At least one CPU exceeds {self._warning_percentage} percent') | ||||||
| f'CPU Average exceeds {self._warning_percentage} percent') | ||||||
| else: | ||||||
| stat.summary(DiagnosticStatus.OK, | ||||||
| f'CPU Average {cpu_average:.2f} percent') | ||||||
|
|
@@ -100,16 +101,20 @@ def main(args=None): | |||||
|
|
||||||
| # Declare and get parameters | ||||||
| node.declare_parameter('warning_percentage', 90) | ||||||
| node.declare_parameter('error_percentage', 100) | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 100 is a weird default value. I suggest 95 |
||||||
| node.declare_parameter('window', 1) | ||||||
|
|
||||||
| warning_percentage = node.get_parameter( | ||||||
| 'warning_percentage').get_parameter_value().integer_value | ||||||
| error_percentage = node.get_parameter( | ||||||
| 'error_percentage').get_parameter_value().integer_value | ||||||
| window = node.get_parameter('window').get_parameter_value().integer_value | ||||||
|
|
||||||
| # Create diagnostic updater with default updater rate of 1 hz | ||||||
| updater = Updater(node) | ||||||
| updater.setHardwareID(hostname) | ||||||
| updater.add(CpuTask(warning_percentage=warning_percentage, window=window)) | ||||||
| updater.add(CpuTask(warning_percentage=warning_percentage, error_percentage=error_percentage, | ||||||
| window=window)) | ||||||
|
|
||||||
| rclpy.spin(node) | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
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