|
Common System 0.2.0
Common interfaces and patterns for system integration
|
Central health monitoring system. More...
#include <health_monitor.h>

Public Member Functions | |
| health_monitor ()=default | |
| ~health_monitor () | |
| health_monitor (const health_monitor &)=delete | |
| health_monitor & | operator= (const health_monitor &)=delete |
| health_monitor (health_monitor &&)=delete | |
| health_monitor & | operator= (health_monitor &&)=delete |
| Result< bool > | register_check (const std::string &name, std::shared_ptr< health_check > check) |
| Register a health check. | |
| Result< bool > | unregister_check (const std::string &name) |
| Unregister a health check. | |
| Result< health_check_result > | check (const std::string &name) |
| Execute a specific health check. | |
| Result< bool > | add_dependency (const std::string &dependent, const std::string &dependency) |
| Add a dependency between health checks. | |
| VoidResult | start () |
| Start the health monitoring. | |
| VoidResult | stop () |
| Stop the health monitoring. | |
| bool | is_running () const |
| Check if health monitoring is running. | |
| void | refresh () |
| Refresh all health checks. | |
| void | register_recovery_handler (const std::string &name, recovery_handler handler) |
| Register a recovery handler for a health check. | |
| health_monitor_stats | get_stats () const |
| Get monitoring statistics. | |
| std::string | get_health_report () const |
| Get a formatted health report. | |
| health_status | get_overall_status () const |
| Get the overall health status. | |
| bool | has_check (const std::string &name) const |
| Check if a health check is registered. | |
| std::vector< std::string > | get_check_names () const |
| Get all registered check names. | |
Private Member Functions | |
| void | update_stats_after_check (const health_check_result &result) |
| void | attempt_recovery (const std::string &name) |
| std::string | get_overall_status_string () const |
| health_status | get_overall_status_internal () const |
Private Attributes | |
| health_dependency_graph | graph_ |
| std::unordered_map< std::string, recovery_handler > | recovery_handlers_ |
| std::unordered_map< std::string, health_check_result > | last_results_ |
| health_monitor_stats | stats_ |
| std::atomic< bool > | running_ {false} |
| std::mutex | mutex_ |
Central health monitoring system.
This class provides a complete health monitoring solution with:
Example usage:
Definition at line 95 of file health_monitor.h.
|
default |
|
inline |
Definition at line 99 of file health_monitor.h.
References stop(), and kcenon::common::Result< T >::value_or().

|
delete |
|
delete |
|
inline |
Add a dependency between health checks.
| dependent | The check that depends on another |
| dependency | The check being depended upon |
Definition at line 175 of file health_monitor.h.
References kcenon::common::interfaces::health_dependency_graph::add_dependency(), kcenon::common::interfaces::dependency, graph_, and mutex_.

|
inlineprivate |
Definition at line 350 of file health_monitor.h.
References kcenon::common::interfaces::health_monitor_stats::recovery_attempts, recovery_handlers_, stats_, and kcenon::common::interfaces::health_monitor_stats::successful_recoveries.
Referenced by check(), and refresh().

|
inline |
Execute a specific health check.
| name | Name of the check to execute |
Definition at line 144 of file health_monitor.h.
References attempt_recovery(), kcenon::common::interfaces::health_monitor_stats::check_executions, kcenon::common::interfaces::health_dependency_graph::check_with_dependencies(), graph_, kcenon::common::interfaces::health_monitor_stats::last_check_duration, kcenon::common::interfaces::health_monitor_stats::last_check_time, last_results_, mutex_, stats_, kcenon::common::interfaces::unhealthy, and update_stats_after_check().
Referenced by register_check().


|
inlinenodiscard |
Get all registered check names.
Definition at line 327 of file health_monitor.h.
References kcenon::common::interfaces::health_dependency_graph::get_all_nodes(), graph_, and mutex_.

|
inlinenodiscard |
Get a formatted health report.
Definition at line 267 of file health_monitor.h.
References kcenon::common::interfaces::health_monitor_stats::degraded_count, get_overall_status_string(), kcenon::common::interfaces::health_monitor_stats::healthy_count, last_results_, mutex_, stats_, kcenon::common::interfaces::to_string(), kcenon::common::interfaces::health_monitor_stats::total_checks, kcenon::common::interfaces::health_monitor_stats::unhealthy_count, and kcenon::common::interfaces::health_monitor_stats::unknown_count.

|
inlinenodiscard |
Get the overall health status.
Definition at line 295 of file health_monitor.h.
References kcenon::common::interfaces::degraded, kcenon::common::interfaces::health_monitor_stats::degraded_count, kcenon::common::interfaces::healthy, kcenon::common::interfaces::health_monitor_stats::healthy_count, mutex_, stats_, kcenon::common::interfaces::unhealthy, kcenon::common::interfaces::health_monitor_stats::unhealthy_count, kcenon::common::interfaces::unknown, and kcenon::common::interfaces::health_monitor_stats::unknown_count.
|
inlinenodiscardprivate |
Definition at line 366 of file health_monitor.h.
References kcenon::common::interfaces::degraded, kcenon::common::interfaces::health_monitor_stats::degraded_count, kcenon::common::interfaces::healthy, kcenon::common::interfaces::health_monitor_stats::healthy_count, stats_, kcenon::common::interfaces::unhealthy, kcenon::common::interfaces::health_monitor_stats::unhealthy_count, kcenon::common::interfaces::unknown, and kcenon::common::interfaces::health_monitor_stats::unknown_count.
Referenced by get_overall_status_string().

|
inlinenodiscardprivate |
Definition at line 362 of file health_monitor.h.
References get_overall_status_internal(), and kcenon::common::interfaces::to_string().
Referenced by get_health_report().


|
inlinenodiscard |
|
inlinenodiscard |
Check if a health check is registered.
| name | Name of the health check |
Definition at line 318 of file health_monitor.h.
References graph_, kcenon::common::interfaces::health_dependency_graph::has_node(), and mutex_.

|
inlinenodiscard |
Check if health monitoring is running.
Definition at line 206 of file health_monitor.h.
References running_.
|
delete |
|
delete |
|
inline |
Refresh all health checks.
Executes all registered health checks and updates statistics.
Definition at line 213 of file health_monitor.h.
References attempt_recovery(), kcenon::common::interfaces::health_monitor_stats::check_executions, kcenon::common::interfaces::health_dependency_graph::check_with_dependencies(), kcenon::common::interfaces::health_monitor_stats::degraded_count, kcenon::common::interfaces::health_dependency_graph::get_all_nodes(), graph_, kcenon::common::interfaces::health_monitor_stats::healthy_count, kcenon::common::interfaces::health_monitor_stats::last_check_duration, kcenon::common::interfaces::health_monitor_stats::last_check_time, last_results_, mutex_, stats_, kcenon::common::interfaces::unhealthy, kcenon::common::interfaces::health_monitor_stats::unhealthy_count, kcenon::common::interfaces::health_monitor_stats::unknown_count, and update_stats_after_check().

|
inline |
Register a health check.
| name | Unique name for this check |
| check | Health check implementation |
Definition at line 112 of file health_monitor.h.
References kcenon::common::interfaces::health_dependency_graph::add_node(), check(), graph_, mutex_, stats_, and kcenon::common::interfaces::health_monitor_stats::total_checks.

|
inline |
Register a recovery handler for a health check.
| name | Name of the health check |
| handler | Recovery function to execute on failure |
Definition at line 249 of file health_monitor.h.
References mutex_, and recovery_handlers_.
|
inline |
Start the health monitoring.
Definition at line 184 of file health_monitor.h.
References kcenon::common::ok(), and running_.

|
inline |
Stop the health monitoring.
Definition at line 195 of file health_monitor.h.
References kcenon::common::ok(), and running_.
Referenced by ~health_monitor().


|
inline |
Unregister a health check.
| name | Name of the check to remove |
Definition at line 127 of file health_monitor.h.
References graph_, last_results_, mutex_, recovery_handlers_, kcenon::common::interfaces::health_dependency_graph::remove_node(), stats_, and kcenon::common::interfaces::health_monitor_stats::total_checks.

|
inlineprivate |
Definition at line 333 of file health_monitor.h.
References kcenon::common::interfaces::degraded, kcenon::common::interfaces::health_monitor_stats::degraded_count, kcenon::common::interfaces::healthy, kcenon::common::interfaces::health_monitor_stats::healthy_count, stats_, kcenon::common::interfaces::health_check_result::status, kcenon::common::interfaces::unhealthy, kcenon::common::interfaces::health_monitor_stats::unhealthy_count, kcenon::common::interfaces::unknown, and kcenon::common::interfaces::health_monitor_stats::unknown_count.
Referenced by check(), and refresh().

|
private |
Definition at line 382 of file health_monitor.h.
Referenced by add_dependency(), check(), get_check_names(), has_check(), refresh(), register_check(), and unregister_check().
|
private |
Definition at line 384 of file health_monitor.h.
Referenced by check(), get_health_report(), refresh(), and unregister_check().
|
mutableprivate |
Definition at line 387 of file health_monitor.h.
Referenced by add_dependency(), check(), get_check_names(), get_health_report(), get_overall_status(), get_stats(), has_check(), refresh(), register_check(), register_recovery_handler(), and unregister_check().
|
private |
Definition at line 383 of file health_monitor.h.
Referenced by attempt_recovery(), register_recovery_handler(), and unregister_check().
|
private |
Definition at line 386 of file health_monitor.h.
Referenced by is_running(), start(), and stop().
|
private |
Definition at line 385 of file health_monitor.h.
Referenced by attempt_recovery(), check(), get_health_report(), get_overall_status(), get_overall_status_internal(), get_stats(), refresh(), register_check(), unregister_check(), and update_stats_after_check().