RTC Toolkit 6.0.0-pre2
Loading...
Searching...
No Matches
telegrafAdapter.hpp
Go to the documentation of this file.
1
12
13#ifndef RTCTK_COMPONENTFRAMEWORK_TELEGRAFADAPTER_HPP
14#define RTCTK_COMPONENTFRAMEWORK_TELEGRAFADAPTER_HPP
15
16#include <string>
17#include <map>
18#include <boost/asio.hpp>
19#include <mal/utility/Uri.hpp>
20
22
24
25using FieldValue = std::variant<int64_t, uint64_t, float, double, bool, std::string>;
26
43 std::string table_name;
44
50 std::map<std::string, std::string> tags;
51
57 std::map<std::string, FieldValue> fields;
58
65 std::optional<std::chrono::nanoseconds> timestamp = std::nullopt;
66
80 std::string ToLineProtocol() const;
81};
82
83std::vector<InfluxPoint>
84ParseStateToInfluxPoints(const std::string& component_name,
85 const std::string& states_str,
86 const std::map<std::string, std::string>& base_tags);
87
94public:
96 TelegrafAdapter() = delete;
97
100
103
110 explicit TelegrafAdapter(const elt::mal::Uri& uri, std::string component);
111
112 ~TelegrafAdapter() = default;
113
126 std::map<std::string, std::string> BaseTags();
127
137 void SendPoints(const std::vector<InfluxPoint>& points);
138
139private:
140 static const std::size_t MTU = 1500;
141
142 boost::asio::io_service m_io_service;
143 boost::asio::ip::udp::socket m_socket;
144 boost::asio::ip::udp::endpoint m_endpoint;
145 std::string m_host;
146 std::string m_pid;
147 std::string m_component;
148 std::mutex m_mutex;
149 log4cplus::Logger m_logger;
150 bool m_enabled = true;
151};
152
153} // namespace rtctk::componentFramework
154
155#endif // RTCTK_COMPONENTFRAMEWORK_TELEGRAFADAPTER_HPP
std::map< std::string, std::string > BaseTags()
Constructs and returns a map of base tags for InfluxDB.
Definition telegrafAdapter.cpp:78
TelegrafAdapter(const TelegrafAdapter &)=delete
This class cannot be copy constructed.
TelegrafAdapter()=delete
Do not allow construction with no arguments.
void SendPoints(const std::vector< InfluxPoint > &points)
Sends vector of points to Telegraf using UDP and Influx line protocol.
Definition telegrafAdapter.cpp:86
TelegrafAdapter & operator=(const TelegrafAdapter &)=delete
This class cannot be copy assigned.
Logging Support Library based on log4cplus.
Definition commandReplier.cpp:22
std::vector< InfluxPoint > ParseStateToInfluxPoints(const std::string &component_name, const std::string &states_str, const std::map< std::string, std::string > &base_tags)
Definition telegrafAdapter.cpp:213
std::variant< int64_t, uint64_t, float, double, bool, std::string > FieldValue
Definition telegrafAdapter.hpp:25
Represents a single data point for InfluxDB.
Definition telegrafAdapter.hpp:37
std::string ToLineProtocol() const
Encodes data to InfluxDB line protocol format.
Definition telegrafAdapter.cpp:128
std::optional< std::chrono::nanoseconds > timestamp
Optional timestamp of the measurement.
Definition telegrafAdapter.hpp:65
std::map< std::string, std::string > tags
Tags are indexed key–value pairs used for efficient filtering.
Definition telegrafAdapter.hpp:50
std::string table_name
Name of the table.
Definition telegrafAdapter.hpp:43
std::map< std::string, FieldValue > fields
Fields hold the measured data values.
Definition telegrafAdapter.hpp:57