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

Grafana Integration #425

Merged
merged 36 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6c6eef9
First working version of remote_logging
Dec 4, 2024
8662aee
Merge branch 'ros:ros2' into ros2
dwffls Dec 11, 2024
390bb8c
Added more error handling, and skipping values when new line is prese…
dwffls Dec 18, 2024
53b5297
Changed default telegraf url to reflect the change to influxdb_v2_lis…
dwffls Dec 18, 2024
a43c0c0
Changed default telegraf url to reflect the change to influxdb_v2_lis…
dwffls Dec 18, 2024
003e8a5
Made node composable and changed name to influx to better reflect use…
Dec 18, 2024
0d526ee
Added README
Dec 18, 2024
0a7ebbc
Merge branch 'ros:ros2' into influx_db
dwffls Dec 18, 2024
2491bad
Escaping string values fixed
Jan 6, 2025
b97c4de
Build fix on farm
dwffls Jan 8, 2025
3231f91
Adde curl dependency
dwffls Jan 8, 2025
6eb4c49
Removed Curl Dependency as build does not work on farm
dwffls Jan 8, 2025
adbc480
Merge branch 'ros:ros2' into influx_db
dwffls Jan 8, 2025
5e15745
Curl Dependency
dwffls Jan 8, 2025
61c69eb
Update diagnostic_remote_logging/package.xml
dwffls Jan 8, 2025
3c26580
Update diagnostic_remote_logging/package.xml
dwffls Jan 8, 2025
0ece0a2
Added unit tests for influx_line_protocol
Jan 9, 2025
5ca34cd
Only depend on gtest when testing
Jan 9, 2025
733b6fb
Update diagnostic_remote_logging/README.md
dwffls Jan 15, 2025
91880fb
Update diagnostic_remote_logging/README.md
dwffls Jan 15, 2025
87fa500
Update diagnostic_remote_logging/README.md
dwffls Jan 15, 2025
2f16302
Update diagnostic_remote_logging/README.md
dwffls Jan 15, 2025
a73894f
Update diagnostic_remote_logging/README.md
dwffls Jan 15, 2025
6fcf498
Apply suggestions from code review
dwffls Jan 15, 2025
598ed5d
Added diagnostic_remote_logging
Jan 15, 2025
3635eb4
Added BSD clause and added untested function
Jan 15, 2025
09986e3
Apply suggestions from code review
Jan 15, 2025
9533f14
Update diagnostic_remote_logging/package.xml
dwffls Feb 4, 2025
feebeea
Implemented linter feedback
dwffls Feb 4, 2025
f62799e
Updated README.md
dwffls Feb 4, 2025
545d6b4
removed build warning
dwffls Feb 4, 2025
02a3719
Merge branch 'ros:ros2' into influx_db
dwffls Feb 4, 2025
ee48a40
Fixed linting erorrs that were fixed by auto formatting
dwffls Feb 4, 2025
1ed80fc
Hopefully the last of the linting errors
dwffls Feb 4, 2025
8d37e53
This should do it for cpplint
dwffls Feb 4, 2025
eacde28
Forgot uncrustify
dwffls Feb 4, 2025
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 @@ -41,6 +41,7 @@ jobs:
package-name: |
diagnostic_aggregator
diagnostic_common_diagnostics
diagnostic_remote_logging
diagnostic_updater
self_test

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
package: [
diagnostic_aggregator,
diagnostic_common_diagnostics,
diagnostic_remote_logging,
diagnostic_updater,
self_test,
]
Expand Down
52 changes: 52 additions & 0 deletions diagnostic_remote_logging/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
cmake_minimum_required(VERSION 3.8)

project(diagnostic_remote_logging)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

set(dependencies
ament_cmake
rclcpp
rclcpp_components
diagnostic_msgs
CURL
)

foreach(dep ${dependencies})
find_package(${dep} REQUIRED)
endforeach(dep)

include_directories(
src/
include/
)
add_library(influx_component SHARED src/influxdb.cpp)

ament_target_dependencies(influx_component ${dependencies})

ament_export_dependencies(influx_component ${dependencies})

target_compile_features(influx_component PUBLIC c_std_99 cxx_std_17)

rclcpp_components_register_node(
influx_component
PLUGIN "InfluxDB"
EXECUTABLE influx
)
ament_export_targets(export_influx_component)
install(TARGETS influx_component
EXPORT export_influx_component
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)

if(BUILD_TESTING)
find_package(ament_cmake_gtest REQUIRED)
ament_add_gtest(unit_tests test/influx_line_protocol.cpp)
target_include_directories(unit_tests PRIVATE include)
target_link_libraries(unit_tests influx_component)
ament_target_dependencies(unit_tests ${dependencies} ament_cmake_gtest)
endif()
ament_package()
52 changes: 52 additions & 0 deletions diagnostic_remote_logging/CMakeLists.txt.uncrustify
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
cmake_minimum_required(VERSION 3.8)

project(diagnostic_remote_logging)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall - Wextra - Wpedantic)
endif()

set(dependencies
ament_cmake
rclcpp
rclcpp_components
diagnostic_msgs
CURL
)

foreach(dep $ {dependencies})
find_package($ {dep} REQUIRED)
endforeach(dep)

include_directories(
src /
include /
)
add_library(influx_component SHARED src / influxdb.cpp)

ament_target_dependencies(influx_component $ {dependencies})

ament_export_dependencies(influx_component $ {dependencies})

target_compile_features(influx_component PUBLIC c_std_99 cxx_std_17)

rclcpp_components_register_node(
influx_component
PLUGIN "InfluxDB"
EXECUTABLE influx
)
ament_export_targets(export_influx_component)
install(TARGETS influx_component
EXPORT export_influx_component
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)

if(BUILD_TESTING)
find_package(ament_cmake_gtest REQUIRED)
ament_add_gtest(unit_tests test / influx_line_protocol.cpp)
target_include_directories(unit_tests PRIVATE include)
target_link_libraries(unit_tests influx_component)
ament_target_dependencies(unit_tests $ {dependencies} ament_cmake_gtest)
endif()
ament_package()
52 changes: 52 additions & 0 deletions diagnostic_remote_logging/CMakeLists.txt.uncrustify.uncrustify
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
cmake_minimum_required(VERSION 3.8)

project(diagnostic_remote_logging)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall - Wextra - Wpedantic)
endif()

set(dependencies
ament_cmake
rclcpp
rclcpp_components
diagnostic_msgs
CURL
)

foreach(dep $ {dependencies})
find_package($ {dep} REQUIRED)
endforeach(dep)

include_directories(
src /
include /
)
add_library(influx_component SHARED src / influxdb.cpp)

ament_target_dependencies(influx_component $ {dependencies})

ament_export_dependencies(influx_component $ {dependencies})

target_compile_features(influx_component PUBLIC c_std_99 cxx_std_17)

rclcpp_components_register_node(
influx_component
PLUGIN "InfluxDB"
EXECUTABLE influx
)
ament_export_targets(export_influx_component)
install(TARGETS influx_component
EXPORT export_influx_component
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)

if(BUILD_TESTING)
find_package(ament_cmake_gtest REQUIRED)
ament_add_gtest(unit_tests test / influx_line_protocol.cpp)
target_include_directories(unit_tests PRIVATE include)
target_link_libraries(unit_tests influx_component)
ament_target_dependencies(unit_tests $ {dependencies} ament_cmake_gtest)
endif()
ament_package()
81 changes: 81 additions & 0 deletions diagnostic_remote_logging/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
General information about this repository, including legal information and known issues/limitations, are given in [README.md](../README.md) in the repository root.

# The diagnostic_remote_logging package

This package provides the `influx` node, which listens to diagnostic messages and integrates with InfluxDB v2 for monitoring and visualization. Specifically, it subscribes to the [`diagnostic_msgs/DiagnosticArray`](https://index.ros.org/p/diagnostic_msgs) messages on the `/diagnostics_agg` topic and the [`diagnostic_msgs/DiagnosticStatus`](https://index.ros.org/p/diagnostic_msgs) messages on the `/diagnostics_toplevel_state` topic. The node processes these messages, sending their statistics and levels to an [`InfluxDB`](http://influxdb.com) database, enabling use with tools like [`Grafana`](https://grafana.com).

As of now we only support InfluxDB v2, for support with older versions please use a proxy like [`Telegraf`](https://www.influxdata.com/time-series-platform/telegraf/). See section [Telegraf](#using-a-telegraf-proxy) for an example on how to setup.

## Node Configuration

You can send data to [`InfluxDB`](http://influxdb.com) in two ways: directly to the database or via a proxy like [`Telegraf`](https://www.influxdata.com/time-series-platform/telegraf/). While both methods are valid, using a proxy is generally recommended due to the following benefits:

- **Efficient Data Transmission**: Telegraf aggregates multiple measurements and sends them in a single request, reducing bandwidth usage and minimizing database load.
- **Enhanced Reliability**: Provides buffering in case of connection issues, ensuring no data is lost.
- **Comprehensive Metric Collection**: Telegraf can send additional system metrics (e.g., RAM, CPU, network usage) with minimal configuration.
- **Data Filtering and Transformation**: Supports preprocessing, such as filtering or transforming data, before sending it to InfluxDB.

To use either method, ensure you have a running instance of InfluxDB. The simplest way to set this up is through [`InfluxDB Cloud`](https://cloud2.influxdata.com/signup).

### Parameters

The `influx` node supports several parameters. Below is an example configuration:

```yaml
/influx:
ros__parameters:
connection:
url: http://localhost:8086/api/v2/write
token:
bucket:
organization:
send:
agg: true
top_level_state: true
```

- `send.agg`: Enables or disables subscription to the `/diagnostics_agg` topic.
- `send.top_level_state`: Enables or disables subscription to the `/diagnostics_toplevel_state` topic.

#### InfluxDB Configuration

Set the following parameters in your configuration to match your InfluxDB instance:

- `connection.url`: The URL of your InfluxDB write API endpoint.
- `connection.token`: Your InfluxDB authentication token.
- `connection.bucket`: The target bucket in InfluxDB.
- `connection.organization`: The name of your InfluxDB organization.

### Starting the node

Afterward all configurations are set run the node with the following command:

```bash
ros2 run diagnostic_remote_logging influx --ros-args --params-file <path_to_yaml_file>
```

## Using a Telegraf Proxy

To configure Telegraf as a proxy for InfluxDB:

1. Ensure Telegraf is set up to send data to your InfluxDB instance via its configuration file (`/etc/telegraf/telegraf.conf`). Check [this link](https://docs.influxdata.com/influxdb/cloud/write-data/no-code/use-telegraf/manual-config/) for an example.
2. Add the following to the telegraf configuration file to enable the InfluxDB v2 listener:

```toml
[[inputs.influxdb_v2_listener]]
service_address = ":8086"
```

3. Update the `influx` node configuration to point to the appropriate URL. For example, if Telegraf is running on the same host as the `influx` node, the default `http://localhost:8086/api/v2/write` should work.

4. Leave the following parameters empty in the `influx` node configuration when using Telegraf as a proxy:

- `connection.token`
- `connection.bucket`
- `connection.organization`

5. Afterwards run the node with the following command:

```bash
ros2 run diagnostic_remote_logging influx --ros-args --params-file <path_to_yaml_file>
```
Empty file.
Loading
Loading