|
Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
|
Thread-safe metric storage with ring buffer buffering. More...
#include <metric_storage.h>

Classes | |
| struct | validated_tag |
Public Member Functions | |
| metric_storage (const metric_storage_config &config={}) | |
| Constructor with configuration. | |
| metric_storage (const metric_storage &)=delete | |
| metric_storage & | operator= (const metric_storage &)=delete |
| ~metric_storage () | |
| Destructor. | |
| common::VoidResult | store_metric (const std::string &name, double value, metric_type type=metric_type::gauge) |
| Store a single metric value. | |
| size_t | store_metrics_batch (const metric_batch &batch) |
| Store a batch of metrics. | |
| void | flush () |
| Flush buffered metrics to time series. | |
| common::Result< double > | get_latest_value (const std::string &name) const |
| Get the latest value for a metric. | |
| std::vector< std::string > | get_metric_names () const |
| Get all metric names. | |
| common::Result< aggregation_result > | query_metric (const std::string &name, const time_series_query &query) const |
| Query metric data. | |
| const metric_storage_stats & | get_stats () const noexcept |
| Get storage statistics. | |
| const metric_storage_config & | get_config () const noexcept |
| Get configuration. | |
| void | clear () |
| Clear all stored metrics. | |
| size_t | series_count () const |
| Get number of active metric series. | |
| size_t | memory_footprint () const |
| Get memory footprint estimate. | |
Static Public Member Functions | |
| static common::Result< std::unique_ptr< metric_storage > > | create (const metric_storage_config &config={}) |
| Create a metric storage with validated configuration. | |
Private Member Functions | |
| void | background_processor () |
| Background processing loop. | |
| time_series * | get_or_create_series (const std::string &name) |
| Get or create time series for a metric. | |
| void | init_internals () |
| metric_storage (const metric_storage_config &config, validated_tag) | |
Private Attributes | |
| std::shared_mutex | mutex_ |
| metric_storage_config | config_ |
| metric_storage_stats | stats_ |
| std::unique_ptr< ring_buffer< compact_metric_value > > | incoming_buffer_ |
| std::unordered_map< std::string, std::unique_ptr< time_series > > | time_series_map_ |
| std::unordered_map< uint32_t, std::string > | hash_to_name_ |
| std::atomic< bool > | running_ {false} |
| std::thread | background_thread_ |
Thread-safe metric storage with ring buffer buffering.
Provides efficient metric storage using ring buffers for incoming data and time series for historical queries. Supports background processing for automatic flushing.
Definition at line 95 of file metric_storage.h.
|
inlineprivate |
Definition at line 177 of file metric_storage.h.
References init_internals().
Referenced by memory_footprint().


|
inlineexplicit |
Constructor with configuration.
| config | Metric storage configuration options |
| std::invalid_argument | if configuration validation fails |
Definition at line 208 of file metric_storage.h.
|
delete |
|
inline |
Destructor.
Definition at line 227 of file metric_storage.h.
References background_thread_, and running_.
|
inlineprivate |
Background processing loop.
Definition at line 119 of file metric_storage.h.
References config_, flush(), kcenon::monitoring::metric_storage_config::flush_interval, and running_.
Referenced by init_internals().


|
inline |
Clear all stored metrics.
Definition at line 396 of file metric_storage.h.
References kcenon::monitoring::metric_storage_stats::active_metric_series, hash_to_name_, incoming_buffer_, mutex_, stats_, and time_series_map_.
|
inlinestatic |
Create a metric storage with validated configuration.
| config | Metric storage configuration options |
Definition at line 188 of file metric_storage.h.
Referenced by TEST_F(), and TEST_F().

|
inline |
Flush buffered metrics to time series.
Definition at line 290 of file metric_storage.h.
References config_, kcenon::monitoring::metric_storage_stats::failed_flushes, kcenon::monitoring::metric_storage_stats::flush_count, get_or_create_series(), hash_to_name_, incoming_buffer_, mutex_, kcenon::monitoring::metric_storage_config::ring_buffer_capacity, and stats_.
Referenced by background_processor(), and TEST_F().


|
inlinenoexcept |
|
inline |
Get the latest value for a metric.
| name | Metric name |
Definition at line 331 of file metric_storage.h.
References kcenon::monitoring::collection_failed, mutex_, and time_series_map_.
|
inline |
Get all metric names.
Definition at line 347 of file metric_storage.h.
References mutex_, and time_series_map_.
|
inlineprivate |
Get or create time series for a metric.
Definition at line 131 of file metric_storage.h.
References kcenon::monitoring::metric_storage_stats::active_metric_series, config_, kcenon::monitoring::time_series::create(), kcenon::monitoring::hash_metric_name(), hash_to_name_, kcenon::monitoring::metric_storage_config::max_metrics, kcenon::monitoring::time_series_config::max_points, kcenon::monitoring::metric_storage_config::retention_period, kcenon::monitoring::time_series_config::retention_period, stats_, time_series_map_, and kcenon::monitoring::metric_storage_config::time_series_max_points.
Referenced by flush().


|
inlinenoexcept |
|
inlineprivate |
Definition at line 162 of file metric_storage.h.
References background_processor(), background_thread_, kcenon::monitoring::ring_buffer_config::batch_size, kcenon::monitoring::ring_buffer_config::capacity, config_, kcenon::monitoring::metric_storage_config::enable_background_processing, incoming_buffer_, kcenon::monitoring::ring_buffer_config::overwrite_old, kcenon::monitoring::metric_storage_config::ring_buffer_capacity, and running_.
Referenced by metric_storage().


|
inline |
Get memory footprint estimate.
Definition at line 415 of file metric_storage.h.
References config_, metric_storage(), mutex_, kcenon::monitoring::metric_storage_config::ring_buffer_capacity, and time_series_map_.

|
delete |
|
inline |
Query metric data.
| name | Metric name |
| query | Query parameters |
Definition at line 366 of file metric_storage.h.
References kcenon::monitoring::collection_failed, mutex_, and time_series_map_.
|
inline |
Get number of active metric series.
Definition at line 407 of file metric_storage.h.
References mutex_, and time_series_map_.
|
inline |
Store a single metric value.
| name | Metric name |
| value | Metric value |
| type | Metric type (default: gauge) |
Definition at line 243 of file metric_storage.h.
References kcenon::monitoring::create_metric_metadata(), hash_to_name_, incoming_buffer_, mutex_, stats_, kcenon::monitoring::metric_storage_stats::total_metrics_dropped, and kcenon::monitoring::metric_storage_stats::total_metrics_stored.

|
inline |
Store a batch of metrics.
| batch | Metric batch to store |
Definition at line 270 of file metric_storage.h.
References incoming_buffer_, kcenon::monitoring::metric_batch::metrics, stats_, kcenon::monitoring::metric_storage_stats::total_metrics_dropped, and kcenon::monitoring::metric_storage_stats::total_metrics_stored.
|
private |
Definition at line 114 of file metric_storage.h.
Referenced by init_internals(), and ~metric_storage().
|
private |
Definition at line 100 of file metric_storage.h.
Referenced by background_processor(), flush(), get_config(), get_or_create_series(), init_internals(), and memory_footprint().
|
private |
Definition at line 110 of file metric_storage.h.
Referenced by clear(), flush(), get_or_create_series(), and store_metric().
|
private |
Definition at line 104 of file metric_storage.h.
Referenced by clear(), flush(), init_internals(), store_metric(), and store_metrics_batch().
|
mutableprivate |
Definition at line 99 of file metric_storage.h.
Referenced by clear(), flush(), get_latest_value(), get_metric_names(), memory_footprint(), query_metric(), series_count(), and store_metric().
|
private |
Definition at line 113 of file metric_storage.h.
Referenced by background_processor(), init_internals(), and ~metric_storage().
|
mutableprivate |
Definition at line 101 of file metric_storage.h.
Referenced by clear(), flush(), get_or_create_series(), get_stats(), store_metric(), and store_metrics_batch().
|
private |
Definition at line 107 of file metric_storage.h.
Referenced by clear(), get_latest_value(), get_metric_names(), get_or_create_series(), memory_footprint(), query_metric(), and series_count().