metrics#

namespace heph
namespace telemetry

Functions

void registerMetricSink(std::unique_ptr<IMetricSink> sink)#

Register a new metric sink. For every metric recorded, the sink will be called to consume the data. There is no limit on the number of sinks supported.

void record(Metric metric)#

Record a metric. The metric is forwarded to all registered sinks. Sinks process the metric in a dedicated thread, this means that this function is non-blocking and deterministic.

void record(heph::UniqueFunction<Metric()> &&metric)#
template<typename DataT>
void record(std::string component, std::string tag, DataT &&data, ClockT::time_point timestamp = ClockT::now())#

Record a user defined metric. NOTE: the data needs to be serializable to JSON. For details on how to achieve this, see heph::serdes::serializeToJSON.

Parameters:
  • component – The component that is logging the metric_record, e.g. SLAM, Navigation, etc.

  • tag – The tag of the metric_record used to identify who created it, e.g. “front_camera”, “motor1”, etc.

  • data – The data to record, needs to be json serializable.

  • timestamp – The timestamp of the metric, if not provided, the current time is used.

void flushMetrics()#
namespace heph
namespace telemetry
namespace metric_sinks#
class TerminalMetricSink : public heph::telemetry::IMetricSink#

Public Functions

void send(const Metric &metric) override#
namespace heph
namespace telemetry
template<typename ClockT = std::chrono::steady_clock>
class ScopedDurationRecorder#
#include “/home/runner/.bazel/sandbox/processwrapper-sandbox/341/execroot/_main/modules/telemetry/metrics/include/hephaestus/telemetry/metrics/metric_scope.h”

Helper class to compute a scope time duration and add it to a Metric. The duration is added upon destruction of the scope. Example usage:

{
  Metric metric{
    .component = "component",
    .tag = "tag",
    .timestamp = now,
    .values = {},
  };
  {
    auto _ = ScopedDurationRecorder{metric, "key"};
    // code to measure
  }
  metric.addKeyValue("key.value_key", 42);
}
The above code creates the following metrics entry:
  • ”key.value_key” : 42

  • ”key.elapsed_s” : <elapsed time in seconds>

Public Types

using SecondsT = std::chrono::duration<double>#

Public Functions

inline ScopedDurationRecorder(Metric &metric, std::string_view key)#
inline ~ScopedDurationRecorder()#
ScopedDurationRecorder(const ScopedDurationRecorder&) = delete#
ScopedDurationRecorder(ScopedDurationRecorder&&) = delete#
ScopedDurationRecorder &=delete operator= (const ScopedDurationRecorder &)
ScopedDurationRecorder &=delete operator= (ScopedDurationRecorder &&)
struct ScopedMetric : public heph::telemetry::Metric#
#include “/home/runner/.bazel/sandbox/processwrapper-sandbox/341/execroot/_main/modules/telemetry/metrics/include/hephaestus/telemetry/metrics/metric_scope.h”

ScopedMetric is an extension for Metric that publish itself upon destruction. Example usage:

{
  ScopedMetric publisher{{
    .component = "component",
    .tag = "tag",
    .timestamp = now,
    .values = {};
  }};
  auto* metric = publisher.metric();
  addKeyValue(*metric, "key.value", 42);
  {
    ScopedDurationRecorder recorder{*metric, "key"};
  }
}
The above code records the following metric entries:
  • ”key.value” : 42

  • ”key.elapsed_s” : <elapsed time in seconds>

Public Functions

inline ScopedMetric(Metric &&metric)#
inline ~ScopedMetric()#
ScopedMetric(const ScopedMetric&) = delete#
ScopedMetric(ScopedMetric&&) = delete#
ScopedMetric &=delete operator= (const ScopedMetric &)
ScopedMetric &=delete operator= (ScopedMetric &&)
namespace heph
namespace telemetry
namespace heph
namespace telemetry
class IMetricSink#

Public Functions

virtual ~IMetricSink() = default#
virtual void send(const Metric&) = 0#
struct Metric#

Public Types

using ValueType = std::variant<int64_t, double, std::string, bool>#
using KeyValueType = std::pair<std::string, ValueType>#

Public Members

std::string component#

The component that is logging the metric_record, e.g. SLAM, Navigation, etc.

std::string tag#

The tag of the metric_record used to identify who created it, e.g. “front_camera”, “motor1”, etc.

ClockT::time_point timestamp#
std::vector<KeyValueType> values#

Public Functions

bool=default operator== (const Metric &) const
std::string toString() const#
template<typename T>
inline void addKeyValue(std::string key, T value)#

Typedefs

using ClockT = std::chrono::system_clock#
template<>
struct formatter<heph::telemetry::Metric> : public fmt::formatter<std::string_view>#

Public Static Functions

static inline auto format(const heph::telemetry::Metric &metric, fmt::format_context &ctx)#