Telemetry#
Macros for Sensing Metrics#
The following macros should be used for triggering sending metrics manually.
Defines
-
STAT(name, value)#
Trigger a metric to be sent with a given value. The value expression is only evaluated if sending should take place.
- Parameters:
name – Name of the metric
value – Value or function returning the value of the metric
-
STAT_IF(name, value, condition)#
Trigger a metric to be sent with a given value if the given condition is met. The given condition is evaluated after it was evaluated if sending should take place.
- Parameters:
name – Name of the metric
value – Value or function returning the value of the metric
condition – Expression returning a bool if the metric should be triggered
-
STAT_NTH(name, value, count)#
Trigger a metric to be sent every nth call.
- Parameters:
name – Name of the metric
value – Value or function returning the value of the metric
count – Interval of calls at which the metric should be triggered
-
STAT_T(name, value, interval)#
Trigger a metric to be sent at most every t seconds.
- Parameters:
name – Name of the metric
value – Value or function returning the value of the metric
interval – Time interval at which the metric should be triggered
Note
The value within the STAT
macros can be a function. This way the function retrieving the value is only executed when the
conditions are met and there is at least one subscriber for the metric.
constellation::metrics
Namespace#
-
enum class constellation::metrics::MetricType : std::uint8_t#
Metrics types
Values:
-
enumerator LAST_VALUE#
Always keep the latest value, replace earlier ones
-
enumerator ACCUMULATE#
Sum every new value to previously received ones
-
enumerator AVERAGE#
Calculate the average value
-
enumerator RATE#
Calculate the rate from the value over a given time interval
-
enumerator LAST_VALUE#
-
class InvalidMetricValueException : public constellation::utils::LogicError#
- #include <constellation/core/metrics/exceptions.hpp>
Value of a metric has an invalid type.
Public Functions
-
inline explicit InvalidMetricValueException(std::string_view name, std::string_view type)#
-
inline explicit InvalidMetricValueException(std::string_view name, std::string_view type)#
-
class Metric#
- #include <constellation/core/metrics/Metric.hpp>
This class represents a metric for telemetry or data quality monitoring.
It comprises a name, a unit and a type. The type defines how the value should be treated, i.e. if always the last transmitted value should be displayed, if an average of the values should be calculated or if they should be accumulated.
Subclassed by constellation::metrics::TimedMetric
Public Functions
-
inline Metric(std::string name, std::string unit, MetricType type)#
Metric constructor.
- Parameters:
name – Name of the metric
unit – Unit of the metric as human readable string
type – Type of the metric
-
inline std::string_view name() const#
Obtain the name of the metrics.
- Returns:
Name of the metric
-
inline std::string_view unit() const#
Obtain unit as human-readable string.
- Returns:
Unit of the metric
-
inline MetricType type() const#
Obtain type of the metric.
- Returns:
Metric type
-
inline Metric(std::string name, std::string unit, MetricType type)#
-
class MetricsManager#
- #include <constellation/core/metrics/MetricsManager.hpp>
Manager for Metrics handling & transmission
Public Functions
-
virtual ~MetricsManager() noexcept#
Register a (manually triggered) metric
- Parameters:
metric – Shared pointer to the metric
-
void registerMetric(std::string name, std::string unit, metrics::MetricType type)#
Register a (manually triggered) metric
- Parameters:
name – Unique topic of the metric
unit – Unit of the provided value
type – Type of the metric
Register a timed metric
- Parameters:
metric – Shared pointer to the timed metric
-
template<typename C>
void registerTimedMetric(std::string name, std::string unit, metrics::MetricType type, std::chrono::steady_clock::duration interval, C value_callback)# Register a timed metric
- Parameters:
name – Name of the metric
unit – Unit of the metric as human readable string
type – Type of the metric
interval – Interval in which to send the metric
value_callback – Callback to determine the current value of the metric
-
void unregisterMetric(std::string_view name)#
Unregister a previously registered metric from the manager
- Parameters:
name – Name of the metric
-
void unregisterMetrics()#
Unregisters all metrics registered in the manager
Equivalent to calling
unregisterMetric
for every registered metric.
-
void triggerMetric(std::string name, config::Value value)#
Manually trigger a metric
- Parameters:
name – Name of the metric
value – Value of the metric
Public Static Functions
-
static MetricsManager &getInstance()#
Return instance of metrics manager.
-
static inline bool shouldStat(std::string_view)#
Check if a metric should be send given the subscription status
-
virtual ~MetricsManager() noexcept#
-
class MetricValue#
- #include <constellation/core/metrics/Metric.hpp>
Class containing a pointer to a metric and a corresponding metric value.
Public Functions
Metric value constructor.
- Parameters:
metric – Shared pointer to a metric
value – Value corresponding to the metric
-
MetricValue() = default#
-
inline std::shared_ptr<Metric> getMetric() const#
Obtain the underlying metric.
- Returns:
Shared pointer tot the metric
-
inline const config::Value &getValue() const#
Obtain the metric value.
- Returns:
Value of the metric
-
message::PayloadBuffer assemble() const#
Assemble metric via msgpack for message payload
Public Static Functions
-
static MetricValue disassemble(std::string name, const message::PayloadBuffer &message)#
Disassemble metric from message payload
-
class TimedMetric : public constellation::metrics::Metric#
- #include <constellation/core/metrics/Metric.hpp>
This class represents a timed metric for telemetry or data quality monitoring.
A timed metric is a metric that is polled in regular intervals. It requires an interval, a value callback, and a list of states where the callback is allowed to be called.
Public Functions
-
inline TimedMetric(std::string name, std::string unit, MetricType type, std::chrono::nanoseconds interval, std::function<std::optional<config::Value>()> value_callback)#
Timed metric constructor.
- Parameters:
name – Name of the metric
unit – Unit of the metric as human readable string
type – Type of the metric
interval – Interval in which to send the metric
value_callback – Callback to determine the current value of the metric
-
inline std::chrono::nanoseconds interval() const#
Obtain interval of the metric.
- Returns:
Interval in nanoseconds
-
inline std::optional<config::Value> currentValue()#
Evaluate the value callback to get the current value of the metric.
- Returns:
Optional with current value or no value
-
inline TimedMetric(std::string name, std::string unit, MetricType type, std::chrono::nanoseconds interval, std::function<std::optional<config::Value>()> value_callback)#