Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
kcenon::monitoring::health_check_builder Class Reference

Fluent builder for creating functional_health_check instances. More...

#include <health_monitor.h>

Collaboration diagram for kcenon::monitoring::health_check_builder:
Collaboration graph

Public Member Functions

health_check_builderwith_name (const std::string &name)
 Set the health check name.
 
health_check_builderwith_type (health_check_type type)
 Set the health check type.
 
health_check_builderwith_check (std::function< health_check_result()> func)
 Set the callable that performs the health check.
 
health_check_builderwith_timeout (std::chrono::milliseconds timeout)
 Set the maximum duration allowed for the check.
 
health_check_buildercritical (bool is_critical)
 Mark this check as critical for overall system health.
 
std::shared_ptr< functional_health_checkbuild ()
 Build and return the configured functional_health_check.
 

Private Attributes

std::string name_
 
health_check_type type_ {health_check_type::liveness}
 
std::function< health_check_result()> check_func_
 
std::chrono::milliseconds timeout_ {std::chrono::milliseconds(1000)}
 
bool critical_ {false}
 

Detailed Description

Fluent builder for creating functional_health_check instances.

auto check = health_check_builder()
.with_name("redis")
.with_check([]() {
return ping_redis()
: health_check_result::unhealthy("Redis unreachable");
})
.with_timeout(std::chrono::milliseconds(500))
.critical(true)
.build();
Fluent builder for creating functional_health_check instances.
health_check_builder & critical(bool is_critical)
Mark this check as critical for overall system health.
health_check_builder & with_check(std::function< health_check_result()> func)
Set the callable that performs the health check.
health_check_builder & with_type(health_check_type type)
Set the health check type.
health_check_builder & with_name(const std::string &name)
Set the health check name.
std::shared_ptr< functional_health_check > build()
Build and return the configured functional_health_check.
health_check_builder & with_timeout(std::chrono::milliseconds timeout)
Set the maximum duration allowed for the check.
@ readiness
Indicates whether the service is ready to accept traffic.
Result of a health check operation.
static health_check_result healthy(const std::string &msg="OK")
See also
functional_health_check For the type created by build()

Definition at line 605 of file health_monitor.h.

Member Function Documentation

◆ build()

std::shared_ptr< functional_health_check > kcenon::monitoring::health_check_builder::build ( )
inline

Build and return the configured functional_health_check.

Returns
Shared pointer to the constructed health check

Definition at line 661 of file health_monitor.h.

661 {
662 return std::make_shared<functional_health_check>(
664 }
std::function< health_check_result()> check_func_

References check_func_, critical_, name_, timeout_, and type_.

Referenced by TEST_F().

Here is the caller graph for this function:

◆ critical()

health_check_builder & kcenon::monitoring::health_check_builder::critical ( bool is_critical)
inline

Mark this check as critical for overall system health.

Parameters
is_criticaltrue if system should be marked unhealthy when this check fails
Returns
Reference to this builder for chaining

Definition at line 652 of file health_monitor.h.

652 {
653 critical_ = is_critical;
654 return *this;
655 }

References critical_.

Referenced by TEST_F().

Here is the caller graph for this function:

◆ with_check()

health_check_builder & kcenon::monitoring::health_check_builder::with_check ( std::function< health_check_result()> func)
inline

Set the callable that performs the health check.

Parameters
funcA callable returning health_check_result
Returns
Reference to this builder for chaining

Definition at line 632 of file health_monitor.h.

632 {
633 check_func_ = std::move(func);
634 return *this;
635 }

References check_func_.

Referenced by TEST_F(), and TEST_F().

Here is the caller graph for this function:

◆ with_name()

health_check_builder & kcenon::monitoring::health_check_builder::with_name ( const std::string & name)
inline

Set the health check name.

Parameters
nameHuman-readable name
Returns
Reference to this builder for chaining

Definition at line 612 of file health_monitor.h.

612 {
613 name_ = name;
614 return *this;
615 }

References name_.

Referenced by TEST_F(), and TEST_F().

Here is the caller graph for this function:

◆ with_timeout()

health_check_builder & kcenon::monitoring::health_check_builder::with_timeout ( std::chrono::milliseconds timeout)
inline

Set the maximum duration allowed for the check.

Parameters
timeoutTimeout duration
Returns
Reference to this builder for chaining

Definition at line 642 of file health_monitor.h.

642 {
643 timeout_ = timeout;
644 return *this;
645 }

References timeout_.

◆ with_type()

health_check_builder & kcenon::monitoring::health_check_builder::with_type ( health_check_type type)
inline

Set the health check type.

Parameters
typeThe check type (liveness, readiness, or startup)
Returns
Reference to this builder for chaining

Definition at line 622 of file health_monitor.h.

622 {
623 type_ = type;
624 return *this;
625 }

References type_.

Referenced by TEST_F(), and TEST_F().

Here is the caller graph for this function:

Member Data Documentation

◆ check_func_

std::function<health_check_result()> kcenon::monitoring::health_check_builder::check_func_
private

Definition at line 669 of file health_monitor.h.

Referenced by build(), and with_check().

◆ critical_

bool kcenon::monitoring::health_check_builder::critical_ {false}
private

Definition at line 671 of file health_monitor.h.

671{false};

Referenced by build(), and critical().

◆ name_

std::string kcenon::monitoring::health_check_builder::name_
private

Definition at line 667 of file health_monitor.h.

Referenced by build(), and with_name().

◆ timeout_

std::chrono::milliseconds kcenon::monitoring::health_check_builder::timeout_ {std::chrono::milliseconds(1000)}
private

Definition at line 670 of file health_monitor.h.

670{std::chrono::milliseconds(1000)};

Referenced by build(), and with_timeout().

◆ type_

health_check_type kcenon::monitoring::health_check_builder::type_ {health_check_type::liveness}
private

Definition at line 668 of file health_monitor.h.

@ liveness
Indicates whether the process is alive and should be restarted if failing.

Referenced by build(), and with_type().


The documentation for this class was generated from the following file: