74 std::lock_guard<std::mutex> lock(
mutex_);
78 auto start_time = std::chrono::steady_clock::now();
80 std::vector<std::string> messages;
81 std::size_t healthy_count = 0;
82 std::size_t degraded_count = 0;
83 std::size_t unhealthy_count = 0;
86 auto child_result =
check->check();
88 switch (child_result.status) {
92 messages.push_back(
check->get_name() +
": " + child_result.
message);
99 messages.push_back(
check->get_name() +
": " + child_result.
message);
105 messages.push_back(
check->get_name() +
": " + child_result.
message);
113 auto end_time = std::chrono::steady_clock::now();
114 result.
check_duration = std::chrono::duration_cast<std::chrono::milliseconds>(
115 end_time - start_time);
117 if (messages.empty()) {
118 result.
message =
"All " + std::to_string(healthy_count) +
" checks passed";
120 result.
message = std::to_string(unhealthy_count) +
" unhealthy, " +
121 std::to_string(degraded_count) +
" degraded";
122 for (
const auto& msg : messages) {
128 result.
metadata[
"healthy_count"] = std::to_string(healthy_count);
129 result.
metadata[
"degraded_count"] = std::to_string(degraded_count);
130 result.
metadata[
"unhealthy_count"] = std::to_string(unhealthy_count);
143 std::lock_guard<std::mutex> lock(
mutex_);
153 std::lock_guard<std::mutex> lock(
mutex_);
155 [&name](
const std::shared_ptr<health_check>&
check) {
156 return check->get_name() == name;
169 [[nodiscard]] std::size_t
size()
const {
170 std::lock_guard<std::mutex> lock(
mutex_);
179 std::lock_guard<std::mutex> lock(
mutex_);
187 std::lock_guard<std::mutex> lock(
mutex_);
196 std::lock_guard<std::mutex> lock(
mutex_);
197 std::vector<std::string> names;
200 names.push_back(
check->get_name());
209 std::vector<std::shared_ptr<health_check>>
checks_;
Aggregates multiple health checks into a single check.
void clear()
Clear all child checks.
std::string get_name() const override
Get the unique name of this health check.
bool remove_check(const std::string &name)
Remove a child health check by name.
bool is_critical() const override
Check if this health check is critical.
bool empty() const
Check if this composite has no child checks.
health_check_type get_type() const override
Get the type of this health check.
composite_health_check(std::string name, health_check_type type=health_check_type::custom, bool critical=true)
Construct a composite health check.
void add_check(std::shared_ptr< health_check > check)
Add a child health check.
std::vector< std::string > get_check_names() const
Get all child check names.
std::vector< std::shared_ptr< health_check > > checks_
std::size_t size() const
Get the number of child checks.
health_check_result check() override
Execute all child health checks and aggregate results.
Abstract base class for health checks.
Base classes and types for health checking functionality.
health_check_type
Types of health checks supported by the system.
Result of a health check operation.
std::unordered_map< std::string, std::string > metadata
std::chrono::milliseconds check_duration