Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
kcenon::monitoring::logger_to_monitoring_adapter Class Reference

Logger system adapter using dependency injection (Phase 2.3.3) More...

#include <logger_to_monitoring_adapter.h>

Collaboration diagram for kcenon::monitoring::logger_to_monitoring_adapter:
Collaboration graph

Public Member Functions

 logger_to_monitoring_adapter (std::shared_ptr< event_bus > bus, std::shared_ptr< common::interfaces::ILogger > logger=nullptr)
 Constructor with optional logger injection.
 
bool is_logger_system_available () const
 Check if logger is available.
 
void set_logger (std::shared_ptr< common::interfaces::ILogger > logger)
 Set or replace the logger instance.
 
std::shared_ptr< common::interfaces::ILogger > get_logger () const
 Get the current logger instance.
 
common::Result< std::vector< metric > > collect_metrics ()
 Collect metrics from logger if available (Phase 2.3.3)
 
common::VoidResult register_logger (const std::string &)
 Register a logger instance by name.
 
double get_current_log_rate () const
 Get current log rate (if logger supports metrics)
 

Private Attributes

std::shared_ptr< event_busbus_
 
std::shared_ptr< common::interfaces::ILogger > logger_
 

Detailed Description

Logger system adapter using dependency injection (Phase 2.3.3)

This adapter uses common::interfaces::ILogger instead of concrete logger_system classes, removing compile-time dependency on logger_system. Works with any ILogger implementation through dependency injection.

Examples
event_bus_example.cpp.

Definition at line 48 of file logger_to_monitoring_adapter.h.

Constructor & Destructor Documentation

◆ logger_to_monitoring_adapter()

kcenon::monitoring::logger_to_monitoring_adapter::logger_to_monitoring_adapter ( std::shared_ptr< event_bus > bus,
std::shared_ptr< common::interfaces::ILogger > logger = nullptr )
inlineexplicit

Constructor with optional logger injection.

Parameters
busEvent bus for monitoring events
loggerOptional logger instance (any ILogger implementation)

Definition at line 55 of file logger_to_monitoring_adapter.h.

58 : bus_(std::move(bus)), logger_(std::move(logger)) {}
std::shared_ptr< common::interfaces::ILogger > logger_

Member Function Documentation

◆ collect_metrics()

common::Result< std::vector< metric > > kcenon::monitoring::logger_to_monitoring_adapter::collect_metrics ( )
inline

Collect metrics from logger if available (Phase 2.3.3)

Definition at line 85 of file logger_to_monitoring_adapter.h.

85 {
86 std::vector<metric> out;
87 if (logger_) {
88 // If logger implements IMonitorable, collect its metrics
89 auto monitorable = std::dynamic_pointer_cast<common::interfaces::IMonitorable>(logger_);
90 if (monitorable) {
91 auto metrics_result = monitorable->get_monitoring_data();
92 if (metrics_result.is_ok()) {
93 const auto& snapshot = metrics_result.value();
94 // Convert to monitoring_system metric format
95 for (const auto& m : snapshot.metrics) {
96 metric converted;
97 converted.name = m.name;
98 converted.value = m.value;
99 converted.timestamp = m.timestamp;
100 out.push_back(converted);
101 }
102 }
103 }
104 }
105 return common::ok(std::move(out));
106 }

References logger_, kcenon::monitoring::metric::name, kcenon::monitoring::metric::timestamp, and kcenon::monitoring::metric::value.

Referenced by TEST_F().

Here is the caller graph for this function:

◆ get_current_log_rate()

double kcenon::monitoring::logger_to_monitoring_adapter::get_current_log_rate ( ) const
inline

Get current log rate (if logger supports metrics)

Definition at line 119 of file logger_to_monitoring_adapter.h.

119 {
120 if (logger_) {
121 auto monitorable = std::dynamic_pointer_cast<common::interfaces::IMonitorable>(logger_);
122 if (monitorable) {
123 auto metrics_result = monitorable->get_monitoring_data();
124 if (metrics_result.is_ok()) {
125 const auto& snapshot = metrics_result.value();
126 for (const auto& m : snapshot.metrics) {
127 if (m.name.find("messages_logged") != std::string::npos ||
128 m.name.find("log_rate") != std::string::npos) {
129 return m.value;
130 }
131 }
132 }
133 }
134 }
135 return 0.0;
136 }

References logger_.

Referenced by TEST_F().

Here is the caller graph for this function:

◆ get_logger()

std::shared_ptr< common::interfaces::ILogger > kcenon::monitoring::logger_to_monitoring_adapter::get_logger ( ) const
inline

Get the current logger instance.

Definition at line 78 of file logger_to_monitoring_adapter.h.

78 {
79 return logger_;
80 }

References logger_.

◆ is_logger_system_available()

bool kcenon::monitoring::logger_to_monitoring_adapter::is_logger_system_available ( ) const
inline

Check if logger is available.

Examples
event_bus_example.cpp.

Definition at line 63 of file logger_to_monitoring_adapter.h.

63 {
64 return logger_ != nullptr;
65 }

References logger_.

Referenced by main(), and TEST_F().

Here is the caller graph for this function:

◆ register_logger()

common::VoidResult kcenon::monitoring::logger_to_monitoring_adapter::register_logger ( const std::string & )
inline

Register a logger instance by name.

Definition at line 111 of file logger_to_monitoring_adapter.h.

111 {
112 // Logger is now provided via DI, not registered by name
113 return common::ok();
114 }

Referenced by TEST_F().

Here is the caller graph for this function:

◆ set_logger()

void kcenon::monitoring::logger_to_monitoring_adapter::set_logger ( std::shared_ptr< common::interfaces::ILogger > logger)
inline

Set or replace the logger instance.

Parameters
loggerNew logger instance

Definition at line 71 of file logger_to_monitoring_adapter.h.

71 {
72 logger_ = std::move(logger);
73 }

References logger_.

Member Data Documentation

◆ bus_

std::shared_ptr<event_bus> kcenon::monitoring::logger_to_monitoring_adapter::bus_
private

Definition at line 139 of file logger_to_monitoring_adapter.h.

◆ logger_

std::shared_ptr<common::interfaces::ILogger> kcenon::monitoring::logger_to_monitoring_adapter::logger_
private

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