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

Silence configuration to suppress alerts. More...

#include <alert_types.h>

Collaboration diagram for kcenon::monitoring::alert_silence:
Collaboration graph

Public Member Functions

 alert_silence ()
 
bool is_active () const
 Check if silence is currently active.
 
bool matches (const alert &a) const
 Check if an alert matches this silence.
 

Public Attributes

uint64_t id = 0
 Silence ID.
 
std::string comment
 Reason for silence.
 
std::string created_by
 Creator identifier.
 
alert_labels matchers
 Labels to match.
 
std::chrono::steady_clock::time_point starts_at
 Silence start time.
 
std::chrono::steady_clock::time_point ends_at
 Silence end time.
 

Static Private Member Functions

static uint64_t generate_id ()
 

Detailed Description

Silence configuration to suppress alerts.

Silences prevent matching alerts from sending notifications for a specified duration.

Definition at line 385 of file alert_types.h.

Constructor & Destructor Documentation

◆ alert_silence()

kcenon::monitoring::alert_silence::alert_silence ( )
inline

Definition at line 393 of file alert_types.h.

394 : id(generate_id())
395 , starts_at(std::chrono::steady_clock::now())
396 , ends_at(starts_at + std::chrono::hours(1)) {}
std::chrono::steady_clock::time_point ends_at
Silence end time.
std::chrono::steady_clock::time_point starts_at
Silence start time.

Member Function Documentation

◆ generate_id()

static uint64_t kcenon::monitoring::alert_silence::generate_id ( )
inlinestaticprivate

Definition at line 427 of file alert_types.h.

427 {
428 static std::atomic<uint64_t> counter{0};
429 return counter.fetch_add(1, std::memory_order_relaxed);
430 }
@ counter
Monotonically increasing counter.

References kcenon::monitoring::counter.

◆ is_active()

bool kcenon::monitoring::alert_silence::is_active ( ) const
inline

Check if silence is currently active.

Returns
True if within active period

Definition at line 402 of file alert_types.h.

402 {
403 auto now = std::chrono::steady_clock::now();
404 return now >= starts_at && now < ends_at;
405 }

References ends_at, and starts_at.

Referenced by matches().

Here is the caller graph for this function:

◆ matches()

bool kcenon::monitoring::alert_silence::matches ( const alert & a) const
inline

Check if an alert matches this silence.

Parameters
aThe alert to check
Returns
True if alert should be silenced

Definition at line 412 of file alert_types.h.

412 {
413 if (!is_active()) {
414 return false;
415 }
416
417 // All matcher labels must be present in alert labels
418 for (const auto& [key, value] : matchers.labels) {
419 if (a.labels.get(key) != value) {
420 return false;
421 }
422 }
423 return true;
424 }
std::unordered_map< std::string, std::string > labels
bool is_active() const
Check if silence is currently active.
alert_labels matchers
Labels to match.

References kcenon::monitoring::alert_labels::get(), is_active(), kcenon::monitoring::alert::labels, kcenon::monitoring::alert_labels::labels, and matchers.

Here is the call graph for this function:

Member Data Documentation

◆ comment

std::string kcenon::monitoring::alert_silence::comment

Reason for silence.

Definition at line 387 of file alert_types.h.

Referenced by TEST_F().

◆ created_by

std::string kcenon::monitoring::alert_silence::created_by

Creator identifier.

Definition at line 388 of file alert_types.h.

◆ ends_at

std::chrono::steady_clock::time_point kcenon::monitoring::alert_silence::ends_at

Silence end time.

Definition at line 391 of file alert_types.h.

Referenced by is_active().

◆ id

uint64_t kcenon::monitoring::alert_silence::id = 0

Silence ID.

Definition at line 386 of file alert_types.h.

Referenced by TEST_F(), and TEST_F().

◆ matchers

alert_labels kcenon::monitoring::alert_silence::matchers

Labels to match.

Definition at line 389 of file alert_types.h.

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

◆ starts_at

std::chrono::steady_clock::time_point kcenon::monitoring::alert_silence::starts_at

Silence start time.

Definition at line 390 of file alert_types.h.

Referenced by is_active().


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