29 Metric::Metric(
const std::vector<std::string>& name,
const std::map<std::string, std::string>& tags,
const std::string& unit) noexcept :
39 Metric::Metric(std::vector<std::string>&& name, std::map<std::string, std::string>&& tags, std::string&& unit) noexcept :
51 roundKey_(other.roundKey_),
53 previousValue_(other.previousValue_),
55 timestamp_(other.timestamp_),
62 roundKey_(other.roundKey_),
63 name_(std::move(other.name_)),
64 previousValue_(other.previousValue_),
66 timestamp_(other.timestamp_),
67 unit_(std::move(other.unit_)),
68 tags_(std::move(other.tags_))
72 this->key_ = other.
key_;
73 this->roundKey_ = other.roundKey_;
74 std::swap(this->name_, other.name_);
75 this->previousValue_ = other.previousValue_;
76 this->value_ = other.value_;
77 this->timestamp_ = other.timestamp_;
78 std::swap(this->unit_, other.unit_);
79 std::swap(this->tags_, other.tags_);
84 size_t Metric::generateKey(
const std::vector<std::string>& name,
const std::map<std::string, std::string>& tags) {
86 for (
const auto& n :
name)
88 for (
const auto& [k, v] :
tags) {
119 const std::map<std::string, std::string>&
Metric::tags() const noexcept {
126 this->value_ = value - this->previousValue_;
128 this->value_ = value;
129 this->previousValue_ = value;
130 this->value_ *= unitsPerSecondFactor;
134 this->value_ /= unitsPerSecondFactor;
135 this->value_ += value;
136 this->previousValue_ += value;
137 this->value_ *= unitsPerSecondFactor;
141 this->timestamp_ = timestamp;
145 this->roundKey_ = roundKey;
void setTimestamp(std::chrono::system_clock::time_point timestamp) noexcept
Sets the timestamp of the metric.
void setNewValue(double value, bool computeRate, double unitsPerSecondFactor=1.0) noexcept
Sets a new value to the metric.
std::vector< std::string > name_
Array of strings representing the name of the metric.
size_t key() const noexcept
Returns the key of the metric.
Metric()=delete
Deleted default constructor.
const std::string & unit() const noexcept
Returns the unit of the metric.
const std::vector< std::string > & name() const noexcept
Returns the name of the metric.
size_t key_
Key of the metric (hash of its name, tag keys and tags values)
static size_t generateKey(const std::vector< std::string > &name, const std::map< std::string, std::string > &tags)
Compute the key of potential metric.
std::string unit_
Unit of the metric.
std::chrono::system_clock::time_point timestamp_
Timestamp of the metric.
size_t roundKey() const noexcept
Returns the key of the collection iteration which created the metric.
std::chrono::system_clock::time_point timestamp() const noexcept
Returns the timestamp of the metric.
size_t roundKey_
Key of the collection iteration which created this metric.
const std::map< std::string, std::string > & tags() const noexcept
Returns the tags of the metric.
std::map< std::string, std::string > tags_
Tags of the metric.
double value_
Current value of the metric.
Class used to represent a metric object (with a name, unit, tags, a value and a timestamp) ...
void setRoundKey(size_t roundKey) noexcept
Sets the round key of the metric.
Metric & operator=(Metric other) noexcept
Assignment operator.
static std::hash< std::string > hasher
Object used to compute keys (string hashes)
double value() const noexcept
Returns the value of the metric.
void updateValue(double value, double unitsPerSecondFactor=1.0) noexcept
Adds a new value to the current value.