48 EAlertLevel Evaluate(
const float value,
const float warningThreshold,
const float alertThreshold,
const bool higherIsWorse);
67 std::string
BuildMessage(
const std::string& metricName,
const float value,
const float threshold);
172 void Check(
const std::string& metricName,
const float value,
const float warningThreshold,
const float alertThreshold,
const bool higherIsWorse);
A single alert event: a metric crossing (or recovering from) a threshold, with the reading that trigg...
Definition: AlertEvent.h:13
A singleton that components hand readings to.
Definition: AlertManager.h:16
void Unsubscribe(std::size_t subscription)
Removes a previously registered callback by its handle; unknown or already-removed handles are ignore...
Definition: AlertManager.cpp:94
std::size_t myNextSubscriberId
Monotonic source of subscription handles; only ever increments so a handle is never reused.
Definition: AlertManager.h:28
std::size_t Subscribe(std::function< void(const AlertEvent &)> callback)
Registers a callback (e.g.
Definition: AlertManager.cpp:70
AlertManager(const AlertManager &)=delete
Singletons must not be copied or moved.
virtual ~AlertManager()
Destroys the alert manager.
Definition: AlertManager.cpp:31
void CopySubscribersLocked(std::vector< std::function< void(const AlertEvent &)> > &outSubscribers) const
Copies the current subscriber callbacks into outSubscribers so the dispatch loop can run them after t...
Definition: AlertManager.cpp:115
std::map< std::size_t, std::function< void(const AlertEvent &)> > mySubscribers
Who to notify, keyed by the handle Subscribe() hands out so Unsubscribe() can remove one.
Definition: AlertManager.h:22
AlertManager()
Builds the alert manager, starting subscription handles at 1.
Definition: AlertManager.cpp:16
std::string BuildMessage(const std::string &metricName, const float value, const float threshold)
Builds a "metric = value (threshold N)" summary string for an alert event.
Definition: AlertManager.cpp:354
EAlertLevel Evaluate(const float value, const float warningThreshold, const float alertThreshold, const bool higherIsWorse)
Evaluates a reading against its warning/alert thresholds, using higherIsWorse to choose the direction...
Definition: AlertManager.cpp:142
std::mutex myMutex
Guards the subscriber map, the per-metric levels, and the subscription-id counter below.
Definition: AlertManager.h:19
static AlertManager & GetInstance()
Gets the singleton instance, constructing it thread-safely on first call.
Definition: AlertManager.cpp:48
AlertManager & operator=(const AlertManager &)=delete
void Report(const EAlertLevel level, const std::string &message)
Logs a free-text message (a failure, error, or trace) through the alert system.
Definition: AlertManager.cpp:272
static std::string LevelToString(const EAlertLevel level)
Converts an alert level to its display string, useful for subscribers that want to format the level.
Definition: AlertManager.cpp:317
void Check(const std::string &metricName, const float value, const float warningThreshold, const float alertThreshold, const bool higherIsWorse)
A component calls this after each read: evaluates the reading, and only when the metric changes level...
Definition: AlertManager.cpp:191
std::map< std::string, EAlertLevel > myLastLevels
Last level seen per metric.
Definition: AlertManager.h:25
RumPi is the library's top-level facade.
Definition: AlertManager.h:6
EAlertLevel
Severity of a metric relative to its thresholds.
Definition: Common.h:94