|
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>

Public Member Functions | |
| metric_storage (const metric_storage_config &config={}) | |
| Constructor with configuration. | |
| ~metric_storage () | |
| Destructor. | |
| metric_storage (const metric_storage &)=delete | |
| metric_storage & | operator= (const metric_storage &)=delete |
| 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. | |
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. | |
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.
|
inlineexplicit |
Constructor with configuration.
| config | Metric storage configuration options |
| std::invalid_argument | if configuration validation fails |
Definition at line 166 of file metric_storage.h.
Referenced by memory_footprint().

|
inline |
Destructor.
Definition at line 193 of file metric_storage.h.
References background_thread_, and running_.
|
delete |
|
inlineprivate |
Background processing loop.
Definition at line 117 of file metric_storage.h.
References config_, flush(), kcenon::monitoring::metric_storage_config::flush_interval, and running_.

|
inline |
Clear all stored metrics.
Definition at line 366 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_.
|
inline |
Flush buffered metrics to time series.
Definition at line 260 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 301 of file metric_storage.h.
References kcenon::monitoring::collection_failed, mutex_, and time_series_map_.
|
inline |
Get all metric names.
Definition at line 317 of file metric_storage.h.
References mutex_, and time_series_map_.
|
inlineprivate |
Get or create time series for a metric.
Definition at line 129 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 |
|
inline |
Get memory footprint estimate.
Definition at line 385 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 336 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 377 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 213 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 240 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 112 of file metric_storage.h.
Referenced by ~metric_storage().
|
private |
Definition at line 98 of file metric_storage.h.
Referenced by background_processor(), flush(), get_config(), get_or_create_series(), and memory_footprint().
|
private |
Definition at line 108 of file metric_storage.h.
Referenced by clear(), flush(), get_or_create_series(), and store_metric().
|
private |
Definition at line 102 of file metric_storage.h.
Referenced by clear(), flush(), store_metric(), and store_metrics_batch().
|
mutableprivate |
Definition at line 97 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 111 of file metric_storage.h.
Referenced by background_processor(), and ~metric_storage().
|
mutableprivate |
Definition at line 99 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 105 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().