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

Health check implementation backed by a std::function. More...

#include <health_monitor.h>

Inheritance diagram for kcenon::monitoring::functional_health_check:
Inheritance graph
Collaboration diagram for kcenon::monitoring::functional_health_check:
Collaboration graph

Public Member Functions

 functional_health_check (const std::string &name, health_check_type type, std::function< health_check_result()> check_func, std::chrono::milliseconds timeout=std::chrono::milliseconds(1000), bool critical=false)
 Construct a functional health check.
 
std::string get_name () const override
 Get the human-readable name of this health check.
 
health_check_type get_type () const override
 Get the type of this health check (liveness, readiness, or startup).
 
std::chrono::milliseconds get_timeout () const override
 Get the maximum time allowed for this check to complete.
 
bool is_critical () const override
 Whether this check is critical for overall system health.
 
health_check_result check () override
 Execute the stored check function.
 
- Public Member Functions inherited from kcenon::monitoring::health_check
virtual ~health_check ()=default
 

Private Attributes

std::string name_
 
health_check_type type_
 
std::function< health_check_result()> check_func_
 
std::chrono::milliseconds timeout_
 
bool critical_
 

Detailed Description

Health check implementation backed by a std::function.

Wraps a callable as a health_check, allowing health checks to be defined inline without subclassing. Typically created via health_check_builder.

See also
health_check_builder For the preferred way to create instances

Definition at line 157 of file health_monitor.h.

Constructor & Destructor Documentation

◆ functional_health_check()

kcenon::monitoring::functional_health_check::functional_health_check ( const std::string & name,
health_check_type type,
std::function< health_check_result()> check_func,
std::chrono::milliseconds timeout = std::chrono::milliseconds(1000),
bool critical = false )
inline

Construct a functional health check.

Parameters
nameHuman-readable name for this check
typeThe check type (liveness, readiness, or startup)
check_funcCallable that performs the health check
timeoutMaximum duration for the check (default: 1000ms)
criticalWhether this check is critical for overall health (default: false)

Definition at line 167 of file health_monitor.h.

Member Function Documentation

◆ check()

health_check_result kcenon::monitoring::functional_health_check::check ( )
inlineoverridevirtual

Execute the stored check function.

Returns
The health check result, or healthy("No check function") if no callable is set

Implements kcenon::monitoring::health_check.

Definition at line 191 of file health_monitor.h.

191 {
192 if (check_func_) {
193 return check_func_();
194 }
195 return health_check_result::healthy("No check function");
196 }
static health_check_result healthy(const std::string &msg="OK")

References check_func_, and kcenon::monitoring::health_check_result::healthy().

Referenced by TEST_F().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_name()

std::string kcenon::monitoring::functional_health_check::get_name ( ) const
inlineoverridevirtual

Get the human-readable name of this health check.

Returns
The health check name

Implements kcenon::monitoring::health_check.

Definition at line 179 of file health_monitor.h.

179{ return name_; }

References name_.

Referenced by TEST_F().

Here is the caller graph for this function:

◆ get_timeout()

std::chrono::milliseconds kcenon::monitoring::functional_health_check::get_timeout ( ) const
inlineoverridevirtual

Get the maximum time allowed for this check to complete.

Returns
Timeout duration (default: 1000ms)

Reimplemented from kcenon::monitoring::health_check.

Definition at line 183 of file health_monitor.h.

183{ return timeout_; }

References timeout_.

◆ get_type()

health_check_type kcenon::monitoring::functional_health_check::get_type ( ) const
inlineoverridevirtual

Get the type of this health check (liveness, readiness, or startup).

Returns
The health check type

Implements kcenon::monitoring::health_check.

Definition at line 181 of file health_monitor.h.

181{ return type_; }

References type_.

Referenced by TEST_F().

Here is the caller graph for this function:

◆ is_critical()

bool kcenon::monitoring::functional_health_check::is_critical ( ) const
inlineoverridevirtual

Whether this check is critical for overall system health.

Returns
true if failure of this check should mark the system as unhealthy (default: false)

Reimplemented from kcenon::monitoring::health_check.

Definition at line 185 of file health_monitor.h.

185{ return critical_; }

References critical_.

Member Data Documentation

◆ check_func_

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

Definition at line 201 of file health_monitor.h.

Referenced by check().

◆ critical_

bool kcenon::monitoring::functional_health_check::critical_
private

Definition at line 203 of file health_monitor.h.

Referenced by is_critical().

◆ name_

std::string kcenon::monitoring::functional_health_check::name_
private

Definition at line 199 of file health_monitor.h.

Referenced by get_name().

◆ timeout_

std::chrono::milliseconds kcenon::monitoring::functional_health_check::timeout_
private

Definition at line 202 of file health_monitor.h.

Referenced by get_timeout().

◆ type_

health_check_type kcenon::monitoring::functional_health_check::type_
private

Definition at line 200 of file health_monitor.h.

Referenced by get_type().


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