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

Cloud storage backend (stub implementation) More...

#include <storage_backends.h>

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

Public Member Functions

 cloud_storage_backend ()
 
 cloud_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

Cloud storage backend (stub implementation)

Definition at line 281 of file storage_backends.h.

Constructor & Destructor Documentation

◆ cloud_storage_backend() [1/2]

kcenon::monitoring::cloud_storage_backend::cloud_storage_backend ( )
inline

Definition at line 283 of file storage_backends.h.

◆ cloud_storage_backend() [2/2]

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

Definition at line 285 of file storage_backends.h.

286 : config_(config) {}

Member Function Documentation

◆ capacity()

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

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 327 of file storage_backends.h.

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

Referenced by TEST_F().

Here is the caller graph for this function:

◆ clear()

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

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 335 of file storage_backends.h.

335 {
336 std::lock_guard<std::mutex> lock(mutex_);
337 snapshots_.clear();
338 return common::ok(true);
339 }
std::deque< metrics_snapshot > snapshots_

References mutex_, and snapshots_.

Referenced by TEST_F().

Here is the caller graph for this function:

◆ flush()

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

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 331 of file storage_backends.h.

331 {
332 return common::ok(true);
333 }

Referenced by TEST_F().

Here is the caller graph for this function:

◆ get_stats()

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

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 341 of file storage_backends.h.

341 {
342 std::lock_guard<std::mutex> lock(mutex_);
343 return {
344 {"stored_count", snapshots_.size()},
345 {"capacity", config_.max_capacity}
346 };
347 }

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

◆ retrieve()

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

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 299 of file storage_backends.h.

299 {
300 std::lock_guard<std::mutex> lock(mutex_);
301
302 if (index >= snapshots_.size()) {
303 return common::Result<metrics_snapshot>::err(error_info(monitoring_error_code::not_found, "Snapshot index out of range").to_common_error());
304 }
305
306 return common::ok(snapshots_[index]);
307 }

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

Referenced by TEST_F().

Here is the caller graph for this function:

◆ retrieve_range()

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

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 309 of file storage_backends.h.

309 {
310 std::lock_guard<std::mutex> lock(mutex_);
311
312 std::vector<metrics_snapshot> result;
313 size_t end = std::min(start + count, snapshots_.size());
314
315 for (size_t i = start; i < end; ++i) {
316 result.push_back(snapshots_[i]);
317 }
318
319 return common::ok(std::move(result));
320 }

References mutex_, and snapshots_.

Referenced by TEST_F().

Here is the caller graph for this function:

◆ size()

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

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 322 of file storage_backends.h.

322 {
323 std::lock_guard<std::mutex> lock(mutex_);
324 return snapshots_.size();
325 }

References mutex_, and snapshots_.

Referenced by TEST_F().

Here is the caller graph for this function:

◆ store()

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

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 288 of file storage_backends.h.

288 {
289 std::lock_guard<std::mutex> lock(mutex_);
290
291 if (snapshots_.size() >= config_.max_capacity) {
292 snapshots_.pop_front();
293 }
294
295 snapshots_.push_back(snapshot);
296 return common::ok(true);
297 }

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

Referenced by TEST_F(), and TEST_F().

Here is the caller graph for this function:

Member Data Documentation

◆ config_

storage_config kcenon::monitoring::cloud_storage_backend::config_
private

Definition at line 350 of file storage_backends.h.

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

◆ mutex_

std::mutex kcenon::monitoring::cloud_storage_backend::mutex_
mutableprivate

Definition at line 352 of file storage_backends.h.

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

◆ snapshots_

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

Definition at line 351 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: