userver: alerts::Source Class Reference
Loading...
Searching...
No Matches
alerts::Source Class Referencefinal

#include <userver/alerts/source.hpp>

Detailed Description

Alert source instance which is used to fire alerts via metrics for a specified amount of time.

To declare an alert:

const alerts::Source kLogReopeningAlert{"log_reopening_error"};

Tu fire or to stop an alert:

if (error_happened) {
kLogReopeningAlert.FireAlert(*metrics_storage_);
ReportReopeningErrorAndThrow(failed_loggers, result_messages);
} else {
kLogReopeningAlert.StopAlertNow(*metrics_storage_);
}

For non alert-metrics consider using utils::statistics::MetricTag.

Definition at line 36 of file source.hpp.

Public Member Functions

 Source (std::string_view name)
 
void FireAlert (utils::statistics::MetricsStorage &storage, std::chrono::seconds duration=kDefaultDuration) const
 Fire alert for duration seconds.
 
void StopAlertNow (utils::statistics::MetricsStorage &storage) const
 Stop fired alert.
 

Static Public Attributes

static constexpr std::chrono::seconds kDefaultDuration {120}
 
static constexpr std::chrono::hours kInfiniteDuration {24 * 365 * 10}
 

Constructor & Destructor Documentation

◆ Source()

alerts::Source::Source ( std::string_view name)
explicit

Constructs an alert source instance that will be reported as non-zero "alerts." + std::string{name} metric in case of error

Member Data Documentation

◆ kDefaultDuration

std::chrono::seconds alerts::Source::kDefaultDuration {120}
staticconstexpr

Definition at line 38 of file source.hpp.

◆ kInfiniteDuration

std::chrono::hours alerts::Source::kInfiniteDuration {24 * 365 * 10}
staticconstexpr

Definition at line 39 of file source.hpp.


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