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

Ros2cli diagnostics #301

Draft
wants to merge 25 commits into
base: ros2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ jobs:
diagnostic_aggregator
diagnostic_common_diagnostics
diagnostic_updater
ros2diagnostics_cli
self_test
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
diagnostic_aggregator,
diagnostic_common_diagnostics,
diagnostic_updater,
ros2diagnostics_cli,
self_test,
]
distro: [foxy, humble, rolling]
Expand Down
152 changes: 152 additions & 0 deletions ros2diagnostics_cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# ROS2 diagnostic cli

ROS2 cli to analysis and monitor `/diagnostics` topic
It's alternative to `diagnostic_analysis` project that not ported yet to ROS2.

The project add `diagnostics` command to ROS2 cli with there verbs.

- list
- show
- csv

### list
Monitor the current diagnostics_status message from `/diagnostics` topic group by Node name and print `diagnostics status` name

```bash
ros2 diagnostics list
# Result
--- time: 1682528234 ---
diagnostic_simple:
- DemoTask
- DemoTask2
```

### show
Monitor `/diagnostics` topic and print the diagnostics_status data can filter by level and node/status name

```bash
ros2 diagnostics show -h
usage: ros2 diagnostics show [-h] [-1] [-f FILTER] [--verbose] [-l {info,warn,error}]

Show diagnostics status item info

options:
-h, --help show this help message and exit
-1, --once run only once
-f FILTER, --filter FILTER
filter diagnostic status name
--verbose, -v Display more info.
-l {info,warn,error}, --levels {info,warn,error}
levels to filter, can be multiple times
```

#### demo

```bash title="show all diagnostics status"
ros2 diagnostics show
#
--- time: 1682528494 ---
diagnostic_simple: DemoTask: WARN, running
diagnostic_simple: DemoTask2: ERROR, bad
--- time: 1682528495 ---
diagnostic_simple: DemoTask: WARN, running
diagnostic_simple: DemoTask2: ERROR, bad
```

```bash title="filter by level"
ros2 diagnostics show -l error
--- time: 1682528568 ---
diagnostic_simple: DemoTask2: ERROR, bad
--- time: 1682528569 ---
diagnostic_simple: DemoTask2: ERROR, bad
--- time: 1682528570 ---
```

```bash title="filter by name"
ros2 diagnostics show -f Task2
#
--- time: 1682528688 ---
diagnostic_simple: DemoTask2: ERROR, bad
--- time: 1682528689 ---
diagnostic_simple: DemoTask2: ERROR, bad
```

```bash title="verbose usage"
ros2 diagnostics show -l warn -v
#
--- time: 1682528760 ---
diagnostic_simple: DemoTask: WARN, running
- key1=val1
- key2=val2
--- time: 1682528761 ---
diagnostic_simple: DemoTask: WARN, running
- key1=val1
- key2=val2

```

### csv
Export `/diagnostics` topic to csv file

**CSV headers**:
- time (sec)
- level
- node name
- diagnostics status name
- message
- hardware id
- values from keyvalue field (only on verbose)


```bash
ros2 diagnostics csv --help
usage: ros2 diagnostics csv [-h] [-1] [-f FILTER] [-l {info,warn,error}] [--output OUTPUT] [--verbose]

export /diagnostics message to csv file

options:
-h, --help show this help message and exit
-1, --once run only once
-f FILTER, --filter FILTER
filter diagnostic status name
-l {info,warn,error}, --levels {info,warn,error}
levels to filter, can be multiple times
--output OUTPUT, -o OUTPUT
export file full path
--verbose, -v export DiagnosticStatus values filed
```

#### Demos

```bash title="simple csv file"
ros2 diagnostics csv -o /tmp/1.csv
--- time: 1682529183 ---
1682529183,WARN,diagnostic_simple,DemoTask,running,
```

```bash title="show csv file"
cat /tmp/1.csv

1682529183,WARN,diagnostic_simple,DemoTask,running,
1682529183,ERROR,diagnostic_simple,DemoTask2,bad,
```

```bash title="filter by level"
ros2 diagnostics csv -o /tmp/1.csv -l error
```

```bash title="filter by name with regex"
ros2 diagnostics csv -o /tmp/1.csv -f Task$ -v
```

## Todo
- More tests
- Add unit test
- DEB package and install tests
- Ideas


## Tests
```
ros2 launch diagnostic_aggregator example.launch.py
```
20 changes: 20 additions & 0 deletions ros2diagnostics_cli/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
<name>ros2diagnostics_cli</name>
<version>3.1.2</version>
<description>diagnostic command for ROS2 command line, parse and show /diagnostics topic</description>
<maintainer email="[email protected]"></maintainer>
<maintainer email="[email protected]">Christian Henkel</maintainer>
<license>BSD-3-Clause</license>

<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<!-- <test_depend>ament_pep257</test_depend> -->
<test_depend>python3-pytest</test_depend>
<depend>ros2cli</depend>
Copy link
Collaborator

Choose a reason for hiding this comment

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

All required packages from this repo must be declared here

<depend>python3-yaml</depend>
<export>
<build_type>ament_python</build_type>
</export>
</package>
Empty file.
Empty file.
Loading