Telemetry#

Macros for Sending 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#

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)#
class Metric#
#include <constellation/core/metrics/Metric.hpp>

This class represents a metric for telemetry or data quality monitoring.

Subclassed by constellation::metrics::TimedMetric

Public Functions

inline Metric(std::string name, std::string unit, std::string description = "")#

Metric constructor.

Parameters:
  • name – Name of the metric

  • unit – Unit of the metric as human readable string

  • description – Description of the metric

inline std::string_view name() const#

Obtain the name of the metric.

Returns:

Name of the metric

inline std::string_view unit() const#

Obtain unit as human-readable string.

Returns:

Unit of the metric

inline std::string_view description() const#

Obtain the description of the metric.

Returns:

Description of the metric

class MetricsManager#
#include <constellation/core/metrics/MetricsManager.hpp>

Manager for Metrics handling & transmission

Public Functions

virtual ~MetricsManager() noexcept#
void registerMetric(std::shared_ptr<Metric> metric)#

Register a (manually triggered) metric

Parameters:

metric – Shared pointer to the metric

void registerMetric(std::string name, std::string unit, std::string description)#

Register a (manually triggered) metric

Parameters:
  • name – Unique topic of the metric

  • unit – Unit of the provided value

  • description – Description of the metric

void registerTimedMetric(std::shared_ptr<TimedMetric> metric)#

Register a timed metric

Parameters:

metric – Shared pointer to the timed metric

template<typename C>
void registerTimedMetric(std::string name, std::string unit, std::string description, 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

  • description – Description 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.

bool shouldStat(std::string_view name) const#

Check if a metric should be send given the subscription status

template<typename T>
void triggerMetric(std::string name, const T &value)#

Manually trigger a metric

Parameters:
  • name – Name of the metric

  • value – Value of the metric

void updateSubscriptions(bool global, utils::string_hash_set topic_subscriptions = {})#

Update topic subscriptions.

Parameters:
  • global – Global Flag for global subscription to all topics

  • topic_subscriptions – List of individual subscription topics

std::map<std::string, std::string> getMetricsDescriptions() const#

Obtain map of registered metrics along with their descriptions.

Returns:

Map with metric descriptions

class MetricValue#
#include <constellation/core/metrics/Metric.hpp>

Class containing a pointer to a metric and a corresponding metric value.

Public Functions

inline MetricValue(std::shared_ptr<Metric> metric, config::Scalar &&value)#

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::Scalar &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, std::string description, std::chrono::nanoseconds interval, std::function<std::optional<config::Scalar>()> value_callback)#

Timed metric constructor.

Parameters:
  • name – Name of the metric

  • unit – Unit of the metric as human readable string

  • description – Description 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::Scalar> currentValue()#

Evaluate the value callback to get the current value of the metric.

Returns:

Optional with current value or no value