|
Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
|
Central coordinator for the alert pipeline. More...
#include <alert_manager.h>

Public Types | |
| using | metric_provider_func = std::function<std::optional<double>(const std::string&)> |
Public Member Functions | |
| alert_manager () | |
| Default constructor. | |
| alert_manager (const alert_manager_config &config) | |
| Construct with configuration. | |
| ~alert_manager () | |
| Destructor. | |
| alert_manager (const alert_manager &)=delete | |
| alert_manager & | operator= (const alert_manager &)=delete |
| alert_manager (alert_manager &&)=delete | |
| alert_manager & | operator= (alert_manager &&)=delete |
| common::VoidResult | start () |
| Start the alert manager. | |
| common::VoidResult | stop () |
| Stop the alert manager. | |
| bool | is_running () const |
| Check if manager is running. | |
| common::VoidResult | add_rule (std::shared_ptr< alert_rule > rule) |
| Add an alert rule. | |
| common::VoidResult | remove_rule (const std::string &rule_name) |
| Remove an alert rule. | |
| std::shared_ptr< alert_rule > | get_rule (const std::string &rule_name) const |
| Get a rule by name. | |
| std::vector< std::shared_ptr< alert_rule > > | get_rules () const |
| Get all rules. | |
| common::VoidResult | add_rule_group (std::shared_ptr< alert_rule_group > group) |
| Add a rule group. | |
| common::VoidResult | process_metric (const std::string &metric_name, double value) |
| Process a metric value. | |
| common::VoidResult | process_metrics (const std::unordered_map< std::string, double > &metrics) |
| Process a batch of metrics. | |
| std::vector< alert > | get_active_alerts () const |
| Get all active alerts. | |
| std::optional< alert > | get_alert (const std::string &fingerprint) const |
| Get alert by fingerprint. | |
| common::VoidResult | resolve_alert (const std::string &fingerprint) |
| Resolve an alert manually. | |
| common::Result< uint64_t > | create_silence (const alert_silence &silence) |
| Create a silence. | |
| common::VoidResult | delete_silence (uint64_t silence_id) |
| Delete a silence. | |
| std::vector< alert_silence > | get_silences () const |
| Get all active silences. | |
| bool | is_silenced (const alert &a) const |
| Check if an alert is silenced. | |
| common::VoidResult | add_notifier (std::shared_ptr< alert_notifier > notifier) |
| Add a notifier. | |
| common::VoidResult | remove_notifier (const std::string ¬ifier_name) |
| Remove a notifier. | |
| std::vector< std::shared_ptr< alert_notifier > > | get_notifiers () const |
| Get all notifiers. | |
| void | set_metric_provider (metric_provider_func provider) |
| Set the metric provider function. | |
| void | set_event_bus (std::shared_ptr< interface_event_bus > event_bus) |
| Set event bus for publishing alert events. | |
| alert_manager_metrics | get_metrics () const |
| Get manager metrics. | |
| const alert_manager_config & | config () const |
| Get configuration. | |
Private Member Functions | |
| void | evaluation_loop () |
| Main evaluation loop. | |
| void | evaluate_rule (const std::shared_ptr< alert_rule > &rule, double value) |
| Evaluate a single rule. | |
| void | update_alert_state (const std::string &fingerprint, bool condition_met, double value, const std::shared_ptr< alert_rule > &rule) |
| Update alert state. | |
| void | send_notifications (const alert &a) |
| Send notifications for an alert. | |
| void | cleanup_silences () |
| Clean up expired silences. | |
| void | cleanup_resolved_alerts () |
| Clean up resolved alerts. | |
Private Attributes | |
| alert_manager_config | config_ |
| std::mutex | rules_mutex_ |
| std::unordered_map< std::string, std::shared_ptr< alert_rule > > | rules_ |
| std::vector< std::shared_ptr< alert_rule_group > > | rule_groups_ |
| std::mutex | alerts_mutex_ |
| std::unordered_map< std::string, alert > | alerts_ |
| std::mutex | silences_mutex_ |
| std::unordered_map< uint64_t, alert_silence > | silences_ |
| std::mutex | notifiers_mutex_ |
| std::vector< std::shared_ptr< alert_notifier > > | notifiers_ |
| std::mutex | provider_mutex_ |
| metric_provider_func | metric_provider_ |
| std::shared_ptr< interface_event_bus > | event_bus_ |
| alert_manager_metrics | metrics_ |
| std::atomic< bool > | running_ {false} |
| std::thread | evaluation_thread_ |
| std::condition_variable | cv_ |
| std::mutex | cv_mutex_ |
| std::unordered_map< std::string, std::chrono::steady_clock::time_point > | last_notification_times_ |
Central coordinator for the alert pipeline.
The alert manager is responsible for:
Definition at line 122 of file alert_manager.h.
| using kcenon::monitoring::alert_manager::metric_provider_func = std::function<std::optional<double>(const std::string&)> |
Definition at line 124 of file alert_manager.h.
| kcenon::monitoring::alert_manager::alert_manager | ( | ) |
Default constructor.
|
explicit |
Construct with configuration.
| config | Manager configuration |
| kcenon::monitoring::alert_manager::~alert_manager | ( | ) |
|
delete |
|
delete |
| common::VoidResult kcenon::monitoring::alert_manager::add_notifier | ( | std::shared_ptr< alert_notifier > | notifier | ) |
Add a notifier.
| notifier | Notifier to add |
Referenced by main().

| common::VoidResult kcenon::monitoring::alert_manager::add_rule | ( | std::shared_ptr< alert_rule > | rule | ) |
Add an alert rule.
| rule | Rule to add |
Referenced by main(), AlertManagerProcessingTest::SetUp(), and TEST().

| common::VoidResult kcenon::monitoring::alert_manager::add_rule_group | ( | std::shared_ptr< alert_rule_group > | group | ) |
Add a rule group.
| group | Rule group to add |
Referenced by main(), and TEST().

|
private |
Clean up resolved alerts.
|
private |
Clean up expired silences.
| const alert_manager_config & kcenon::monitoring::alert_manager::config | ( | ) | const |
| common::Result< uint64_t > kcenon::monitoring::alert_manager::create_silence | ( | const alert_silence & | silence | ) |
Create a silence.
| silence | Silence configuration |
| common::VoidResult kcenon::monitoring::alert_manager::delete_silence | ( | uint64_t | silence_id | ) |
Delete a silence.
| silence_id | Silence ID |
|
private |
Evaluate a single rule.
| rule | Rule to evaluate |
| value | Metric value |
|
private |
Main evaluation loop.
| std::vector< alert > kcenon::monitoring::alert_manager::get_active_alerts | ( | ) | const |
Get all active alerts.
Referenced by main(), and print_active_alerts().

| std::optional< alert > kcenon::monitoring::alert_manager::get_alert | ( | const std::string & | fingerprint | ) | const |
Get alert by fingerprint.
| fingerprint | Alert fingerprint |
| alert_manager_metrics kcenon::monitoring::alert_manager::get_metrics | ( | ) | const |
Get manager metrics.
Referenced by main(), TEST(), and TEST().

| std::vector< std::shared_ptr< alert_notifier > > kcenon::monitoring::alert_manager::get_notifiers | ( | ) | const |
Get all notifiers.
| std::shared_ptr< alert_rule > kcenon::monitoring::alert_manager::get_rule | ( | const std::string & | rule_name | ) | const |
Get a rule by name.
| rule_name | Name of rule |
| std::vector< std::shared_ptr< alert_rule > > kcenon::monitoring::alert_manager::get_rules | ( | ) | const |
Get all rules.
Referenced by main().

| std::vector< alert_silence > kcenon::monitoring::alert_manager::get_silences | ( | ) | const |
Get all active silences.
| bool kcenon::monitoring::alert_manager::is_running | ( | ) | const |
| bool kcenon::monitoring::alert_manager::is_silenced | ( | const alert & | a | ) | const |
Check if an alert is silenced.
| a | Alert to check |
|
delete |
|
delete |
| common::VoidResult kcenon::monitoring::alert_manager::process_metric | ( | const std::string & | metric_name, |
| double | value ) |
Process a metric value.
| metric_name | Name of the metric |
| value | Metric value |
Referenced by main(), and TEST().

| common::VoidResult kcenon::monitoring::alert_manager::process_metrics | ( | const std::unordered_map< std::string, double > & | metrics | ) |
Process a batch of metrics.
| metrics | Map of metric names to values |
| common::VoidResult kcenon::monitoring::alert_manager::remove_notifier | ( | const std::string & | notifier_name | ) |
Remove a notifier.
| notifier_name | Name of notifier |
| common::VoidResult kcenon::monitoring::alert_manager::remove_rule | ( | const std::string & | rule_name | ) |
Remove an alert rule.
| rule_name | Name of rule to remove |
| common::VoidResult kcenon::monitoring::alert_manager::resolve_alert | ( | const std::string & | fingerprint | ) |
Resolve an alert manually.
| fingerprint | Alert fingerprint |
Referenced by TEST_F().

|
private |
Send notifications for an alert.
| a | Alert to notify about |
| void kcenon::monitoring::alert_manager::set_event_bus | ( | std::shared_ptr< interface_event_bus > | event_bus | ) |
| void kcenon::monitoring::alert_manager::set_metric_provider | ( | metric_provider_func | provider | ) |
Set the metric provider function.
| provider | Function that returns metric values by name |
Referenced by TEST().

| common::VoidResult kcenon::monitoring::alert_manager::start | ( | ) |
Start the alert manager.
Referenced by main(), TEST_F(), TEST_F(), and TEST_F().

| common::VoidResult kcenon::monitoring::alert_manager::stop | ( | ) |
Stop the alert manager.
Referenced by main(), TEST_F(), TEST_F(), and TEST_F().

|
private |
Update alert state.
| fingerprint | Alert fingerprint |
| condition_met | Whether condition is met |
| value | Current metric value |
|
private |
Definition at line 372 of file alert_manager.h.
|
mutableprivate |
Definition at line 371 of file alert_manager.h.
|
private |
Definition at line 363 of file alert_manager.h.
|
private |
Definition at line 395 of file alert_manager.h.
|
private |
Definition at line 396 of file alert_manager.h.
|
private |
Definition at line 394 of file alert_manager.h.
|
private |
Definition at line 387 of file alert_manager.h.
|
private |
Definition at line 399 of file alert_manager.h.
|
private |
Definition at line 384 of file alert_manager.h.
|
mutableprivate |
Definition at line 390 of file alert_manager.h.
|
private |
Definition at line 380 of file alert_manager.h.
|
mutableprivate |
Definition at line 379 of file alert_manager.h.
|
private |
Definition at line 383 of file alert_manager.h.
|
private |
Definition at line 368 of file alert_manager.h.
|
private |
Definition at line 367 of file alert_manager.h.
|
mutableprivate |
Definition at line 366 of file alert_manager.h.
|
private |
Definition at line 393 of file alert_manager.h.
|
private |
Definition at line 376 of file alert_manager.h.
|
mutableprivate |
Definition at line 375 of file alert_manager.h.