Skip to content
Open
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
6 changes: 3 additions & 3 deletions diagnostic_remote_logging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions diagnostic_remote_logging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand Down Expand Up @@ -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 <path_to_yaml_file>
ros2 run diagnostic_remote_logging influxdb_connector --ros-args --params-file <path_to_yaml_file>
```

## Using a Telegraf Proxy
Expand All @@ -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`
Expand All @@ -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 <path_to_yaml_file>
ros2 run diagnostic_remote_logging influxdb_connector --ros-args --params-file <path_to_yaml_file>
```
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<diagnostic_msgs::msg::DiagnosticArray>::SharedPtr diag_sub_;
Expand All @@ -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_
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>("connection.url", "http://localhost:8086/api/v2/write");
Expand Down Expand Up @@ -78,11 +78,14 @@ InfluxDB::InfluxDB(const rclcpp::NodeOptions & opt)

if (send_diagnostics) {
diagnostics_send_timer_ = this->create_wall_timer(
std::chrono::duration<double>(send_period), std::bind(&InfluxDB::sendTimerCallback, this));

diag_sub_ = this->create_subscription<diagnostic_msgs::msg::DiagnosticArray>(
"/diagnostics", rclcpp::SensorDataQoS(),
std::bind(&InfluxDB::diagnosticsCallback, this, std::placeholders::_1));
std::chrono::duration<double>(send_period),
std::bind(&InfluxDBConnector::sendTimerCallback, this));

diag_sub_ =
this->create_subscription<diagnostic_msgs::msg::DiagnosticArray>(
"/diagnostics", rclcpp::SensorDataQoS(),
std::bind(&InfluxDBConnector::diagnosticsCallback, this,
std::placeholders::_1));
}

if (declare_parameter("send.agg", false)) {
Expand All @@ -92,18 +95,21 @@ InfluxDB::InfluxDB(const rclcpp::NodeOptions & opt)
}

if (declare_parameter<bool>("send.top_level_state", true)) {
top_level_sub_ = this->create_subscription<diagnostic_msgs::msg::DiagnosticStatus>(
"/diagnostics_toplevel_state", rclcpp::SensorDataQoS(),
std::bind(&InfluxDB::topLevelCallback, this, std::placeholders::_1));
top_level_sub_ =
this->create_subscription<diagnostic_msgs::msg::DiagnosticStatus>(
"/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");
Expand All @@ -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());
Expand All @@ -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();
Expand All @@ -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.");
Expand Down Expand Up @@ -180,7 +187,7 @@ bool InfluxDB::sendToInfluxDB(const std::string & data)
return true;
}

InfluxDB::~InfluxDB()
InfluxDBConnector::~InfluxDBConnector()
{
if (curl_) {
curl_easy_cleanup(curl_);
Expand All @@ -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)
Loading