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

In-memory snapshot storage backend. More...

#include <storage_backends.h>

Inheritance diagram for kcenon::monitoring::memory_storage_backend:
Inheritance graph
Collaboration diagram for kcenon::monitoring::memory_storage_backend:
Collaboration graph

Public Member Functions

 memory_storage_backend ()
 
 memory_storage_backend (const storage_config &config)
 
common::Result< bool > store (const metrics_snapshot &snapshot) override
 
common::Result< metrics_snapshotretrieve (size_t index) override
 
common::Result< std::vector< metrics_snapshot > > retrieve_range (size_t start, size_t count) override
 
size_t size () const override
 
size_t capacity () const override
 
common::Result< bool > flush () override
 
common::Result< bool > clear () override
 
std::unordered_map< std::string, size_t > get_stats () const override
 
- Public Member Functions inherited from kcenon::monitoring::snapshot_storage_backend
virtual ~snapshot_storage_backend ()=default
 

Private Attributes

storage_config config_
 
std::deque< metrics_snapshotsnapshots_
 
std::mutex mutex_
 

Detailed Description

In-memory snapshot storage backend.

Definition at line 358 of file storage_backends.h.

Constructor & Destructor Documentation

◆ memory_storage_backend() [1/2]

kcenon::monitoring::memory_storage_backend::memory_storage_backend ( )
inline

Definition at line 360 of file storage_backends.h.

◆ memory_storage_backend() [2/2]

kcenon::monitoring::memory_storage_backend::memory_storage_backend ( const storage_config & config)
inlineexplicit

Definition at line 362 of file storage_backends.h.

363 : config_(config) {}

Member Function Documentation

◆ capacity()

size_t kcenon::monitoring::memory_storage_backend::capacity ( ) const
inlineoverridevirtual

◆ clear()

common::Result< bool > kcenon::monitoring::memory_storage_backend::clear ( )
inlineoverridevirtual

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 412 of file storage_backends.h.

412 {
413 std::lock_guard<std::mutex> lock(mutex_);
414 snapshots_.clear();
415 return common::ok(true);
416 }
std::deque< metrics_snapshot > snapshots_

References mutex_, and snapshots_.

◆ flush()

common::Result< bool > kcenon::monitoring::memory_storage_backend::flush ( )
inlineoverridevirtual

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 408 of file storage_backends.h.

408 {
409 return common::ok(true);
410 }

◆ get_stats()

std::unordered_map< std::string, size_t > kcenon::monitoring::memory_storage_backend::get_stats ( ) const
inlineoverridevirtual

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 418 of file storage_backends.h.

418 {
419 std::lock_guard<std::mutex> lock(mutex_);
420 return {
421 {"stored_count", snapshots_.size()},
422 {"capacity", config_.max_capacity}
423 };
424 }

References config_, kcenon::monitoring::storage_config::max_capacity, mutex_, and snapshots_.

◆ retrieve()

common::Result< metrics_snapshot > kcenon::monitoring::memory_storage_backend::retrieve ( size_t index)
inlineoverridevirtual

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 376 of file storage_backends.h.

376 {
377 std::lock_guard<std::mutex> lock(mutex_);
378
379 if (index >= snapshots_.size()) {
380 return common::Result<metrics_snapshot>::err(error_info(monitoring_error_code::not_found, "Snapshot index out of range").to_common_error());
381 }
382
383 return common::ok(snapshots_[index]);
384 }

References mutex_, kcenon::monitoring::not_found, and snapshots_.

◆ retrieve_range()

common::Result< std::vector< metrics_snapshot > > kcenon::monitoring::memory_storage_backend::retrieve_range ( size_t start,
size_t count )
inlineoverridevirtual

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 386 of file storage_backends.h.

386 {
387 std::lock_guard<std::mutex> lock(mutex_);
388
389 std::vector<metrics_snapshot> result;
390 size_t end = std::min(start + count, snapshots_.size());
391
392 for (size_t i = start; i < end; ++i) {
393 result.push_back(snapshots_[i]);
394 }
395
396 return common::ok(std::move(result));
397 }

References mutex_, and snapshots_.

◆ size()

size_t kcenon::monitoring::memory_storage_backend::size ( ) const
inlineoverridevirtual

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 399 of file storage_backends.h.

399 {
400 std::lock_guard<std::mutex> lock(mutex_);
401 return snapshots_.size();
402 }

References mutex_, and snapshots_.

◆ store()

common::Result< bool > kcenon::monitoring::memory_storage_backend::store ( const metrics_snapshot & snapshot)
inlineoverridevirtual

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 365 of file storage_backends.h.

365 {
366 std::lock_guard<std::mutex> lock(mutex_);
367
368 if (snapshots_.size() >= config_.max_capacity) {
369 snapshots_.pop_front();
370 }
371
372 snapshots_.push_back(snapshot);
373 return common::ok(true);
374 }

References config_, kcenon::monitoring::storage_config::max_capacity, mutex_, and snapshots_.

Member Data Documentation

◆ config_

storage_config kcenon::monitoring::memory_storage_backend::config_
private

Definition at line 427 of file storage_backends.h.

Referenced by capacity(), get_stats(), and store().

◆ mutex_

std::mutex kcenon::monitoring::memory_storage_backend::mutex_
mutableprivate

Definition at line 429 of file storage_backends.h.

Referenced by clear(), get_stats(), retrieve(), retrieve_range(), size(), and store().

◆ snapshots_

std::deque<metrics_snapshot> kcenon::monitoring::memory_storage_backend::snapshots_
private

Definition at line 428 of file storage_backends.h.

Referenced by clear(), get_stats(), retrieve(), retrieve_range(), size(), and store().


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