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

Basic metric structure for interface compatibility. More...

#include <metric_types_adapter.h>

Collaboration diagram for kcenon::monitoring::metric:
Collaboration graph

Public Member Functions

 metric ()
 
 metric (const std::string &n, const std::variant< double, int64_t, std::string > &v, const std::unordered_map< std::string, std::string > &t, metric_type mt=metric_type::gauge)
 
compact_metric_value to_compact () const
 

Public Attributes

std::string name
 
std::variant< double, int64_t, std::string > value
 
std::unordered_map< std::string, std::string > tags
 
metric_type type {metric_type::gauge}
 
std::chrono::system_clock::time_point timestamp
 

Detailed Description

Basic metric structure for interface compatibility.

A generic metric container that can hold different value types (double, int64_t, or string) along with metadata tags and type information. Supports conversion to compact representation for efficient storage.

Thread Safety:
This struct is NOT thread-safe. External synchronization is required when accessed from multiple threads.
Examples
basic_monitoring_example.cpp, bidirectional_di_example.cpp, monitor_factory_pattern_example.cpp, plugin_collector_example.cpp, plugin_example/plugin_loader_example.cpp, and storage_example.cpp.

Definition at line 53 of file metric_types_adapter.h.

Constructor & Destructor Documentation

◆ metric() [1/2]

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

Definition at line 60 of file metric_types_adapter.h.

60: timestamp(std::chrono::system_clock::now()) {}
std::chrono::system_clock::time_point timestamp

◆ metric() [2/2]

kcenon::monitoring::metric::metric ( const std::string & n,
const std::variant< double, int64_t, std::string > & v,
const std::unordered_map< std::string, std::string > & t,
metric_type mt = metric_type::gauge )
inline

Definition at line 62 of file metric_types_adapter.h.

65 : name(n), value(v), tags(t), type(mt),
66 timestamp(std::chrono::system_clock::now()) {}
std::variant< double, int64_t, std::string > value
std::unordered_map< std::string, std::string > tags

Member Function Documentation

◆ to_compact()

compact_metric_value kcenon::monitoring::metric::to_compact ( ) const
inline
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/metric_types_adapter.h.

Definition at line 69 of file metric_types_adapter.h.

69 {
70 // Simple hash function for name
71 uint32_t hash = 0;
72 for (char c : name) {
73 hash = hash * 31 + static_cast<uint32_t>(c);
74 }
75
76 metric_metadata meta(hash, type, static_cast<uint8_t>(tags.size()));
77
78 if (std::holds_alternative<double>(value)) {
79 return compact_metric_value(meta, std::get<double>(value));
80 } else if (std::holds_alternative<int64_t>(value)) {
81 return compact_metric_value(meta, std::get<int64_t>(value));
82 } else {
83 return compact_metric_value(meta, std::get<std::string>(value));
84 }
85 }

References name, tags, type, and value.

Member Data Documentation

◆ name

◆ tags

◆ timestamp

◆ type

◆ value


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