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

Central collector for aggregating metrics from thread-local buffers. More...

#include <central_collector.h>

Collaboration diagram for kcenon::monitoring::central_collector:
Collaboration graph

Classes

struct  profile_data
 Internal structure for profile data with LRU tracking. More...
 
struct  stats
 Get statistics about the collector. More...
 

Public Member Functions

 central_collector (size_t max_profiles=DEFAULT_MAX_PROFILES)
 Construct a central collector.
 
void receive_batch (const std::vector< metric_sample > &samples)
 Receive a batch of samples from a thread-local buffer.
 
common::Result< performance_profileget_profile (const std::string &operation_name) const
 Get aggregated profile for an operation.
 
std::unordered_map< std::string, performance_profileget_all_profiles () const
 Get all aggregated profiles.
 
void clear ()
 Clear all collected data.
 
size_t get_operation_count () const
 Get the number of tracked operations.
 
size_t get_total_sample_count () const
 Get total number of samples received.
 
stats get_stats () const
 

Static Public Attributes

static constexpr size_t DEFAULT_MAX_PROFILES = 10000
 

Private Member Functions

void process_sample (const metric_sample &sample)
 Process a single sample into a profile.
 
void evict_lru ()
 Evict least recently used profile.
 

Private Attributes

std::shared_mutex profiles_mutex_
 
std::unordered_map< std::string, std::unique_ptr< profile_data > > profiles_
 
size_t max_profiles_
 
std::atomic< size_t > total_samples_ {0}
 
std::atomic< size_t > batches_received_ {0}
 
std::atomic< size_t > lru_evictions_ {0}
 

Detailed Description

Central collector for aggregating metrics from thread-local buffers.

Receives batches of metric samples from multiple thread-local buffers and aggregates them into performance profiles.

Thread Safety:
Thread-safe. All methods can be called concurrently. Uses std::shared_mutex for read/write synchronization.

Definition at line 35 of file central_collector.h.

Constructor & Destructor Documentation

◆ central_collector()

kcenon::monitoring::central_collector::central_collector ( size_t max_profiles = DEFAULT_MAX_PROFILES)
explicit

Construct a central collector.

Parameters
max_profilesMaximum number of operation profiles to maintain

Member Function Documentation

◆ clear()

void kcenon::monitoring::central_collector::clear ( )

Clear all collected data.

Thread Safety:
Thread-safe. Uses exclusive lock.

◆ evict_lru()

void kcenon::monitoring::central_collector::evict_lru ( )
private

Evict least recently used profile.

Note
Caller must hold profiles_mutex_ (exclusive lock)

◆ get_all_profiles()

std::unordered_map< std::string, performance_profile > kcenon::monitoring::central_collector::get_all_profiles ( ) const

Get all aggregated profiles.

Returns
Map of operation names to performance profiles
Thread Safety:
Thread-safe. Uses shared lock for read access.

◆ get_operation_count()

size_t kcenon::monitoring::central_collector::get_operation_count ( ) const

Get the number of tracked operations.

Returns
Number of operation profiles
Thread Safety:
Thread-safe. Uses shared lock.

◆ get_profile()

common::Result< performance_profile > kcenon::monitoring::central_collector::get_profile ( const std::string & operation_name) const

Get aggregated profile for an operation.

Parameters
operation_nameName of the operation
Returns
common::Result<performance_profile> Profile data or error
Thread Safety:
Thread-safe. Uses shared lock for read access.

◆ get_stats()

stats kcenon::monitoring::central_collector::get_stats ( ) const

◆ get_total_sample_count()

size_t kcenon::monitoring::central_collector::get_total_sample_count ( ) const
inline

Get total number of samples received.

Returns
Total sample count across all operations
Thread Safety:
Thread-safe. Atomic operation.

Definition at line 96 of file central_collector.h.

96 {
97 return total_samples_.load(std::memory_order_relaxed);
98 }

References total_samples_.

◆ process_sample()

void kcenon::monitoring::central_collector::process_sample ( const metric_sample & sample)
private

Process a single sample into a profile.

Parameters
sampleMetric sample to process
Note
Caller must hold profiles_mutex_ (at least shared lock)

◆ receive_batch()

void kcenon::monitoring::central_collector::receive_batch ( const std::vector< metric_sample > & samples)

Receive a batch of samples from a thread-local buffer.

Parameters
samplesVector of metric samples to process
Thread Safety:
Thread-safe. Uses exclusive lock for write access.
Performance:
Batching reduces lock acquisition frequency. O(n) where n = samples.size()

Member Data Documentation

◆ batches_received_

std::atomic<size_t> kcenon::monitoring::central_collector::batches_received_ {0}
private

Definition at line 150 of file central_collector.h.

150{0};

◆ DEFAULT_MAX_PROFILES

size_t kcenon::monitoring::central_collector::DEFAULT_MAX_PROFILES = 10000
staticconstexpr

Definition at line 37 of file central_collector.h.

◆ lru_evictions_

std::atomic<size_t> kcenon::monitoring::central_collector::lru_evictions_ {0}
private

Definition at line 151 of file central_collector.h.

151{0};

◆ max_profiles_

size_t kcenon::monitoring::central_collector::max_profiles_
private

Definition at line 146 of file central_collector.h.

◆ profiles_

std::unordered_map<std::string, std::unique_ptr<profile_data> > kcenon::monitoring::central_collector::profiles_
private

Definition at line 145 of file central_collector.h.

◆ profiles_mutex_

std::shared_mutex kcenon::monitoring::central_collector::profiles_mutex_
mutableprivate

Definition at line 144 of file central_collector.h.

◆ total_samples_

std::atomic<size_t> kcenon::monitoring::central_collector::total_samples_ {0}
private

Definition at line 149 of file central_collector.h.

149{0};

Referenced by get_total_sample_count().


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