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

Database storage backend (stub implementation) More...

#include <storage_backends.h>

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

Public Member Functions

 database_storage_backend ()
 
 database_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_
 
bool connected_ {false}
 

Detailed Description

Database storage backend (stub implementation)

Definition at line 202 of file storage_backends.h.

Constructor & Destructor Documentation

◆ database_storage_backend() [1/2]

kcenon::monitoring::database_storage_backend::database_storage_backend ( )
inline

Definition at line 204 of file storage_backends.h.

◆ database_storage_backend() [2/2]

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

Definition at line 206 of file storage_backends.h.

Member Function Documentation

◆ capacity()

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

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 248 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::database_storage_backend::clear ( )
inlineoverridevirtual

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 256 of file storage_backends.h.

256 {
257 std::lock_guard<std::mutex> lock(mutex_);
258 snapshots_.clear();
259 return common::ok(true);
260 }
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::database_storage_backend::flush ( )
inlineoverridevirtual

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 252 of file storage_backends.h.

252 {
253 return common::ok(true);
254 }

Referenced by TEST_F().

Here is the caller graph for this function:

◆ get_stats()

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

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 262 of file storage_backends.h.

262 {
263 std::lock_guard<std::mutex> lock(mutex_);
264 return {
265 {"stored_count", snapshots_.size()},
266 {"capacity", config_.max_capacity},
267 {"connected", connected_ ? 1UL : 0UL}
268 };
269 }

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

Referenced by TEST_F().

Here is the caller graph for this function:

◆ retrieve()

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

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 220 of file storage_backends.h.

220 {
221 std::lock_guard<std::mutex> lock(mutex_);
222
223 if (index >= snapshots_.size()) {
224 return common::Result<metrics_snapshot>::err(error_info(monitoring_error_code::not_found, "Snapshot index out of range").to_common_error());
225 }
226
227 return common::ok(snapshots_[index]);
228 }

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::database_storage_backend::retrieve_range ( size_t start,
size_t count )
inlineoverridevirtual

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 230 of file storage_backends.h.

230 {
231 std::lock_guard<std::mutex> lock(mutex_);
232
233 std::vector<metrics_snapshot> result;
234 size_t end = std::min(start + count, snapshots_.size());
235
236 for (size_t i = start; i < end; ++i) {
237 result.push_back(snapshots_[i]);
238 }
239
240 return common::ok(std::move(result));
241 }

References mutex_, and snapshots_.

Referenced by TEST_F().

Here is the caller graph for this function:

◆ size()

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

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 243 of file storage_backends.h.

243 {
244 std::lock_guard<std::mutex> lock(mutex_);
245 return snapshots_.size();
246 }

References mutex_, and snapshots_.

Referenced by TEST_F().

Here is the caller graph for this function:

◆ store()

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

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 209 of file storage_backends.h.

209 {
210 std::lock_guard<std::mutex> lock(mutex_);
211
212 if (snapshots_.size() >= config_.max_capacity) {
213 snapshots_.pop_front();
214 }
215
216 snapshots_.push_back(snapshot);
217 return common::ok(true);
218 }

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::database_storage_backend::config_
private

Definition at line 272 of file storage_backends.h.

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

◆ connected_

bool kcenon::monitoring::database_storage_backend::connected_ {false}
private

Definition at line 275 of file storage_backends.h.

275{false};

Referenced by get_stats().

◆ mutex_

std::mutex kcenon::monitoring::database_storage_backend::mutex_
mutableprivate

Definition at line 274 of file storage_backends.h.

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

◆ snapshots_

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

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