RTC Toolkit 6.0.0
Loading...
Searching...
No Matches
componentMetrics.hpp
Go to the documentation of this file.
1
11#ifndef RTCTK_COMPONENTFRAMEWORK_COMPONENTMETRICS_HPP
12#define RTCTK_COMPONENTFRAMEWORK_COMPONENTMETRICS_HPP
13
14#include <condition_variable>
15#include <optional>
16#include <thread>
17
18#include <log4cplus/logger.h>
19
23
25
26class RepositoryIf;
27class OldbIf;
28class RuntimeRepoIf;
29
44public:
47
52 struct Parameters {
53 std::chrono::milliseconds counter_poll_interval = std::chrono::milliseconds(5000);
54 int thread_nice = 5;
55 };
56
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 explicit 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:163
typename CounterTypes::CounterVariant CounterVariant
std::variant of pointers to each supported type in CounterTypes.
Definition componentMetricsIf.hpp:220
perfc::CounterTypes< perfc::CounterDouble, perfc::CounterU64, perfc::CounterI64 > CounterTypes
Defines standard performance counter types:
Definition componentMetricsIf.hpp:213
typename CounterTypes::CounterVariant CounterVariant
std::variant of pointers to each supported type in CounterTypes.
Definition componentMetricsIf.hpp:220
void StopMonitoring() noexcept override
Stop monitoring.
Definition componentMetrics.cpp:234
Parameters GetParams()
Definition componentMetrics.cpp:290
bool RemoveCounter(CounterVariant counter) override
Remove counter from register.
Definition componentMetrics.cpp:340
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:295
bool IsMonitoring() noexcept override
Query whether monitoring is active.
Definition componentMetrics.cpp:250
~ComponentMetrics() noexcept override
Destructor will automatically stop monitoring.
Definition componentMetrics.cpp:201
void StartMonitoring() override
Start monitoring and publishing metrics.
Definition componentMetrics.cpp:205
ComponentMetrics(OldbIf &oldb, DataPointPath oldb_root, RuntimeRepoIf &rtr, DataPointPath rtr_root, log4cplus::Logger logger, TelegrafAdapter *telegraf_adapter=nullptr)
Construct new metrics object.
Definition componentMetrics.cpp:186
void UpdateParams() override
Reloads parameters.
Definition componentMetrics.cpp:256
Defines auxiliary information associated with each counter registered with ComponentMetricsIf.
Definition componentMetricsIf.hpp:48
This class provides a wrapper for a data point path.
Definition dataPointPath.hpp:76
Base interface for all OLDB adapters.
Definition oldbIf.hpp:24
Abstract interface providing basic read and write facilities to a repository.
Definition repositoryIf.hpp:50
Base interface for all Runtime Configuration Repository adapters.
Definition runtimeRepoIf.hpp:26
Implementation of the Telegraf Adapter.
Definition telegrafAdapter.hpp:93
Header file for ComponentMetricsIf.
Header file for DataPointPath.
Definition commandReplier.cpp:21
Definition ddsSub.hpp:155
Runtime parameters.
Definition componentMetrics.hpp:52
int thread_nice
Definition componentMetrics.hpp:54
std::chrono::milliseconds counter_poll_interval
Definition componentMetrics.hpp:53
Header file needed to instantiate an TelegrafAdapter.