Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
monitoring_integration.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
5#pragma once
6#ifndef KCENON_NETWORK_INTERNAL_INTEGRATION_MONITORING_INTEGRATION_H_
7#define KCENON_NETWORK_INTERNAL_INTEGRATION_MONITORING_INTEGRATION_H_
8
24#include <map>
25#include <memory>
26#include <string>
27
29
31{
32
37 enum class metric_type
38 {
39 counter,
40 gauge,
41 histogram,
42 summary
43 };
44
52 class monitoring_interface
53 {
54 public:
55 virtual ~monitoring_interface() = default;
56
63 virtual void report_counter(const std::string& name, double value,
64 const std::map<std::string, std::string>& labels = {}) = 0;
65
72 virtual void report_gauge(const std::string& name, double value,
73 const std::map<std::string, std::string>& labels = {}) = 0;
74
81 virtual void report_histogram(const std::string& name, double value,
82 const std::map<std::string, std::string>& labels = {}) = 0;
83
92 virtual void report_health(const std::string& connection_id, bool is_alive,
93 double response_time_ms, size_t missed_heartbeats,
94 double packet_loss_rate) = 0;
95 };
96
105 {
106 public:
111 explicit basic_monitoring(bool enable_logging = true);
112
114
115 // monitoring_interface implementation
116 void report_counter(const std::string& name, double value,
117 const std::map<std::string, std::string>& labels = {}) override;
118
119 void report_gauge(const std::string& name, double value,
120 const std::map<std::string, std::string>& labels = {}) override;
121
122 void report_histogram(const std::string& name, double value,
123 const std::map<std::string, std::string>& labels = {}) override;
124
125 void report_health(const std::string& connection_id, bool is_alive,
126 double response_time_ms, size_t missed_heartbeats,
127 double packet_loss_rate) override;
128
133 void set_logging_enabled(bool enabled);
134
139 bool is_logging_enabled() const;
140
141 private:
142 class impl;
143 std::unique_ptr<impl> pimpl_;
144 };
145
146 // Note: monitoring_system_adapter has been removed in favor of EventBus-based
147 // metric publishing. See issue #342 for details.
148 //
149 // External consumers (like monitoring_system) should subscribe to
150 // network_metric_event via common_system's EventBus:
151 //
152 // auto& bus = common::get_event_bus();
153 // bus.subscribe<network::events::network_metric_event>(
154 // [](const auto& event) { /* process metric */ }
155 // );
156
165 {
166 public:
172
177 void set_monitoring(std::shared_ptr<monitoring_interface> monitoring);
178
183 std::shared_ptr<monitoring_interface> get_monitoring();
184
191 void report_counter(const std::string& name, double value,
192 const std::map<std::string, std::string>& labels = {});
193
200 void report_gauge(const std::string& name, double value,
201 const std::map<std::string, std::string>& labels = {});
202
209 void report_histogram(const std::string& name, double value,
210 const std::map<std::string, std::string>& labels = {});
211
220 void report_health(const std::string& connection_id, bool is_alive,
221 double response_time_ms, size_t missed_heartbeats,
222 double packet_loss_rate);
223
224 private:
227
228 class impl;
229 std::unique_ptr<impl> pimpl_;
230 };
231
232} // namespace kcenon::network::integration
233
234// Backward compatibility namespace alias is defined in thread_integration.h
235
236#endif // KCENON_NETWORK_INTERNAL_INTEGRATION_MONITORING_INTEGRATION_H_
Basic monitoring implementation for standalone use.
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(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.
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.
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.
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.
Interface for monitoring integration.
Definition core.cppm:147
virtual void report_counter(const std::string &name, double value, const std::map< std::string, std::string > &labels={})=0
Report a counter metric.
virtual void report_health(const std::string &connection_id, bool is_alive, double response_time_ms, size_t missed_heartbeats, double packet_loss_rate)=0
Report connection health metrics.
virtual void report_histogram(const std::string &name, double value, const std::map< std::string, std::string > &labels={})=0
Report a histogram metric.
virtual void report_gauge(const std::string &name, double value, const std::map< std::string, std::string > &labels={})=0
Report a gauge metric.
std::atomic< bool > enabled
Definition exporters.cpp:28
metric_type
Types of metrics supported.
Thread system integration interface for network_system.