Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
Loading...
Searching...
No Matches
kcenon::logger::thread_system_monitor_adapter Class Reference

Adapter to use thread_system's monitoring capabilities. More...

#include <thread_system_monitor_adapter.h>

Inheritance diagram for kcenon::logger::thread_system_monitor_adapter:
Inheritance graph
Collaboration diagram for kcenon::logger::thread_system_monitor_adapter:
Collaboration graph

Public Member Functions

 thread_system_monitor_adapter (kcenon::thread::monitorable_interface *monitorable)
 Constructor with external monitorable.
 
 thread_system_monitor_adapter ()
 Default constructor with fallback to basic monitor.
 
 ~thread_system_monitor_adapter () override
 Destructor.
 
result< monitoring_datacollect_metrics () const override
 Collect current metrics.
 
result< health_check_resultcheck_health () const override
 Perform health check.
 
common::VoidResult reset_metrics () override
 Reset all metrics.
 
common::VoidResult set_enabled (bool enable) override
 Enable or disable monitoring.
 
bool is_enabled () const override
 Check if monitoring is enabled.
 
std::string get_backend_name () const override
 Get backend name.
 
void increment_counter (const std::string &name, double value=1.0) override
 Increment a counter.
 
void update_gauge (const std::string &name, double value) override
 Update a gauge.
 
void record_histogram (const std::string &name, double value) override
 Record a histogram value.
 
void set_monitorable (kcenon::thread::monitorable_interface *monitorable, bool take_ownership=false)
 Set the thread_system monitorable.
 
basic_monitorget_fallback_monitor ()
 Get the fallback monitor for direct access.
 
- Public Member Functions inherited from kcenon::logger::monitoring_interface
virtual ~monitoring_interface ()=default
 Virtual destructor.
 

Private Attributes

kcenon::thread::monitorable_interface * monitorable_
 
std::unique_ptr< basic_monitorfallback_monitor_
 
bool owns_monitorable_
 
std::atomic< bool > enabled_ {true}
 

Detailed Description

Adapter to use thread_system's monitoring capabilities.

This adapter wraps thread_system's monitorable_interface to provide compatibility with our monitoring interface, enabling advanced monitoring features when thread_system is available.

Definition at line 32 of file thread_system_monitor_adapter.h.

Constructor & Destructor Documentation

◆ thread_system_monitor_adapter() [1/2]

kcenon::logger::thread_system_monitor_adapter::thread_system_monitor_adapter ( kcenon::thread::monitorable_interface * monitorable)
inlineexplicit

Constructor with external monitorable.

Parameters
monitorablePointer to existing monitorable interface

Definition at line 44 of file thread_system_monitor_adapter.h.

46 : monitorable_(monitorable),
47 fallback_monitor_(std::make_unique<basic_monitor>()),
48 owns_monitorable_(false) {
49 if (!monitorable_) {
50 throw std::invalid_argument("Monitorable cannot be null");
51 }
52 }
kcenon::thread::monitorable_interface * monitorable_

References monitorable_.

◆ thread_system_monitor_adapter() [2/2]

kcenon::logger::thread_system_monitor_adapter::thread_system_monitor_adapter ( )
inline

Default constructor with fallback to basic monitor.

Definition at line 57 of file thread_system_monitor_adapter.h.

58 : monitorable_(nullptr),
59 fallback_monitor_(std::make_unique<basic_monitor>()),
60 owns_monitorable_(false) {}

◆ ~thread_system_monitor_adapter()

kcenon::logger::thread_system_monitor_adapter::~thread_system_monitor_adapter ( )
inlineoverride

Destructor.

Definition at line 65 of file thread_system_monitor_adapter.h.

65 {
67 delete monitorable_;
68 }
69 }

References monitorable_, and owns_monitorable_.

Member Function Documentation

◆ check_health()

result< health_check_result > kcenon::logger::thread_system_monitor_adapter::check_health ( ) const
inlineoverridevirtual

Perform health check.

Returns
Result containing health check result

Implements kcenon::logger::monitoring_interface.

Definition at line 123 of file thread_system_monitor_adapter.h.

123 {
124 health_check_result result;
125
126 // Check thread_system health if available
127 if (monitorable_) {
128 try {
129 auto ts_health = monitorable_->get_health_status();
130 if (ts_health) {
131 // Convert thread_system health to our format
132 auto status = ts_health.value();
133
134 if (!status.is_healthy()) {
135 result.set_status(health_status::degraded);
136 result.add_issue("Thread system reports unhealthy status");
137
138 for (const auto& issue : status.get_issues()) {
139 result.add_issue("Thread system: " + issue);
140 }
141 }
142 }
143 } catch (...) {
144 result.add_issue("Failed to check thread_system health");
145 }
146 }
147
148 // Also check fallback monitor for logger-specific health
149 if (fallback_monitor_) {
150 auto fallback_health = fallback_monitor_->check_health();
151 if (fallback_health) {
152 auto& fb_result = fallback_health.value();
153
154 // Merge health status
155 if (!fb_result.is_healthy()) {
156 if (result.get_status() == health_status::healthy) {
157 result.set_status(fb_result.get_status());
158 } else if (fb_result.get_status() == health_status::unhealthy) {
159 result.set_status(health_status::unhealthy);
160 }
161
162 // Add logger-specific issues
163 for (const auto& issue : fb_result.get_issues()) {
164 result.add_issue(issue);
165 }
166 }
167 }
168 }
169
170 // Set overall message
171 if (result.is_healthy()) {
172 result.set_message("All systems operational");
173 } else {
174 result.set_message("Issues detected in monitoring");
175 }
176
177 return result;
178 }

References fallback_monitor_, and monitorable_.

◆ collect_metrics()

result< monitoring_data > kcenon::logger::thread_system_monitor_adapter::collect_metrics ( ) const
inlineoverridevirtual

Collect current metrics.

Returns
Result containing monitoring data

Implements kcenon::logger::monitoring_interface.

Definition at line 75 of file thread_system_monitor_adapter.h.

75 {
76 if (!enabled_.load()) {
78 }
79
80 // Try thread_system first
81 if (monitorable_) {
82 try {
83 auto ts_metrics = monitorable_->get_metrics();
84 if (ts_metrics) {
85 // Convert thread_system metrics to our format
86 monitoring_data data;
87
88 // Extract metrics from thread_system monitoring_data
89 // Note: This assumes thread_system has similar metric structure
90 for (const auto& [key, value] : ts_metrics.value().get_values()) {
91 data.add_metric(key, value);
92 }
93
94 // Also add fallback monitor metrics for logger-specific data
96 auto fallback_result = fallback_monitor_->collect_metrics();
97 if (fallback_result) {
98 for (const auto& metric : fallback_result.value().get_metrics()) {
99 data.add_metric(metric);
100 }
101 }
102 }
103
104 return data;
105 }
106 } catch (...) {
107 // Fall through to fallback
108 }
109 }
110
111 // Fallback to basic monitor
112 if (fallback_monitor_) {
113 return fallback_monitor_->collect_metrics();
114 }
115
117 }

References kcenon::logger::monitoring_data::add_metric(), enabled_, fallback_monitor_, kcenon::logger::metrics_not_available, and monitorable_.

Here is the call graph for this function:

◆ get_backend_name()

std::string kcenon::logger::thread_system_monitor_adapter::get_backend_name ( ) const
inlineoverridevirtual

Get backend name.

Returns
"thread_system" or "thread_system+basic"

Implements kcenon::logger::monitoring_interface.

Definition at line 237 of file thread_system_monitor_adapter.h.

237 {
238 if (monitorable_) {
239 return "thread_system+basic";
240 }
241 return "basic(via adapter)";
242 }

References monitorable_.

◆ get_fallback_monitor()

basic_monitor * kcenon::logger::thread_system_monitor_adapter::get_fallback_monitor ( )
inline

Get the fallback monitor for direct access.

Returns
Pointer to fallback monitor

Definition at line 323 of file thread_system_monitor_adapter.h.

323 {
324 return fallback_monitor_.get();
325 }

References fallback_monitor_.

◆ increment_counter()

void kcenon::logger::thread_system_monitor_adapter::increment_counter ( const std::string & name,
double value = 1.0 )
inlineoverridevirtual

Increment a counter.

Parameters
nameCounter name
valueIncrement value

Implements kcenon::logger::monitoring_interface.

Definition at line 249 of file thread_system_monitor_adapter.h.

249 {
250 if (!enabled_.load()) return;
251
252 // Always use fallback for logger-specific counters
253 if (fallback_monitor_) {
254 fallback_monitor_->increment_counter(name, value);
255 }
256
257 // Also update thread_system if it supports this
258 if (monitorable_) {
259 try {
260 monitorable_->update_metric(name, value);
261 } catch (...) {
262 // Ignore failures
263 }
264 }
265 }

References enabled_, fallback_monitor_, and monitorable_.

◆ is_enabled()

bool kcenon::logger::thread_system_monitor_adapter::is_enabled ( ) const
inlineoverridevirtual

Check if monitoring is enabled.

Returns
true if enabled

Implements kcenon::logger::monitoring_interface.

Definition at line 229 of file thread_system_monitor_adapter.h.

229 {
230 return enabled_.load();
231 }

References enabled_.

◆ record_histogram()

void kcenon::logger::thread_system_monitor_adapter::record_histogram ( const std::string & name,
double value )
inlineoverridevirtual

Record a histogram value.

Parameters
nameHistogram name
valueValue to record

Implements kcenon::logger::monitoring_interface.

Definition at line 295 of file thread_system_monitor_adapter.h.

295 {
296 if (!enabled_.load()) return;
297
298 // Always use fallback for histograms
299 if (fallback_monitor_) {
300 fallback_monitor_->record_histogram(name, value);
301 }
302 }

References enabled_, and fallback_monitor_.

◆ reset_metrics()

common::VoidResult kcenon::logger::thread_system_monitor_adapter::reset_metrics ( )
inlineoverridevirtual

Reset all metrics.

Returns
Result indicating success

Implements kcenon::logger::monitoring_interface.

Definition at line 184 of file thread_system_monitor_adapter.h.

184 {
186
187 // Reset thread_system metrics if available
188 if (monitorable_) {
189 try {
190 auto ts_result = monitorable_->reset_metrics();
191 if (ts_result.is_err()) {
193 }
194 } catch (...) {
196 }
197 }
198
199 // Reset fallback monitor
200 if (fallback_monitor_) {
201 auto fb_result = fallback_monitor_->reset_metrics();
202 if (fb_result.is_err() && result.is_ok()) {
203 result = fb_result;
204 }
205 }
206
207 return result;
208 }
VoidResult ok()
common::VoidResult make_logger_void_result(logger_error_code code, const std::string &message="")

References fallback_monitor_, kcenon::logger::make_logger_void_result(), monitorable_, kcenon::common::ok(), and kcenon::logger::operation_failed.

Here is the call graph for this function:

◆ set_enabled()

common::VoidResult kcenon::logger::thread_system_monitor_adapter::set_enabled ( bool enable)
inlineoverridevirtual

Enable or disable monitoring.

Parameters
enabletrue to enable
Returns
Result indicating success

Implements kcenon::logger::monitoring_interface.

Definition at line 215 of file thread_system_monitor_adapter.h.

215 {
216 enabled_ = enable;
217
218 if (fallback_monitor_) {
219 fallback_monitor_->set_enabled(enable);
220 }
221
222 return common::ok();
223 }

References enabled_, fallback_monitor_, and kcenon::common::ok().

Here is the call graph for this function:

◆ set_monitorable()

void kcenon::logger::thread_system_monitor_adapter::set_monitorable ( kcenon::thread::monitorable_interface * monitorable,
bool take_ownership = false )
inline

Set the thread_system monitorable.

Parameters
monitorablePointer to monitorable interface
take_ownershipWhether to take ownership

Definition at line 309 of file thread_system_monitor_adapter.h.

310 {
312 delete monitorable_;
313 }
314
315 monitorable_ = monitorable;
316 owns_monitorable_ = take_ownership;
317 }

References monitorable_, and owns_monitorable_.

◆ update_gauge()

void kcenon::logger::thread_system_monitor_adapter::update_gauge ( const std::string & name,
double value )
inlineoverridevirtual

Update a gauge.

Parameters
nameGauge name
valueNew value

Implements kcenon::logger::monitoring_interface.

Definition at line 272 of file thread_system_monitor_adapter.h.

272 {
273 if (!enabled_.load()) return;
274
275 // Always use fallback for logger-specific gauges
276 if (fallback_monitor_) {
277 fallback_monitor_->update_gauge(name, value);
278 }
279
280 // Also update thread_system if it supports this
281 if (monitorable_) {
282 try {
283 monitorable_->update_metric(name, value);
284 } catch (...) {
285 // Ignore failures
286 }
287 }
288 }

References enabled_, fallback_monitor_, and monitorable_.

Member Data Documentation

◆ enabled_

std::atomic<bool> kcenon::logger::thread_system_monitor_adapter::enabled_ {true}
private

◆ fallback_monitor_

std::unique_ptr<basic_monitor> kcenon::logger::thread_system_monitor_adapter::fallback_monitor_
private

◆ monitorable_

kcenon::thread::monitorable_interface* kcenon::logger::thread_system_monitor_adapter::monitorable_
private

◆ owns_monitorable_

bool kcenon::logger::thread_system_monitor_adapter::owns_monitorable_
private

The documentation for this class was generated from the following file: