Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
event_types.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2021-2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
5#pragma once
6
15#include <chrono>
16#include <cstdint>
17#include <optional>
18#include <string>
19#include <unordered_map>
20#include <variant>
21#include <vector>
24
25namespace kcenon { namespace monitoring {
26
50public:
52 size_t active_threads{0};
53 size_t idle_threads{0};
54 size_t queued_tasks{0};
55 size_t completed_tasks{0};
56 double cpu_usage_percent{0.0};
57 std::chrono::milliseconds avg_task_duration{0};
58 };
59
60 thread_pool_metric_event(const std::string& pool_name, const thread_pool_stats& stats)
61 : pool_name_(pool_name), stats_(stats) {}
62
63 std::string get_type_name() const override {
64 return "thread_pool_metric_event";
65 }
66
67 const std::string& get_pool_name() const { return pool_name_; }
68 const thread_pool_stats& get_stats() const { return stats_; }
69
70private:
71 std::string pool_name_;
73};
74
80public:
82 uint64_t total_logs{0};
83 uint64_t error_count{0};
84 uint64_t warning_count{0};
85 uint64_t info_count{0};
86 uint64_t debug_count{0};
88 double logs_per_second{0.0};
89 };
90
91 logging_metric_event(const std::string& logger_name, const logging_stats& stats)
92 : logger_name_(logger_name), stats_(stats) {}
93
94 std::string get_type_name() const override {
95 return "logging_metric_event";
96 }
97
98 const std::string& get_logger_name() const { return logger_name_; }
99 const logging_stats& get_stats() const { return stats_; }
100
101private:
102 std::string logger_name_;
104};
105
111public:
113 double cpu_usage_percent{0.0};
114 uint64_t memory_used_bytes{0};
116 uint64_t disk_used_bytes{0};
117 uint64_t disk_total_bytes{0};
118 uint64_t network_rx_bytes{0};
119 uint64_t network_tx_bytes{0};
120 size_t process_count{0};
121 size_t thread_count{0};
122 };
123
125 : stats_(stats) {}
126
127 std::string get_type_name() const override {
128 return "system_resource_event";
129 }
130
131 const resource_stats& get_stats() const { return stats_; }
132
133private:
135};
136
163public:
164 enum class alert_severity {
165 info,
166 warning,
168 };
169
178
180 const std::string& component,
181 const std::string& message,
182 std::optional<double> threshold = std::nullopt,
183 std::optional<double> actual_value = std::nullopt)
184 : type_(type), severity_(severity), component_(component),
185 message_(message), threshold_(threshold), actual_value_(actual_value) {}
186
187 std::string get_type_name() const override {
188 return "performance_alert_event";
189 }
190
191 alert_type get_alert_type() const { return type_; }
193 const std::string& get_component() const { return component_; }
194 const std::string& get_message() const { return message_; }
195 std::optional<double> get_threshold() const { return threshold_; }
196 std::optional<double> get_actual_value() const { return actual_value_; }
197
198private:
201 std::string component_;
202 std::string message_;
203 std::optional<double> threshold_;
204 std::optional<double> actual_value_;
205};
206
212public:
213 enum class change_type {
214 added,
215 modified,
216 removed
217 };
218
219 configuration_change_event(const std::string& component,
220 const std::string& config_key,
221 change_type type,
222 const std::string& old_value = "",
223 const std::string& new_value = "")
224 : component_(component), config_key_(config_key),
225 type_(type), old_value_(old_value), new_value_(new_value) {}
226
227 std::string get_type_name() const override {
228 return "configuration_change_event";
229 }
230
231 const std::string& get_component() const { return component_; }
232 const std::string& get_config_key() const { return config_key_; }
234 const std::string& get_old_value() const { return old_value_; }
235 const std::string& get_new_value() const { return new_value_; }
236
237private:
238 std::string component_;
239 std::string config_key_;
241 std::string old_value_;
242 std::string new_value_;
243};
244
250public:
251 enum class lifecycle_state {
253 started,
254 running,
255 pausing,
256 paused,
257 resuming,
258 stopping,
259 stopped,
260 error
261 };
262
263 component_lifecycle_event(const std::string& component,
264 lifecycle_state old_state,
265 lifecycle_state new_state,
266 const std::string& reason = "")
267 : component_(component), old_state_(old_state),
268 new_state_(new_state), reason_(reason) {}
269
270 std::string get_type_name() const override {
271 return "component_lifecycle_event";
272 }
273
274 const std::string& get_component() const { return component_; }
277 const std::string& get_reason() const { return reason_; }
278
279private:
280 std::string component_;
283 std::string reason_;
284};
285
291public:
292 metric_collection_event(const std::string& collector_name,
293 std::vector<metric> metrics)
294 : collector_name_(collector_name), metrics_(std::move(metrics)) {}
295
296 std::string get_type_name() const override {
297 return "metric_collection_event";
298 }
299
300 const std::string& get_collector_name() const { return collector_name_; }
301 const std::vector<metric>& get_metrics() const { return metrics_; }
302 size_t get_metric_count() const { return metrics_.size(); }
303
304private:
305 std::string collector_name_;
306 std::vector<metric> metrics_;
307};
308
314public:
315 enum class health_status {
316 healthy,
317 degraded,
318 unhealthy,
319 unknown
320 };
321
323 std::string check_name;
325 std::string message;
326 std::chrono::milliseconds response_time;
327 std::optional<std::unordered_map<std::string, std::string>> metadata;
328 };
329
330 health_check_event(const std::string& component,
331 std::vector<health_check_result> results)
332 : component_(component), results_(std::move(results)) {}
333
334 std::string get_type_name() const override {
335 return "health_check_event";
336 }
337
338 const std::string& get_component() const { return component_; }
339 const std::vector<health_check_result>& get_results() const { return results_; }
340
343 for (const auto& result : results_) {
344 if (result.status == health_status::unhealthy) {
346 }
347 if (result.status == health_status::degraded) {
348 overall = health_status::degraded;
349 }
350 if (result.status == health_status::unknown && overall == health_status::healthy) {
351 overall = health_status::unknown;
352 }
353 }
354 return overall;
355 }
356
357private:
358 std::string component_;
359 std::vector<health_check_result> results_;
360};
361
362} } // namespace kcenon::monitoring
Event for component lifecycle changes.
const std::string & get_component() const
component_lifecycle_event(const std::string &component, lifecycle_state old_state, lifecycle_state new_state, const std::string &reason="")
std::string get_type_name() const override
Get the event type name.
Event fired when configuration changes.
const std::string & get_config_key() const
std::string get_type_name() const override
Get the event type name.
configuration_change_event(const std::string &component, const std::string &config_key, change_type type, const std::string &old_value="", const std::string &new_value="")
const std::string & get_new_value() const
const std::string & get_component() const
const std::string & get_old_value() const
Base class for all events in the system.
Event for health check results.
health_status get_overall_status() const
std::string get_type_name() const override
Get the event type name.
const std::string & get_component() const
std::vector< health_check_result > results_
const std::vector< health_check_result > & get_results() const
health_check_event(const std::string &component, std::vector< health_check_result > results)
Event containing logging system metrics.
Definition event_types.h:79
std::string get_type_name() const override
Get the event type name.
Definition event_types.h:94
const logging_stats & get_stats() const
Definition event_types.h:99
logging_metric_event(const std::string &logger_name, const logging_stats &stats)
Definition event_types.h:91
const std::string & get_logger_name() const
Definition event_types.h:98
Event containing collected metrics batch.
const std::vector< metric > & get_metrics() const
const std::string & get_collector_name() const
metric_collection_event(const std::string &collector_name, std::vector< metric > metrics)
std::string get_type_name() const override
Get the event type name.
Event for performance-related alerts.
const std::string & get_component() const
std::string get_type_name() const override
Get the event type name.
std::optional< double > get_actual_value() const
performance_alert_event(alert_type type, alert_severity severity, const std::string &component, const std::string &message, std::optional< double > threshold=std::nullopt, std::optional< double > actual_value=std::nullopt)
std::optional< double > get_threshold() const
const std::string & get_message() const
Event containing system resource metrics.
std::string get_type_name() const override
Get the event type name.
system_resource_event(const resource_stats &stats)
const resource_stats & get_stats() const
Event containing thread pool metrics.
Definition event_types.h:49
const thread_pool_stats & get_stats() const
Definition event_types.h:68
std::string get_type_name() const override
Get the event type name.
Definition event_types.h:63
const std::string & get_pool_name() const
Definition event_types.h:67
thread_pool_metric_event(const std::string &pool_name, const thread_pool_stats &stats)
Definition event_types.h:60
Event bus interface for decoupled component communication.
Adapter for metric types to support interface definitions.
std::optional< std::unordered_map< std::string, std::string > > metadata