From 55859d8f1930c00e69fc56b33adf2073397dfb43 Mon Sep 17 00:00:00 2001 From: Daan Wijffels Date: Mon, 15 Dec 2025 17:31:20 +0100 Subject: [PATCH 1/2] Change node name from influxdb to influxdb_connector --- diagnostic_remote_logging/CMakeLists.txt | 6 +-- diagnostic_remote_logging/README.md | 14 +++--- .../{influxdb.hpp => influxdb_connector.hpp} | 12 ++--- .../{influxdb.cpp => influxdb_connector.cpp} | 50 +++++++++---------- 4 files changed, 41 insertions(+), 41 deletions(-) rename diagnostic_remote_logging/include/diagnostic_remote_logging/{influxdb.hpp => influxdb_connector.hpp} (89%) rename diagnostic_remote_logging/src/{influxdb.cpp => influxdb_connector.cpp} (81%) diff --git a/diagnostic_remote_logging/CMakeLists.txt b/diagnostic_remote_logging/CMakeLists.txt index 0627da4c2..a82d40ca4 100644 --- a/diagnostic_remote_logging/CMakeLists.txt +++ b/diagnostic_remote_logging/CMakeLists.txt @@ -29,7 +29,7 @@ include_directories( src/ include/ ) -add_library(influx_component SHARED src/influxdb.cpp) +add_library(influx_component SHARED src/influxdb_connector.cpp) target_link_libraries(influx_component PUBLIC ${diagnostic_msgs_TARGETS} @@ -44,8 +44,8 @@ target_compile_features(influx_component PUBLIC c_std_99 cxx_std_17) rclcpp_components_register_node( influx_component - PLUGIN "InfluxDB" - EXECUTABLE influx + PLUGIN "InfluxDBConnector" + EXECUTABLE influxdb_connector ) ament_export_targets(export_influx_component) install(TARGETS influx_component diff --git a/diagnostic_remote_logging/README.md b/diagnostic_remote_logging/README.md index a3e19084b..276776389 100644 --- a/diagnostic_remote_logging/README.md +++ b/diagnostic_remote_logging/README.md @@ -2,7 +2,7 @@ General information about this repository, including legal information and known # The diagnostic_remote_logging package -This package provides the `influxdb` 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). +This package provides the `influxdb_connector` 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. @@ -19,10 +19,10 @@ To use either method, ensure you have a running instance of InfluxDB. The simple ### Parameters -The `influxdb` node supports several parameters. Below is an example configuration: +The `influxdb_connector` node supports several parameters. Below is an example configuration: ```yaml -/influxdb: +/influxdb_connector: ros__parameters: connection: url: http://localhost:8086/api/v2/write @@ -53,7 +53,7 @@ Set the following parameters in your configuration to match your InfluxDB instan Afterward all configurations are set run the node with the following command: ```bash -ros2 run diagnostic_remote_logging influx --ros-args --params-file +ros2 run diagnostic_remote_logging influxdb_connector --ros-args --params-file ``` ## Using a Telegraf Proxy @@ -68,9 +68,9 @@ To configure Telegraf as a proxy for InfluxDB: service_address = ":8187" # different port than the default 8086 ``` -3. Update the `influxdb` node configuration to point to the appropriate URL. For example, if Telegraf is running on the same host as the `influxdb` node, then `http://localhost:8187/api/v2/write` should work. +3. Update the `influxdb_connector` node configuration to point to the appropriate URL. For example, if Telegraf is running on the same host as the `influxdb_connector` node, then `http://localhost:8187/api/v2/write` should work. -4. Leave the following parameters empty in the `influxdb` node configuration when using Telegraf as a proxy: +4. Leave the following parameters empty in the `influxdb_connector` node configuration when using Telegraf as a proxy: - `connection.token` - `connection.bucket` @@ -79,5 +79,5 @@ To configure Telegraf as a proxy for InfluxDB: 5. Afterwards run the node with the following command: ```bash - ros2 run diagnostic_remote_logging influx --ros-args --params-file + ros2 run diagnostic_remote_logging influxdb_connector --ros-args --params-file ``` diff --git a/diagnostic_remote_logging/include/diagnostic_remote_logging/influxdb.hpp b/diagnostic_remote_logging/include/diagnostic_remote_logging/influxdb_connector.hpp similarity index 89% rename from diagnostic_remote_logging/include/diagnostic_remote_logging/influxdb.hpp rename to diagnostic_remote_logging/include/diagnostic_remote_logging/influxdb_connector.hpp index 2c2dda071..52ebf042d 100644 --- a/diagnostic_remote_logging/include/diagnostic_remote_logging/influxdb.hpp +++ b/diagnostic_remote_logging/include/diagnostic_remote_logging/influxdb_connector.hpp @@ -36,8 +36,8 @@ * \author Daan Wijffels */ -#ifndef DIAGNOSTIC_REMOTE_LOGGING__INFLUXDB_HPP_ -#define DIAGNOSTIC_REMOTE_LOGGING__INFLUXDB_HPP_ +#ifndef DIAGNOSTIC_REMOTE_LOGGING__INFLUXDBCONNECTOR_HPP_ +#define DIAGNOSTIC_REMOTE_LOGGING__INFLUXDBCONNECTOR_HPP_ #if defined(_WIN32) #define NOMINMAX @@ -51,11 +51,11 @@ #include "diagnostic_remote_logging/influx_line_protocol.hpp" #include "rclcpp/rclcpp.hpp" -class InfluxDB : public rclcpp::Node +class InfluxDBConnector : public rclcpp::Node { public: - explicit InfluxDB(const rclcpp::NodeOptions & opt); - ~InfluxDB(); + explicit InfluxDBConnector(const rclcpp::NodeOptions & opt); + ~InfluxDBConnector(); private: rclcpp::Subscription::SharedPtr diag_sub_; @@ -77,4 +77,4 @@ class InfluxDB : public rclcpp::Node bool sendToInfluxDB(const std::string & data); }; -#endif // DIAGNOSTIC_REMOTE_LOGGING__INFLUXDB_HPP_ +#endif // DIAGNOSTIC_REMOTE_LOGGING__INFLUXDBCONNECTOR_HPP_ diff --git a/diagnostic_remote_logging/src/influxdb.cpp b/diagnostic_remote_logging/src/influxdb_connector.cpp similarity index 81% rename from diagnostic_remote_logging/src/influxdb.cpp rename to diagnostic_remote_logging/src/influxdb_connector.cpp index 2dd6afa37..8097da8e4 100644 --- a/diagnostic_remote_logging/src/influxdb.cpp +++ b/diagnostic_remote_logging/src/influxdb_connector.cpp @@ -36,11 +36,10 @@ * \author Daan Wijffels */ -#include "diagnostic_remote_logging/influxdb.hpp" +#include "diagnostic_remote_logging/influxdb_connector.hpp" -InfluxDB::InfluxDB(const rclcpp::NodeOptions & opt) -: Node("influxdb", opt) -{ +InfluxDBConnector::InfluxDBConnector(const rclcpp::NodeOptions &opt) + : Node("influxdb_connector", opt) { post_url_ = this->declare_parameter("connection.url", "http://localhost:8086/api/v2/write"); @@ -78,11 +77,14 @@ InfluxDB::InfluxDB(const rclcpp::NodeOptions & opt) if (send_diagnostics) { diagnostics_send_timer_ = this->create_wall_timer( - std::chrono::duration(send_period), std::bind(&InfluxDB::sendTimerCallback, this)); - - diag_sub_ = this->create_subscription( - "/diagnostics", rclcpp::SensorDataQoS(), - std::bind(&InfluxDB::diagnosticsCallback, this, std::placeholders::_1)); + std::chrono::duration(send_period), + std::bind(&InfluxDBConnector::sendTimerCallback, this)); + + diag_sub_ = + this->create_subscription( + "/diagnostics", rclcpp::SensorDataQoS(), + std::bind(&InfluxDBConnector::diagnosticsCallback, this, + std::placeholders::_1)); } if (declare_parameter("send.agg", false)) { @@ -92,19 +94,20 @@ InfluxDB::InfluxDB(const rclcpp::NodeOptions & opt) } if (declare_parameter("send.top_level_state", true)) { - top_level_sub_ = this->create_subscription( - "/diagnostics_toplevel_state", rclcpp::SensorDataQoS(), - std::bind(&InfluxDB::topLevelCallback, this, std::placeholders::_1)); + top_level_sub_ = + this->create_subscription( + "/diagnostics_toplevel_state", rclcpp::SensorDataQoS(), + std::bind(&InfluxDBConnector::topLevelCallback, this, + std::placeholders::_1)); } } -void InfluxDB::diagnosticsCallback(const diagnostic_msgs::msg::DiagnosticArray::SharedPtr msg) -{ +void InfluxDBConnector::diagnosticsCallback( + const diagnostic_msgs::msg::DiagnosticArray::SharedPtr msg) { diagnosticArrayToInfluxLineProtocol(output_string_, msg); } -void InfluxDB::sendTimerCallback() -{ +void InfluxDBConnector::sendTimerCallback() { if (!sendToInfluxDB(output_string_)) { RCLCPP_ERROR(this->get_logger(), "Failed to send /diagnostics to telegraf"); } @@ -114,8 +117,8 @@ void InfluxDB::sendTimerCallback() output_string_.clear(); } -void InfluxDB::topLevelCallback(const diagnostic_msgs::msg::DiagnosticStatus::SharedPtr msg) -{ +void InfluxDBConnector::topLevelCallback( + const diagnostic_msgs::msg::DiagnosticStatus::SharedPtr msg) { std::string output; statusToInfluxLineProtocol(output, *msg, this->get_clock()->now()); @@ -126,8 +129,7 @@ void InfluxDB::topLevelCallback(const diagnostic_msgs::msg::DiagnosticStatus::Sh RCLCPP_DEBUG(this->get_logger(), "%s", output.c_str()); } -void InfluxDB::setupConnection(const std::string & url) -{ +void InfluxDBConnector::setupConnection(const std::string &url) { curl_global_init(CURL_GLOBAL_ALL); curl_ = curl_easy_init(); if (!curl_) { @@ -151,8 +153,7 @@ void InfluxDB::setupConnection(const std::string & url) curl_easy_setopt(curl_, CURLOPT_POST, 1L); } -bool InfluxDB::sendToInfluxDB(const std::string & data) -{ +bool InfluxDBConnector::sendToInfluxDB(const std::string &data) { if (!curl_) { RCLCPP_ERROR(this->get_logger(), "cURL not initialized."); return false; @@ -180,8 +181,7 @@ bool InfluxDB::sendToInfluxDB(const std::string & data) return true; } -InfluxDB::~InfluxDB() -{ +InfluxDBConnector::~InfluxDBConnector() { if (curl_) { curl_easy_cleanup(curl_); } @@ -193,4 +193,4 @@ InfluxDB::~InfluxDB() // Register the component with class_loader. // This acts as a sort of entry point, allowing the component to be discoverable when its library // is being loaded into a running process. -RCLCPP_COMPONENTS_REGISTER_NODE(InfluxDB) +RCLCPP_COMPONENTS_REGISTER_NODE(InfluxDBConnector) From 323e4932161cc28e9803782c5eb00a9866c0327e Mon Sep 17 00:00:00 2001 From: Daan Wijffels Date: Tue, 16 Dec 2025 10:48:00 +0100 Subject: [PATCH 2/2] As always I forgot to lint... --- .../influxdb_connector.hpp | 6 ++--- .../src/influxdb_connector.cpp | 27 ++++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/diagnostic_remote_logging/include/diagnostic_remote_logging/influxdb_connector.hpp b/diagnostic_remote_logging/include/diagnostic_remote_logging/influxdb_connector.hpp index 52ebf042d..50961e91f 100644 --- a/diagnostic_remote_logging/include/diagnostic_remote_logging/influxdb_connector.hpp +++ b/diagnostic_remote_logging/include/diagnostic_remote_logging/influxdb_connector.hpp @@ -36,8 +36,8 @@ * \author Daan Wijffels */ -#ifndef DIAGNOSTIC_REMOTE_LOGGING__INFLUXDBCONNECTOR_HPP_ -#define DIAGNOSTIC_REMOTE_LOGGING__INFLUXDBCONNECTOR_HPP_ +#ifndef DIAGNOSTIC_REMOTE_LOGGING__INFLUXDB_CONNECTOR_HPP_ +#define DIAGNOSTIC_REMOTE_LOGGING__INFLUXDB_CONNECTOR_HPP_ #if defined(_WIN32) #define NOMINMAX @@ -77,4 +77,4 @@ class InfluxDBConnector : public rclcpp::Node bool sendToInfluxDB(const std::string & data); }; -#endif // DIAGNOSTIC_REMOTE_LOGGING__INFLUXDBCONNECTOR_HPP_ +#endif // DIAGNOSTIC_REMOTE_LOGGING__INFLUXDB_CONNECTOR_HPP_ diff --git a/diagnostic_remote_logging/src/influxdb_connector.cpp b/diagnostic_remote_logging/src/influxdb_connector.cpp index 8097da8e4..a9a6f405d 100644 --- a/diagnostic_remote_logging/src/influxdb_connector.cpp +++ b/diagnostic_remote_logging/src/influxdb_connector.cpp @@ -38,8 +38,9 @@ #include "diagnostic_remote_logging/influxdb_connector.hpp" -InfluxDBConnector::InfluxDBConnector(const rclcpp::NodeOptions &opt) - : Node("influxdb_connector", opt) { +InfluxDBConnector::InfluxDBConnector(const rclcpp::NodeOptions & opt) +: Node("influxdb_connector", opt) +{ post_url_ = this->declare_parameter("connection.url", "http://localhost:8086/api/v2/write"); @@ -81,7 +82,7 @@ InfluxDBConnector::InfluxDBConnector(const rclcpp::NodeOptions &opt) std::bind(&InfluxDBConnector::sendTimerCallback, this)); diag_sub_ = - this->create_subscription( + this->create_subscription( "/diagnostics", rclcpp::SensorDataQoS(), std::bind(&InfluxDBConnector::diagnosticsCallback, this, std::placeholders::_1)); @@ -95,7 +96,7 @@ InfluxDBConnector::InfluxDBConnector(const rclcpp::NodeOptions &opt) if (declare_parameter("send.top_level_state", true)) { top_level_sub_ = - this->create_subscription( + this->create_subscription( "/diagnostics_toplevel_state", rclcpp::SensorDataQoS(), std::bind(&InfluxDBConnector::topLevelCallback, this, std::placeholders::_1)); @@ -103,11 +104,13 @@ InfluxDBConnector::InfluxDBConnector(const rclcpp::NodeOptions &opt) } void InfluxDBConnector::diagnosticsCallback( - const diagnostic_msgs::msg::DiagnosticArray::SharedPtr msg) { + const diagnostic_msgs::msg::DiagnosticArray::SharedPtr msg) +{ diagnosticArrayToInfluxLineProtocol(output_string_, msg); } -void InfluxDBConnector::sendTimerCallback() { +void InfluxDBConnector::sendTimerCallback() +{ if (!sendToInfluxDB(output_string_)) { RCLCPP_ERROR(this->get_logger(), "Failed to send /diagnostics to telegraf"); } @@ -118,7 +121,8 @@ void InfluxDBConnector::sendTimerCallback() { } void InfluxDBConnector::topLevelCallback( - const diagnostic_msgs::msg::DiagnosticStatus::SharedPtr msg) { + const diagnostic_msgs::msg::DiagnosticStatus::SharedPtr msg) +{ std::string output; statusToInfluxLineProtocol(output, *msg, this->get_clock()->now()); @@ -129,7 +133,8 @@ void InfluxDBConnector::topLevelCallback( RCLCPP_DEBUG(this->get_logger(), "%s", output.c_str()); } -void InfluxDBConnector::setupConnection(const std::string &url) { +void InfluxDBConnector::setupConnection(const std::string & url) +{ curl_global_init(CURL_GLOBAL_ALL); curl_ = curl_easy_init(); if (!curl_) { @@ -153,7 +158,8 @@ void InfluxDBConnector::setupConnection(const std::string &url) { curl_easy_setopt(curl_, CURLOPT_POST, 1L); } -bool InfluxDBConnector::sendToInfluxDB(const std::string &data) { +bool InfluxDBConnector::sendToInfluxDB(const std::string & data) +{ if (!curl_) { RCLCPP_ERROR(this->get_logger(), "cURL not initialized."); return false; @@ -181,7 +187,8 @@ bool InfluxDBConnector::sendToInfluxDB(const std::string &data) { return true; } -InfluxDBConnector::~InfluxDBConnector() { +InfluxDBConnector::~InfluxDBConnector() +{ if (curl_) { curl_easy_cleanup(curl_); }