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

Trigger based on comparing value against a threshold. More...

#include <alert_triggers.h>

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

Public Member Functions

 threshold_trigger (double threshold, comparison_operator op=comparison_operator::greater_than, double epsilon=1e-9)
 Construct a threshold trigger.
 
bool evaluate (double value) const override
 Evaluate the trigger condition.
 
std::string type_name () const override
 Get trigger type name.
 
std::string description () const override
 Get human-readable description.
 
double threshold () const
 Get the threshold value.
 
comparison_operator op () const
 Get the comparison operator.
 
- Public Member Functions inherited from kcenon::monitoring::alert_trigger
virtual ~alert_trigger ()=default
 

Static Public Member Functions

static std::shared_ptr< threshold_triggerabove (double threshold)
 Create trigger for value > threshold.
 
static std::shared_ptr< threshold_triggerabove_or_equal (double threshold)
 Create trigger for value >= threshold.
 
static std::shared_ptr< threshold_triggerbelow (double threshold)
 Create trigger for value < threshold.
 
static std::shared_ptr< threshold_triggerbelow_or_equal (double threshold)
 Create trigger for value <= threshold.
 
static std::shared_ptr< class range_triggerin_range (double min_val, double max_val)
 Create trigger for value within range (inclusive)
 
static std::shared_ptr< class range_triggerout_of_range (double min_val, double max_val)
 Create trigger for value outside range (exclusive)
 

Private Attributes

double threshold_
 
comparison_operator operator_
 
double epsilon_
 

Detailed Description

Trigger based on comparing value against a threshold.

The most common trigger type, comparing metric values against configured thresholds using various comparison operators.

Definition at line 76 of file alert_triggers.h.

Constructor & Destructor Documentation

◆ threshold_trigger()

kcenon::monitoring::threshold_trigger::threshold_trigger ( double threshold,
comparison_operator op = comparison_operator::greater_than,
double epsilon = 1e-9 )
inlineexplicit

Construct a threshold trigger.

Parameters
thresholdThe threshold value
opComparison operator
epsilonEpsilon for floating-point comparison (default 1e-9)
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/alert/alert_triggers.h.

Definition at line 84 of file alert_triggers.h.

88 , operator_(op)
89 , epsilon_(epsilon) {}
double threshold() const
Get the threshold value.
comparison_operator op() const
Get the comparison operator.

Member Function Documentation

◆ above()

static std::shared_ptr< threshold_trigger > kcenon::monitoring::threshold_trigger::above ( double threshold)
inlinestatic

Create trigger for value > threshold.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/alert/alert_triggers.h.

Definition at line 133 of file alert_triggers.h.

133 {
134 return std::make_shared<threshold_trigger>(threshold, comparison_operator::greater_than);
135 }

References kcenon::monitoring::greater_than, and threshold().

Referenced by AlertManagerRuleTest::create_rule(), main(), AlertManagerProcessingTest::SetUp(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

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

◆ above_or_equal()

static std::shared_ptr< threshold_trigger > kcenon::monitoring::threshold_trigger::above_or_equal ( double threshold)
inlinestatic

Create trigger for value >= threshold.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/alert/alert_triggers.h.

Definition at line 140 of file alert_triggers.h.

140 {
141 return std::make_shared<threshold_trigger>(threshold, comparison_operator::greater_or_equal);
142 }

References kcenon::monitoring::greater_or_equal, and threshold().

Referenced by main(), and TEST_F().

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

◆ below()

static std::shared_ptr< threshold_trigger > kcenon::monitoring::threshold_trigger::below ( double threshold)
inlinestatic

Create trigger for value < threshold.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/alert/alert_triggers.h.

Definition at line 147 of file alert_triggers.h.

147 {
148 return std::make_shared<threshold_trigger>(threshold, comparison_operator::less_than);
149 }

References kcenon::monitoring::less_than, and threshold().

Referenced by main(), TEST_F(), and TEST_F().

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

◆ below_or_equal()

static std::shared_ptr< threshold_trigger > kcenon::monitoring::threshold_trigger::below_or_equal ( double threshold)
inlinestatic

Create trigger for value <= threshold.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/alert/alert_triggers.h.

Definition at line 154 of file alert_triggers.h.

154 {
155 return std::make_shared<threshold_trigger>(threshold, comparison_operator::less_or_equal);
156 }

References kcenon::monitoring::less_or_equal, and threshold().

Referenced by main(), and TEST_F().

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

◆ description()

std::string kcenon::monitoring::threshold_trigger::description ( ) const
inlineoverridevirtual

Get human-readable description.

Returns
Description string

Implements kcenon::monitoring::alert_trigger.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/alert/alert_triggers.h.

Definition at line 114 of file alert_triggers.h.

114 {
115 return "value " + std::string(comparison_operator_to_string(operator_)) +
116 " " + std::to_string(threshold_);
117 }
constexpr const char * comparison_operator_to_string(comparison_operator op) noexcept
Convert comparison operator to string.

References kcenon::monitoring::comparison_operator_to_string(), operator_, and threshold_.

Here is the call graph for this function:

◆ evaluate()

bool kcenon::monitoring::threshold_trigger::evaluate ( double value) const
inlineoverridevirtual

Evaluate the trigger condition.

Parameters
valueCurrent metric value
Returns
True if trigger condition is met

Implements kcenon::monitoring::alert_trigger.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/alert/alert_triggers.h.

Definition at line 91 of file alert_triggers.h.

91 {
92 switch (operator_) {
94 return value > threshold_;
96 return value >= threshold_ - epsilon_;
98 return value < threshold_;
100 return value <= threshold_ + epsilon_;
102 return std::abs(value - threshold_) <= epsilon_;
104 return std::abs(value - threshold_) > epsilon_;
105 default:
106 return false;
107 }
108 }
@ equal
value == threshold (with epsilon)
@ not_equal
value != threshold (with epsilon)

References epsilon_, kcenon::monitoring::equal, kcenon::monitoring::greater_or_equal, kcenon::monitoring::greater_than, kcenon::monitoring::less_or_equal, kcenon::monitoring::less_than, kcenon::monitoring::not_equal, operator_, and threshold_.

◆ in_range()

std::shared_ptr< range_trigger > kcenon::monitoring::threshold_trigger::in_range ( double min_val,
double max_val )
inlinestatic

Create trigger for value within range (inclusive)

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/alert/alert_triggers.h.

Definition at line 215 of file alert_triggers.h.

215 {
216 return std::make_shared<range_trigger>(min_val, max_val, true);
217}

Referenced by main(), and TEST_F().

Here is the caller graph for this function:

◆ op()

comparison_operator kcenon::monitoring::threshold_trigger::op ( ) const
inline

Get the comparison operator.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/alert/alert_triggers.h.

Definition at line 127 of file alert_triggers.h.

127{ return operator_; }

References operator_.

◆ out_of_range()

std::shared_ptr< range_trigger > kcenon::monitoring::threshold_trigger::out_of_range ( double min_val,
double max_val )
inlinestatic

Create trigger for value outside range (exclusive)

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/alert/alert_triggers.h.

Definition at line 219 of file alert_triggers.h.

219 {
220 return std::make_shared<range_trigger>(min_val, max_val, false);
221}

Referenced by main(), and TEST_F().

Here is the caller graph for this function:

◆ threshold()

double kcenon::monitoring::threshold_trigger::threshold ( ) const
inline

Get the threshold value.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/alert/alert_triggers.h.

Definition at line 122 of file alert_triggers.h.

122{ return threshold_; }

References threshold_.

Referenced by above(), above_or_equal(), below(), and below_or_equal().

Here is the caller graph for this function:

◆ type_name()

std::string kcenon::monitoring::threshold_trigger::type_name ( ) const
inlineoverridevirtual

Get trigger type name.

Returns
Type name string

Implements kcenon::monitoring::alert_trigger.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/alert/alert_triggers.h.

Definition at line 110 of file alert_triggers.h.

110 {
111 return "threshold";
112 }

Member Data Documentation

◆ epsilon_

double kcenon::monitoring::threshold_trigger::epsilon_
private

◆ operator_

comparison_operator kcenon::monitoring::threshold_trigger::operator_
private

◆ threshold_

double kcenon::monitoring::threshold_trigger::threshold_
private

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