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..50961e91f 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__INFLUXDB_CONNECTOR_HPP_ +#define DIAGNOSTIC_REMOTE_LOGGING__INFLUXDB_CONNECTOR_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__INFLUXDB_CONNECTOR_HPP_ diff --git a/diagnostic_remote_logging/src/influxdb.cpp b/diagnostic_remote_logging/src/influxdb_connector.cpp similarity index 82% rename from diagnostic_remote_logging/src/influxdb.cpp rename to diagnostic_remote_logging/src/influxdb_connector.cpp index 2dd6afa37..a9a6f405d 100644 --- a/diagnostic_remote_logging/src/influxdb.cpp +++ b/diagnostic_remote_logging/src/influxdb_connector.cpp @@ -36,10 +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 +78,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,18 +95,21 @@ 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,7 +120,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,7 +133,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(); @@ -151,7 +158,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."); @@ -180,7 +187,7 @@ bool InfluxDB::sendToInfluxDB(const std::string & data) return true; } -InfluxDB::~InfluxDB() +InfluxDBConnector::~InfluxDBConnector() { if (curl_) { curl_easy_cleanup(curl_); @@ -193,4 +200,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)