|
PACS System 0.1.0
PACS DICOM system library
|
Performs comprehensive health checks on PACS system components. More...
#include <health_checker.h>

Public Types | |
| using | check_callback = std::function<bool(std::string& error_message)> |
| Custom health check callback type. | |
Public Member Functions | |
| health_checker () | |
| Construct health checker with default configuration. | |
| health_checker (const health_checker_config &config) | |
| Construct health checker with custom configuration. | |
| ~health_checker () | |
| Destructor - stops background checking if enabled. | |
| health_checker (const health_checker &)=delete | |
| Non-copyable. | |
| health_checker & | operator= (const health_checker &)=delete |
| health_checker (health_checker &&other) noexcept | |
| Movable. | |
| health_checker & | operator= (health_checker &&other) noexcept |
| void | set_database (kcenon::pacs::storage::index_database *database) |
| Set the database instance to monitor. | |
| void | set_storage (kcenon::pacs::storage::file_storage *storage) |
| Set the storage instance to monitor. | |
| void | register_check (std::string_view name, check_callback callback) |
| Register a custom health check. | |
| void | unregister_check (std::string_view name) |
| Unregister a custom health check. | |
| health_status | check () |
| Perform a full health check. | |
| bool | is_alive () const noexcept |
| Perform a quick liveness check. | |
| bool | is_ready () |
| Perform a readiness check. | |
| health_status | get_cached_status () const |
| Get cached health status. | |
| health_status | get_status () |
| Get cached status or perform check if stale. | |
| void | update_association_metrics (std::uint32_t active, std::uint32_t max, std::uint64_t total_established, std::uint64_t total_failed) |
| Update association metrics. | |
| void | update_storage_metrics (std::uint64_t instances, std::uint64_t studies, std::uint64_t series, std::uint64_t successful_stores, std::uint64_t failed_stores) |
| Update storage metrics. | |
| void | set_version (std::uint16_t major, std::uint16_t minor, std::uint16_t patch, std::string_view build_id="") |
| Set version information. | |
| const health_checker_config & | config () const noexcept |
| Get current configuration. | |
| void | set_config (const health_checker_config &config) |
| Update configuration. | |
Private Member Functions | |
| void | check_database (health_status &status) |
| Check database connectivity. | |
| void | check_storage (health_status &status) |
| Check storage availability. | |
| void | run_custom_checks (health_status &status) |
| Run all custom checks. | |
Private Attributes | |
| health_checker_config | config_ |
| Configuration. | |
| kcenon::pacs::storage::index_database * | database_ {nullptr} |
| Database instance to monitor. | |
| kcenon::pacs::storage::file_storage * | storage_ {nullptr} |
| Storage instance to monitor. | |
| std::unordered_map< std::string, check_callback > | custom_checks_ |
| Custom health checks. | |
| health_status | cached_status_ |
| Cached health status. | |
| std::chrono::system_clock::time_point | last_check_time_ |
| Timestamp of last check. | |
| association_metrics | associations_ |
| Association metrics (updated externally) | |
| storage_metrics | storage_metrics_ |
| Storage metrics (updated externally) | |
| version_info | version_ |
| Version information. | |
| std::shared_mutex | mutex_ |
| Mutex for thread safety. | |
Performs comprehensive health checks on PACS system components.
The health_checker class provides a unified interface for monitoring the health of all PACS system components including:
The checker supports both on-demand checks and cached results for high- frequency health check requests (e.g., from Kubernetes liveness probes).
Thread Safety: All public methods are thread-safe.
Definition at line 106 of file health_checker.h.
| using kcenon::pacs::monitoring::health_checker::check_callback = std::function<bool(std::string& error_message)> |
Custom health check callback type.
Definition at line 113 of file health_checker.h.
| kcenon::pacs::monitoring::health_checker::health_checker | ( | ) |
Construct health checker with default configuration.
Definition at line 25 of file health_checker.cpp.
|
explicit |
Construct health checker with custom configuration.
| config | Configuration options |
Definition at line 27 of file health_checker.cpp.
References cached_status_, kcenon::pacs::monitoring::health_status::level, kcenon::pacs::monitoring::health_status::message, kcenon::pacs::monitoring::version_info::startup_time, kcenon::pacs::monitoring::unhealthy, and version_.
|
default |
Destructor - stops background checking if enabled.
|
delete |
Non-copyable.
|
noexcept |
Movable.
Definition at line 39 of file health_checker.cpp.
|
nodiscard |
Perform a full health check.
Runs all registered health checks and aggregates results. This method may take time depending on configured timeouts.
Definition at line 104 of file health_checker.cpp.
References associations_, cached_status_, check_database(), check_storage(), last_check_time_, mutex_, run_custom_checks(), storage_metrics_, and version_.
Referenced by get_status().


|
private |
Check database connectivity.
| status | Status to update |
Definition at line 222 of file health_checker.cpp.
References config_, database_, kcenon::pacs::monitoring::health_checker_config::database_timeout, and mutex_.
Referenced by check().

|
private |
Check storage availability.
| status | Status to update |
Definition at line 259 of file health_checker.cpp.
References config_, mutex_, storage_, kcenon::pacs::monitoring::health_checker_config::storage_critical_threshold, and kcenon::pacs::monitoring::health_checker_config::storage_warning_threshold.
Referenced by check().

|
nodiscardnoexcept |
Get current configuration.
Definition at line 209 of file health_checker.cpp.
References config_.
Referenced by set_config().

|
nodiscard |
Get cached health status.
Returns the most recent health check result without performing new checks. Useful for high-frequency monitoring requests.
Definition at line 144 of file health_checker.cpp.
References cached_status_, and mutex_.
|
nodiscard |
Get cached status or perform check if stale.
Returns cached result if within cache_duration, otherwise performs a fresh check.
Definition at line 149 of file health_checker.cpp.
References kcenon::pacs::monitoring::health_checker_config::cache_duration, cached_status_, check(), config_, last_check_time_, and mutex_.
Referenced by is_ready().


|
nodiscardnoexcept |
Perform a quick liveness check.
A minimal check suitable for Kubernetes liveness probes. Only verifies that the service is running.
Definition at line 134 of file health_checker.cpp.
|
nodiscard |
Perform a readiness check.
Checks if the service is ready to accept traffic. Verifies database and storage connectivity.
Definition at line 139 of file health_checker.cpp.
References get_status().

|
delete |
|
noexcept |
Definition at line 54 of file health_checker.cpp.
| void kcenon::pacs::monitoring::health_checker::register_check | ( | std::string_view | name, |
| check_callback | callback ) |
Register a custom health check.
Custom checks allow extending the health checker with application- specific health indicators.
| name | Unique identifier for the check |
| callback | Function that returns true if healthy, false otherwise |
Definition at line 89 of file health_checker.cpp.
References custom_checks_, mutex_, and name.
|
private |
Run all custom checks.
| status | Status to update |
Definition at line 325 of file health_checker.cpp.
References custom_checks_, kcenon::pacs::monitoring::healthy, mutex_, and name.
Referenced by check().

| void kcenon::pacs::monitoring::health_checker::set_config | ( | const health_checker_config & | config | ) |
Update configuration.
| config | New configuration |
Definition at line 213 of file health_checker.cpp.
References config(), config_, and mutex_.

| void kcenon::pacs::monitoring::health_checker::set_database | ( | kcenon::pacs::storage::index_database * | database | ) |
Set the database instance to monitor.
| database | Pointer to the index_database (nullable to disable check) |
Definition at line 79 of file health_checker.cpp.
| void kcenon::pacs::monitoring::health_checker::set_storage | ( | kcenon::pacs::storage::file_storage * | storage | ) |
Set the storage instance to monitor.
| storage | Pointer to the file_storage (nullable to disable check) |
Definition at line 84 of file health_checker.cpp.
| void kcenon::pacs::monitoring::health_checker::set_version | ( | std::uint16_t | major, |
| std::uint16_t | minor, | ||
| std::uint16_t | patch, | ||
| std::string_view | build_id = "" ) |
Set version information.
| major | Major version |
| minor | Minor version |
| patch | Patch version |
| build_id | Build identifier (e.g., git hash) |
Definition at line 194 of file health_checker.cpp.
References kcenon::pacs::monitoring::version_info::build_id, kcenon::pacs::monitoring::version_info::major, kcenon::pacs::monitoring::version_info::minor, mutex_, kcenon::pacs::monitoring::version_info::patch, and version_.
| void kcenon::pacs::monitoring::health_checker::unregister_check | ( | std::string_view | name | ) |
Unregister a custom health check.
| name | The check identifier to remove |
Definition at line 95 of file health_checker.cpp.
References custom_checks_, mutex_, and name.
| void kcenon::pacs::monitoring::health_checker::update_association_metrics | ( | std::uint32_t | active, |
| std::uint32_t | max, | ||
| std::uint64_t | total_established, | ||
| std::uint64_t | total_failed ) |
Update association metrics.
Called by the DICOM server to update active association count.
| active | Current number of active associations |
| max | Maximum allowed associations |
| total_established | Total associations since startup |
| total_failed | Total failed association attempts |
Definition at line 170 of file health_checker.cpp.
References kcenon::pacs::monitoring::association_metrics::active_associations, associations_, kcenon::pacs::monitoring::association_metrics::failed_associations, kcenon::pacs::monitoring::association_metrics::max_associations, mutex_, and kcenon::pacs::monitoring::association_metrics::total_associations.
| void kcenon::pacs::monitoring::health_checker::update_storage_metrics | ( | std::uint64_t | instances, |
| std::uint64_t | studies, | ||
| std::uint64_t | series, | ||
| std::uint64_t | successful_stores, | ||
| std::uint64_t | failed_stores ) |
Update storage metrics.
Called by storage service to update storage statistics.
| instances | Total stored instances |
| studies | Total studies |
| series | Total series |
| successful_stores | Successful C-STORE operations |
| failed_stores | Failed C-STORE operations |
Definition at line 181 of file health_checker.cpp.
References kcenon::pacs::monitoring::storage_metrics::failed_stores, mutex_, storage_metrics_, kcenon::pacs::monitoring::storage_metrics::successful_stores, kcenon::pacs::monitoring::storage_metrics::total_instances, kcenon::pacs::monitoring::storage_metrics::total_series, and kcenon::pacs::monitoring::storage_metrics::total_studies.
|
private |
Association metrics (updated externally)
Definition at line 341 of file health_checker.h.
Referenced by check(), and update_association_metrics().
|
private |
Cached health status.
Definition at line 335 of file health_checker.h.
Referenced by check(), get_cached_status(), get_status(), and health_checker().
|
private |
Configuration.
Definition at line 323 of file health_checker.h.
Referenced by check_database(), check_storage(), config(), get_status(), and set_config().
|
private |
Custom health checks.
Definition at line 332 of file health_checker.h.
Referenced by register_check(), run_custom_checks(), and unregister_check().
|
private |
Database instance to monitor.
Definition at line 326 of file health_checker.h.
Referenced by check_database(), and set_database().
|
private |
Timestamp of last check.
Definition at line 338 of file health_checker.h.
Referenced by check(), and get_status().
|
mutableprivate |
Mutex for thread safety.
Definition at line 350 of file health_checker.h.
Referenced by check(), check_database(), check_storage(), get_cached_status(), get_status(), register_check(), run_custom_checks(), set_config(), set_database(), set_storage(), set_version(), unregister_check(), update_association_metrics(), and update_storage_metrics().
|
private |
Storage instance to monitor.
Definition at line 329 of file health_checker.h.
Referenced by check_storage(), and set_storage().
|
private |
Storage metrics (updated externally)
Definition at line 344 of file health_checker.h.
Referenced by check(), and update_storage_metrics().
|
private |
Version information.
Definition at line 347 of file health_checker.h.
Referenced by check(), health_checker(), and set_version().