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

File storage backend for metrics snapshots. More...

#include <storage_backends.h>

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

Public Member Functions

 file_storage_backend ()
 
 file_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

File storage backend for metrics snapshots.

Definition at line 123 of file storage_backends.h.

Constructor & Destructor Documentation

◆ file_storage_backend() [1/2]

kcenon::monitoring::file_storage_backend::file_storage_backend ( )
inline

Definition at line 125 of file storage_backends.h.

◆ file_storage_backend() [2/2]

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

Definition at line 127 of file storage_backends.h.

128 : config_(config) {}

Member Function Documentation

◆ capacity()

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

Implements kcenon::monitoring::snapshot_storage_backend.

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

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 179 of file storage_backends.h.

179 {
180 std::lock_guard<std::mutex> lock(mutex_);
181 snapshots_.clear();
182 return common::ok(true);
183 }
std::deque< metrics_snapshot > snapshots_

References mutex_, and snapshots_.

Referenced by TEST_F(), and TEST_F().

Here is the caller graph for this function:

◆ flush()

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

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 174 of file storage_backends.h.

174 {
175 // Stub implementation - actual file I/O would go here
176 return common::ok(true);
177 }

Referenced by TEST_F().

Here is the caller graph for this function:

◆ get_stats()

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

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 185 of file storage_backends.h.

185 {
186 std::lock_guard<std::mutex> lock(mutex_);
187 return {
188 {"total_snapshots", snapshots_.size()},
189 {"capacity", config_.max_capacity}
190 };
191 }

References config_, 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::file_storage_backend::retrieve ( size_t index)
inlineoverridevirtual

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 142 of file storage_backends.h.

142 {
143 std::lock_guard<std::mutex> lock(mutex_);
144
145 if (index >= snapshots_.size()) {
146 return common::Result<metrics_snapshot>::err(error_info(monitoring_error_code::not_found, "Snapshot index out of range").to_common_error());
147 }
148
149 return common::ok(snapshots_[index]);
150 }

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

Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

Here is the caller graph for this function:

◆ retrieve_range()

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

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 152 of file storage_backends.h.

152 {
153 std::lock_guard<std::mutex> lock(mutex_);
154
155 std::vector<metrics_snapshot> result;
156 size_t end = std::min(start + count, snapshots_.size());
157
158 for (size_t i = start; i < end; ++i) {
159 result.push_back(snapshots_[i]);
160 }
161
162 return common::ok(std::move(result));
163 }

References mutex_, and snapshots_.

Referenced by TEST_F(), TEST_F(), and TEST_F().

Here is the caller graph for this function:

◆ size()

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

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 165 of file storage_backends.h.

165 {
166 std::lock_guard<std::mutex> lock(mutex_);
167 return snapshots_.size();
168 }

References mutex_, and snapshots_.

Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

Here is the caller graph for this function:

◆ store()

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

Implements kcenon::monitoring::snapshot_storage_backend.

Definition at line 130 of file storage_backends.h.

130 {
131 std::lock_guard<std::mutex> lock(mutex_);
132
133 // Remove oldest if at capacity
134 if (snapshots_.size() >= config_.max_capacity) {
135 snapshots_.pop_front();
136 }
137
138 snapshots_.push_back(snapshot);
139 return common::ok(true);
140 }

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

Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

Here is the caller graph for this function:

Member Data Documentation

◆ config_

storage_config kcenon::monitoring::file_storage_backend::config_
private

Definition at line 194 of file storage_backends.h.

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

◆ mutex_

std::mutex kcenon::monitoring::file_storage_backend::mutex_
mutableprivate

Definition at line 196 of file storage_backends.h.

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

◆ snapshots_

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

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