11#include <unordered_map>
26 const std::map<std::string, std::string>& labels)
31 std::ostringstream oss;
32 oss <<
"[MONITORING] Counter: " << name <<
" = " << value;
37 for (
const auto& [key, val] : labels)
41 oss << key <<
"=" << val;
50 const std::map<std::string, std::string>& labels)
55 std::ostringstream oss;
56 oss <<
"[MONITORING] Gauge: " << name <<
" = " << value;
61 for (
const auto& [key, val] : labels)
65 oss << key <<
"=" << val;
74 const std::map<std::string, std::string>& labels)
79 std::ostringstream oss;
80 oss <<
"[MONITORING] Histogram: " << name <<
" = " << value;
85 for (
const auto& [key, val] : labels)
89 oss << key <<
"=" << val;
98 double response_time_ms,
size_t missed_heartbeats,
99 double packet_loss_rate)
104 std::ostringstream oss;
105 oss <<
"[MONITORING] Health: " << connection_id <<
" - alive=" << is_alive
106 <<
", response_time=" << response_time_ms <<
"ms"
107 <<
", missed_heartbeats=" << missed_heartbeats
108 <<
", packet_loss=" << (packet_loss_rate * 100.0) <<
"%";
121 : pimpl_(std::make_unique<
impl>(enable_logging))
128 const std::map<std::string, std::string>& labels)
134 const std::map<std::string, std::string>& labels)
140 const std::map<std::string, std::string>& labels)
146 double response_time_ms,
size_t missed_heartbeats,
147 double packet_loss_rate)
174 std::lock_guard<std::mutex> lock(
mutex_);
180 std::lock_guard<std::mutex> lock(
mutex_);
184 monitoring_ = std::make_shared<basic_monitoring>(
true);
195 : pimpl_(std::make_unique<
impl>())
208 std::shared_ptr<monitoring_interface> monitoring)
219 const std::string& name,
double value,
const std::map<std::string, std::string>& labels)
225 const std::string& name,
double value,
const std::map<std::string, std::string>& labels)
231 const std::string& name,
double value,
const std::map<std::string, std::string>& labels)
237 bool is_alive,
double response_time_ms,
238 size_t missed_heartbeats,
239 double packet_loss_rate)
241 get_monitoring()->report_health(connection_id, is_alive, response_time_ms,
242 missed_heartbeats, packet_loss_rate);
void report_gauge(const std::string &name, double value, const std::map< std::string, std::string > &labels)
void set_logging_enabled(bool enabled)
impl(bool enable_logging)
void report_health(const std::string &connection_id, bool is_alive, double response_time_ms, size_t missed_heartbeats, double packet_loss_rate)
void report_histogram(const std::string &name, double value, const std::map< std::string, std::string > &labels)
void report_counter(const std::string &name, double value, const std::map< std::string, std::string > &labels)
bool is_logging_enabled() const
void report_health(const std::string &connection_id, bool is_alive, double response_time_ms, size_t missed_heartbeats, double packet_loss_rate) override
Report connection health metrics.
~basic_monitoring() override
basic_monitoring(bool enable_logging=true)
Constructor.
void report_histogram(const std::string &name, double value, const std::map< std::string, std::string > &labels={}) override
Report a histogram metric.
std::unique_ptr< impl > pimpl_
void report_counter(const std::string &name, double value, const std::map< std::string, std::string > &labels={}) override
Report a counter metric.
void set_logging_enabled(bool enabled)
Enable or disable logging.
void report_gauge(const std::string &name, double value, const std::map< std::string, std::string > &labels={}) override
Report a gauge metric.
bool is_logging_enabled() const
Check if logging is enabled.
void set_monitoring(std::shared_ptr< monitoring_interface > monitoring)
std::shared_ptr< monitoring_interface > get_monitoring()
std::shared_ptr< monitoring_interface > monitoring_
Manager for monitoring system integration.
std::shared_ptr< monitoring_interface > get_monitoring()
Get the current monitoring implementation.
void report_health(const std::string &connection_id, bool is_alive, double response_time_ms, size_t missed_heartbeats, double packet_loss_rate)
Report connection health metrics.
~monitoring_integration_manager()
monitoring_integration_manager()
static monitoring_integration_manager & instance()
Get the singleton instance.
void report_histogram(const std::string &name, double value, const std::map< std::string, std::string > &labels={})
Report a histogram metric.
void set_monitoring(std::shared_ptr< monitoring_interface > monitoring)
Set the monitoring implementation.
void report_counter(const std::string &name, double value, const std::map< std::string, std::string > &labels={})
Report a counter metric.
void report_gauge(const std::string &name, double value, const std::map< std::string, std::string > &labels={})
Report a gauge metric.
std::unique_ptr< impl > pimpl_
std::atomic< bool > enabled
Logger system integration interface for network_system.
#define NETWORK_LOG_DEBUG(msg)
Monitoring system integration interface for network_system.