Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
kcenon::monitoring::monitoring_data Struct Reference

Container for monitoring metrics from a component. More...

#include <monitorable_interface.h>

Collaboration diagram for kcenon::monitoring::monitoring_data:
Collaboration graph

Public Types

using metric_map = std::unordered_map<std::string, double>
 
using tag_map = std::unordered_map<std::string, std::string>
 

Public Member Functions

 monitoring_data ()
 Default constructor.
 
 monitoring_data (const std::string &name)
 Constructor with component name.
 
void add_metric (const std::string &key, double value)
 Add a numeric metric.
 
void add_tag (const std::string &key, const std::string &value)
 Add a tag (string metadata)
 
std::optional< double > get_metric (const std::string &key) const
 Get a metric value.
 
std::optional< std::string > get_tag (const std::string &key) const
 Get a tag value.
 
const metric_mapget_metrics () const
 Get all metrics.
 
const tag_mapget_tags () const
 Get all tags.
 
std::chrono::system_clock::time_point get_timestamp () const
 Get the timestamp.
 
const std::string & get_component_name () const
 Get the component name.
 
void set_component_name (const std::string &name)
 Set the component name.
 
void clear ()
 Clear all metrics and tags.
 
bool empty () const
 Check if data is empty.
 
std::size_t metric_count () const
 Get the number of metrics.
 
std::size_t tag_count () const
 Get the number of tags.
 
void merge (const monitoring_data &other, const std::string &prefix="")
 Merge another monitoring_data into this one.
 

Private Attributes

metric_map metrics_
 
tag_map tags_
 
std::chrono::system_clock::time_point timestamp_
 
std::string component_name_
 

Detailed Description

Container for monitoring metrics from a component.

This structure holds key-value pairs of metrics that a component exposes for monitoring purposes. It supports both numeric metrics and string tags for additional metadata.

Thread Safety:
This class is NOT inherently thread-safe. When accessed from multiple threads, external synchronization is required. Consider using mutable with mutex for thread-safe access in derived classes.

Definition at line 63 of file monitorable_interface.h.

Member Typedef Documentation

◆ metric_map

◆ tag_map

Constructor & Destructor Documentation

◆ monitoring_data() [1/2]

kcenon::monitoring::monitoring_data::monitoring_data ( )
inline

Default constructor.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/monitorable_interface.h.

Definition at line 77 of file monitorable_interface.h.

78 : timestamp_(std::chrono::system_clock::now()) {}
std::chrono::system_clock::time_point timestamp_

◆ monitoring_data() [2/2]

kcenon::monitoring::monitoring_data::monitoring_data ( const std::string & name)
inlineexplicit

Constructor with component name.

Parameters
nameName of the component being monitored

Definition at line 84 of file monitorable_interface.h.

85 : timestamp_(std::chrono::system_clock::now())
86 , component_name_(name) {}

Member Function Documentation

◆ add_metric()

void kcenon::monitoring::monitoring_data::add_metric ( const std::string & key,
double value )
inline

◆ add_tag()

void kcenon::monitoring::monitoring_data::add_tag ( const std::string & key,
const std::string & value )
inline

◆ clear()

void kcenon::monitoring::monitoring_data::clear ( )
inline

Clear all metrics and tags.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/monitorable_interface.h.

Definition at line 175 of file monitorable_interface.h.

175 {
176 metrics_.clear();
177 tags_.clear();
178 }

References metrics_, and tags_.

Referenced by kcenon::monitoring::monitorable_component::reset_monitoring(), and TEST_F().

Here is the caller graph for this function:

◆ empty()

bool kcenon::monitoring::monitoring_data::empty ( ) const
inline

Check if data is empty.

Returns
true if no metrics or tags are present
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/monitorable_interface.h.

Definition at line 184 of file monitorable_interface.h.

184 {
185 return metrics_.empty() && tags_.empty();
186 }

References metrics_, and tags_.

Referenced by TEST_F(), and TEST_F().

Here is the caller graph for this function:

◆ get_component_name()

const std::string & kcenon::monitoring::monitoring_data::get_component_name ( ) const
inline

Get the component name.

Returns
Name of the monitored component
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/monitorable_interface.h.

Definition at line 160 of file monitorable_interface.h.

160 {
161 return component_name_;
162 }

References component_name_.

Referenced by kcenon::monitoring::prometheus_exporter::convert_monitoring_data(), kcenon::monitoring::statsd_exporter::convert_monitoring_data(), and TEST_F().

Here is the caller graph for this function:

◆ get_metric()

std::optional< double > kcenon::monitoring::monitoring_data::get_metric ( const std::string & key) const
inline

Get a metric value.

Parameters
keyMetric name
Returns
Optional containing the value if found
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/monitorable_interface.h.

Definition at line 111 of file monitorable_interface.h.

111 {
112 auto it = metrics_.find(key);
113 if (it != metrics_.end()) {
114 return it->second;
115 }
116 return std::nullopt;
117 }

References metrics_.

Referenced by TEST_F(), TEST_F(), and TEST_F().

Here is the caller graph for this function:

◆ get_metrics()

const metric_map & kcenon::monitoring::monitoring_data::get_metrics ( ) const
inline

◆ get_tag()

std::optional< std::string > kcenon::monitoring::monitoring_data::get_tag ( const std::string & key) const
inline

Get a tag value.

Parameters
keyTag name
Returns
Optional containing the value if found
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/monitorable_interface.h.

Definition at line 124 of file monitorable_interface.h.

124 {
125 auto it = tags_.find(key);
126 if (it != tags_.end()) {
127 return it->second;
128 }
129 return std::nullopt;
130 }

References tags_.

Referenced by TEST_F(), TEST_F(), and TEST_F().

Here is the caller graph for this function:

◆ get_tags()

const tag_map & kcenon::monitoring::monitoring_data::get_tags ( ) const
inline

◆ get_timestamp()

std::chrono::system_clock::time_point kcenon::monitoring::monitoring_data::get_timestamp ( ) const
inline

◆ merge()

void kcenon::monitoring::monitoring_data::merge ( const monitoring_data & other,
const std::string & prefix = "" )
inline

Merge another monitoring_data into this one.

Parameters
otherData to merge
prefixOptional prefix for merged metrics
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/monitorable_interface.h.

Definition at line 209 of file monitorable_interface.h.

209 {
210 for (const auto& [key, value] : other.metrics_) {
211 if (prefix.empty()) {
212 metrics_[key] = value;
213 } else {
214 metrics_[prefix + "." + key] = value;
215 }
216 }
217
218 for (const auto& [key, value] : other.tags_) {
219 if (prefix.empty()) {
220 tags_[key] = value;
221 } else {
222 tags_[prefix + "." + key] = value;
223 }
224 }
225 }

References metrics_, kcenon::monitoring::other, and tags_.

Referenced by kcenon::monitoring::monitoring_aggregator::collect_all(), and TEST_F().

Here is the caller graph for this function:

◆ metric_count()

std::size_t kcenon::monitoring::monitoring_data::metric_count ( ) const
inline

Get the number of metrics.

Returns
Count of metrics
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/monitorable_interface.h.

Definition at line 192 of file monitorable_interface.h.

192 {
193 return metrics_.size();
194 }

References metrics_.

Referenced by kcenon::monitoring::monitoring_aggregator::collect_all(), TEST_F(), TEST_F(), and TEST_F().

Here is the caller graph for this function:

◆ set_component_name()

void kcenon::monitoring::monitoring_data::set_component_name ( const std::string & name)
inline

Set the component name.

Parameters
nameComponent name
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/monitorable_interface.h.

Definition at line 168 of file monitorable_interface.h.

168 {
169 component_name_ = name;
170 }

References component_name_.

Referenced by kcenon::monitoring::monitorable_component::reset_monitoring().

Here is the caller graph for this function:

◆ tag_count()

std::size_t kcenon::monitoring::monitoring_data::tag_count ( ) const
inline

Get the number of tags.

Returns
Count of tags
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/monitorable_interface.h.

Definition at line 200 of file monitorable_interface.h.

200 {
201 return tags_.size();
202 }

References tags_.

Referenced by TEST_F(), TEST_F(), and TEST_F().

Here is the caller graph for this function:

Member Data Documentation

◆ component_name_

std::string kcenon::monitoring::monitoring_data::component_name_
private

◆ metrics_

◆ tags_

◆ timestamp_

std::chrono::system_clock::time_point kcenon::monitoring::monitoring_data::timestamp_
private

The documentation for this struct was generated from the following file: