RTC Toolkit 6.0.0-pre2
Loading...
Searching...
No Matches
componentMetrics.hpp
Go to the documentation of this file.
1
12#ifndef RTCTK_COMPONENTFRAMEWORK_COMPONENTMETRICS_HPP
13#define RTCTK_COMPONENTFRAMEWORK_COMPONENTMETRICS_HPP
14
15#include <condition_variable>
16#include <optional>
17#include <thread>
18
19#include <log4cplus/logger.h>
20
24
26
27class RepositoryIf;
28class OldbIf;
29class RuntimeRepoIf;
30
45public:
48
53 struct Parameters {
54 std::chrono::milliseconds counter_poll_interval = std::chrono::milliseconds(5000);
55 int thread_nice = 5;
56 };
57
66 explicit ComponentMetrics(OldbIf& oldb,
67 DataPointPath oldb_root,
68 RuntimeRepoIf& rtr,
69 DataPointPath rtr_root,
70 log4cplus::Logger logger,
71 TelegrafAdapter* telegraf_adapter = nullptr);
75 ~ComponentMetrics() noexcept override;
76
77 void StartMonitoring() override;
78 void StopMonitoring() noexcept override;
79 bool IsMonitoring() noexcept override;
80 void UpdateParams() override;
82
83 [[nodiscard]] perfc::ScopedRegistration
84 AddCounter(CounterVariant counter, CounterMetricInfo info) override;
85 bool RemoveCounter(CounterVariant counter) override;
86
87private:
88 struct MonitoringThread {
89 MonitoringThread(std::thread t) : thread(std::move(t)) {
90 }
94 bool stop_flag = false;
98 pid_t id = 0;
99 std::thread thread;
100 };
101
108 void MonitoringLoop();
109
113 OldbIf& m_oldb;
114 DataPointPath m_oldb_root;
115
119 RuntimeRepoIf& m_rtr;
120 DataPointPath m_rtr_root;
121
129 std::recursive_mutex m_api_mtx;
130
136 std::mutex m_mon_mtx;
137
142 std::condition_variable m_cond;
143
147 Parameters m_params;
148
149 perfc::Register<CounterTypes, CounterMetricInfo> m_counters;
150 std::optional<MonitoringThread> m_monitoring_thread;
151 log4cplus::Logger m_logger;
152 TelegrafAdapter* m_telegraf_adapter;
153};
154
155} // namespace rtctk::componentFramework
156
157#endif // RTCTK_COMPONENTFRAMEWORK_COMPONENTMETRICS_HPP
Component metrics interface.
Definition componentMetricsIf.hpp:164
typename CounterTypes::CounterVariant CounterVariant
std::variant of pointers to each supported type in CounterTypes.
Definition componentMetricsIf.hpp:221
perfc::CounterTypes< perfc::CounterDouble, perfc::CounterU64, perfc::CounterI64 > CounterTypes
Defines standard performance counter types:
Definition componentMetricsIf.hpp:214
typename CounterTypes::CounterVariant CounterVariant
std::variant of pointers to each supported type in CounterTypes.
Definition componentMetricsIf.hpp:221
void StopMonitoring() noexcept override
Stop monitoring.
Definition componentMetrics.cpp:235
Parameters GetParams()
Definition componentMetrics.cpp:291
bool RemoveCounter(CounterVariant counter) override
Remove counter from register.
Definition componentMetrics.cpp:341
perfc::ScopedRegistration AddCounter(CounterVariant counter, CounterMetricInfo info) override
Add a counter to be included in component metrics, identified by its address, together with info to t...
Definition componentMetrics.cpp:296
bool IsMonitoring() noexcept override
Query whether monitoring is active.
Definition componentMetrics.cpp:251
~ComponentMetrics() noexcept override
Destructor will automatically stop monitoring.
Definition componentMetrics.cpp:202
void StartMonitoring() override
Start monitoring and publishing metrics.
Definition componentMetrics.cpp:206
ComponentMetrics(OldbIf &oldb, DataPointPath oldb_root, RuntimeRepoIf &rtr, DataPointPath rtr_root, log4cplus::Logger logger, TelegrafAdapter *telegraf_adapter=nullptr)
Definition componentMetrics.cpp:187
void UpdateParams() override
Reloads parameters.
Definition componentMetrics.cpp:257
Defines auxiliary information associated with each counter registered with ComponentMetricsIf.
Definition componentMetricsIf.hpp:49
This class provides a wrapper for a data point path.
Definition dataPointPath.hpp:77
Base interface for all OLDB adapters.
Definition oldbIf.hpp:25
Abstract interface providing basic read and write facilities to a repository.
Definition repositoryIf.hpp:51
Base interface for all Runtime Configuration Repository adapters.
Definition runtimeRepoIf.hpp:27
Implementation of the Telegraf Adapter.
Definition telegrafAdapter.hpp:93
Header file for ComponentMetricsIf.
Header file for DataPointPath.
Definition commandReplier.cpp:22
Definition ddsSub.hpp:156
Runtime parameters.
Definition componentMetrics.hpp:53
int thread_nice
Definition componentMetrics.hpp:55
std::chrono::milliseconds counter_poll_interval
Definition componentMetrics.hpp:54
Header file needed to instantiate an TelegrafAdapter.