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

Core alert data structure. More...

#include <alert_types.h>

Collaboration diagram for kcenon::monitoring::alert:
Collaboration graph

Public Member Functions

 alert ()
 Default constructor.
 
 alert (std::string alert_name, alert_labels lbl)
 Construct with name and labels.
 
std::string fingerprint () const
 Get alert fingerprint for deduplication.
 
bool is_active () const
 Check if alert is currently active (pending or firing)
 
std::chrono::steady_clock::duration state_duration () const
 Get duration in current state.
 
std::chrono::steady_clock::duration firing_duration () const
 Get firing duration (if currently firing)
 
bool transition_to (alert_state new_state)
 Transition to a new state.
 

Public Attributes

std::string name
 Alert name/identifier.
 
alert_labels labels
 Identifying labels.
 
alert_annotations annotations
 Descriptive annotations.
 
alert_severity severity = alert_severity::warning
 Alert severity level.
 
alert_state state = alert_state::inactive
 Current state.
 
double value = 0.0
 Current metric value.
 
std::chrono::steady_clock::time_point created_at
 When alert was created.
 
std::chrono::steady_clock::time_point updated_at
 Last state change.
 
std::optional< std::chrono::steady_clock::time_point > started_at
 When firing started.
 
std::optional< std::chrono::steady_clock::time_point > resolved_at
 When resolved.
 
uint64_t id = 0
 Unique alert ID.
 
std::string rule_name
 Name of triggering rule.
 
std::string group_key
 Grouping key for dedup.
 

Static Private Member Functions

static uint64_t generate_id ()
 
static bool is_valid_transition (alert_state from, alert_state to)
 Check if state transition is valid.
 

Detailed Description

Core alert data structure.

Represents a single alert instance with its current state, metadata, and lifecycle timestamps.

Thread Safety:
This structure is not thread-safe. External synchronization is required when accessed from multiple threads.
Examples
alert_notifiers_example.cpp, alert_pipeline_example.cpp, and event_bus_example.cpp.

Definition at line 185 of file alert_types.h.

Constructor & Destructor Documentation

◆ alert() [1/2]

kcenon::monitoring::alert::alert ( )
inline

Default constructor.

Definition at line 205 of file alert_types.h.

206 : created_at(std::chrono::steady_clock::now())
208 , id(generate_id()) {}
std::chrono::steady_clock::time_point created_at
When alert was created.
std::chrono::steady_clock::time_point updated_at
Last state change.
static uint64_t generate_id()
uint64_t id
Unique alert ID.

◆ alert() [2/2]

kcenon::monitoring::alert::alert ( std::string alert_name,
alert_labels lbl )
inline

Construct with name and labels.

Parameters
alert_nameAlert name
alert_labelsAlert labels

Definition at line 215 of file alert_types.h.

216 : name(std::move(alert_name))
217 , labels(std::move(lbl))
218 , created_at(std::chrono::steady_clock::now())
220 , id(generate_id()) {}
std::string name
Alert name/identifier.
alert_labels labels
Identifying labels.

Member Function Documentation

◆ fingerprint()

std::string kcenon::monitoring::alert::fingerprint ( ) const
inline

Get alert fingerprint for deduplication.

Returns
Unique fingerprint based on name and labels

Definition at line 226 of file alert_types.h.

226 {
227 return name + "{" + labels.fingerprint() + "}";
228 }
std::string fingerprint() const
Generate a fingerprint for deduplication.

References kcenon::monitoring::alert_labels::fingerprint(), labels, and name.

Referenced by kcenon::monitoring::alert_aggregator::add_alert(), kcenon::monitoring::json_alert_formatter::format(), kcenon::monitoring::text_alert_formatter::format(), kcenon::monitoring::alert_deduplicator::is_duplicate(), kcenon::monitoring::alert_inhibitor::is_inhibited(), kcenon::monitoring::alert_deduplicator::mark_seen(), and kcenon::monitoring::alert_template::render().

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

◆ firing_duration()

std::chrono::steady_clock::duration kcenon::monitoring::alert::firing_duration ( ) const
inline

Get firing duration (if currently firing)

Returns
Duration since firing started, or zero if not firing

Definition at line 250 of file alert_types.h.

250 {
251 if (state == alert_state::firing && started_at.has_value()) {
252 return std::chrono::steady_clock::now() - *started_at;
253 }
254 return std::chrono::steady_clock::duration::zero();
255 }
@ firing
Alert is active and notifications sent.
alert_state state
Current state.
std::optional< std::chrono::steady_clock::time_point > started_at
When firing started.

References kcenon::monitoring::firing, started_at, and state.

Referenced by TEST_F().

Here is the caller graph for this function:

◆ generate_id()

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

Definition at line 281 of file alert_types.h.

281 {
282 static std::atomic<uint64_t> counter{0};
283 return counter.fetch_add(1, std::memory_order_relaxed);
284 }
@ counter
Monotonically increasing counter.

References kcenon::monitoring::counter.

◆ is_active()

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

Check if alert is currently active (pending or firing)

Returns
True if alert is active

Definition at line 234 of file alert_types.h.

234 {
236 }
@ pending
Condition met, waiting for duration threshold.

References kcenon::monitoring::firing, kcenon::monitoring::pending, and state.

Referenced by TEST_F().

Here is the caller graph for this function:

◆ is_valid_transition()

static bool kcenon::monitoring::alert::is_valid_transition ( alert_state from,
alert_state to )
inlinestaticprivate

Check if state transition is valid.

Definition at line 289 of file alert_types.h.

289 {
290 // All transitions are valid from suppressed (when silence expires)
291 if (from == alert_state::suppressed) {
292 return true;
293 }
294
295 // Transition to suppressed is always valid
296 if (to == alert_state::suppressed) {
297 return true;
298 }
299
300 switch (from) {
302 return to == alert_state::pending;
304 return to == alert_state::firing || to == alert_state::inactive;
306 return to == alert_state::resolved;
308 return to == alert_state::pending || to == alert_state::inactive;
309 default:
310 return false;
311 }
312 }
@ inactive
Alert condition not met.
@ suppressed
Alert is silenced.
@ resolved
Alert condition cleared.

References kcenon::monitoring::firing, kcenon::monitoring::inactive, kcenon::monitoring::pending, kcenon::monitoring::resolved, and kcenon::monitoring::suppressed.

Referenced by transition_to().

Here is the caller graph for this function:

◆ state_duration()

std::chrono::steady_clock::duration kcenon::monitoring::alert::state_duration ( ) const
inline

Get duration in current state.

Returns
Duration since last state change

Definition at line 242 of file alert_types.h.

242 {
243 return std::chrono::steady_clock::now() - updated_at;
244 }

References updated_at.

Referenced by TEST_F().

Here is the caller graph for this function:

◆ transition_to()

bool kcenon::monitoring::alert::transition_to ( alert_state new_state)
inline

Transition to a new state.

Parameters
new_stateThe new state
Returns
True if transition was valid

Definition at line 262 of file alert_types.h.

262 {
263 if (!is_valid_transition(state, new_state)) {
264 return false;
265 }
266
267 auto now = std::chrono::steady_clock::now();
268 state = new_state;
269 updated_at = now;
270
271 if (new_state == alert_state::firing && !started_at.has_value()) {
272 started_at = now;
273 } else if (new_state == alert_state::resolved) {
274 resolved_at = now;
275 }
276
277 return true;
278 }
static bool is_valid_transition(alert_state from, alert_state to)
Check if state transition is valid.
std::optional< std::chrono::steady_clock::time_point > resolved_at
When resolved.

References kcenon::monitoring::firing, is_valid_transition(), kcenon::monitoring::resolved, resolved_at, started_at, state, and updated_at.

Here is the call graph for this function:

Member Data Documentation

◆ annotations

◆ created_at

std::chrono::steady_clock::time_point kcenon::monitoring::alert::created_at

When alert was created.

Definition at line 193 of file alert_types.h.

◆ group_key

std::string kcenon::monitoring::alert::group_key

Grouping key for dedup.

Definition at line 200 of file alert_types.h.

Referenced by kcenon::monitoring::alert_rule::create_alert(), and kcenon::monitoring::alert_template::render().

◆ id

uint64_t kcenon::monitoring::alert::id = 0

Unique alert ID.

Definition at line 198 of file alert_types.h.

Referenced by TEST_F().

◆ labels

◆ name

◆ resolved_at

std::optional<std::chrono::steady_clock::time_point> kcenon::monitoring::alert::resolved_at

When resolved.

Definition at line 196 of file alert_types.h.

Referenced by TEST_F(), and transition_to().

◆ rule_name

◆ severity

◆ started_at

std::optional<std::chrono::steady_clock::time_point> kcenon::monitoring::alert::started_at

When firing started.

Definition at line 195 of file alert_types.h.

Referenced by firing_duration(), TEST_F(), and transition_to().

◆ state

◆ updated_at

std::chrono::steady_clock::time_point kcenon::monitoring::alert::updated_at

Last state change.

Definition at line 194 of file alert_types.h.

Referenced by state_duration(), and transition_to().

◆ value


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