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

Complete snapshot of metrics at a point in time. More...

#include <monitoring_core.h>

Collaboration diagram for kcenon::monitoring::metrics_snapshot:
Collaboration graph

Public Member Functions

 metrics_snapshot ()
 
void add_metric (const std::string &name, double value)
 Add a metric to the snapshot.
 
void add_metric (const std::string &name, double value, const std::unordered_map< std::string, std::string > &tags)
 Add a metric to the snapshot with tags.
 
std::optional< double > get_metric (const std::string &name) const
 Get a specific metric value.
 

Public Attributes

std::vector< metric_valuemetrics
 
std::chrono::system_clock::time_point capture_time
 
std::string source_id
 

Detailed Description

Complete snapshot of metrics at a point in time.

Examples
bidirectional_di_example.cpp, monitor_factory_pattern_example.cpp, and result_pattern_example.cpp.

Definition at line 64 of file monitoring_core.h.

Constructor & Destructor Documentation

◆ metrics_snapshot()

kcenon::monitoring::metrics_snapshot::metrics_snapshot ( )
inline
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/monitoring_core.h.

Definition at line 69 of file monitoring_core.h.

70 : capture_time(std::chrono::system_clock::now()) {}
std::chrono::system_clock::time_point capture_time

Member Function Documentation

◆ add_metric() [1/2]

void kcenon::monitoring::metrics_snapshot::add_metric ( const std::string & name,
double value )
inline

◆ add_metric() [2/2]

void kcenon::monitoring::metrics_snapshot::add_metric ( const std::string & name,
double value,
const std::unordered_map< std::string, std::string > & tags )
inline

Add a metric to the snapshot with tags.

Parameters
nameMetric name
valueMetric value
tagsMetadata tags for the metric

Definition at line 87 of file monitoring_core.h.

88 {
89 metric_value mv(name, value);
90 mv.tags = tags;
91 metrics.push_back(std::move(mv));
92 }

References metrics, and kcenon::monitoring::metric_value::tags.

◆ get_metric()

std::optional< double > kcenon::monitoring::metrics_snapshot::get_metric ( const std::string & name) const
inline

Get a specific metric value.

Parameters
nameMetric name
Returns
Optional metric value
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/monitoring_core.h, and result_pattern_example.cpp.

Definition at line 99 of file monitoring_core.h.

99 {
100 for (const auto& m : metrics) {
101 if (m.name == name) {
102 return m.value;
103 }
104 }
105 return std::nullopt;
106 }

References metrics.

Referenced by main(), and TEST_F().

Here is the caller graph for this function:

Member Data Documentation

◆ capture_time

◆ metrics

◆ source_id


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