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

Full-featured streaming aggregation. More...

#include <stream_aggregator.h>

Collaboration diagram for kcenon::monitoring::stream_aggregator:
Collaboration graph

Public Member Functions

 stream_aggregator ()
 Default constructor.
 
 stream_aggregator (const stream_aggregator_config &config)
 Constructor with configuration.
 
common::VoidResult add_observation (double value)
 Add an observation.
 
streaming_statistics get_statistics () const
 Get full statistics.
 
std::optional< double > get_percentile (double p) const
 Get specific percentile.
 
size_t count () const
 Get observation count.
 
double mean () const
 Get mean.
 
double variance () const
 Get variance.
 
double stddev () const
 Get standard deviation.
 
void reset ()
 Reset the aggregator.
 

Private Attributes

std::shared_mutex mutex_
 
stream_aggregator_config config_
 
online_statistics stats_
 
std::map< double, quantile_estimatorpercentile_estimators_
 
size_t outlier_count_ = 0
 
std::vector< double > outliers_
 

Detailed Description

Full-featured streaming aggregation.

Combines online statistics, quantile estimation, and outlier detection for comprehensive streaming metric aggregation.

Definition at line 523 of file stream_aggregator.h.

Constructor & Destructor Documentation

◆ stream_aggregator() [1/2]

kcenon::monitoring::stream_aggregator::stream_aggregator ( )
inline

Default constructor.

Definition at line 528 of file stream_aggregator.h.

528: stream_aggregator(stream_aggregator_config{}) {}

◆ stream_aggregator() [2/2]

kcenon::monitoring::stream_aggregator::stream_aggregator ( const stream_aggregator_config & config)
inlineexplicit

Constructor with configuration.

Parameters
configThe configuration

Definition at line 534 of file stream_aggregator.h.

535 : config_(config) {
536 // Initialize percentile estimators
537 for (double p : config_.percentiles_to_track) {
538 percentile_estimators_.emplace(p, quantile_estimator(p));
539 }
540 }
std::map< double, quantile_estimator > percentile_estimators_

References config_, and kcenon::monitoring::stream_aggregator_config::percentiles_to_track.

Member Function Documentation

◆ add_observation()

common::VoidResult kcenon::monitoring::stream_aggregator::add_observation ( double value)
inline

Add an observation.

Parameters
valueThe observation value
Returns
Result indicating success or failure

Definition at line 547 of file stream_aggregator.h.

547 {
548 std::unique_lock<std::shared_mutex> lock(mutex_);
549
550 // Check for outlier
552 double z_score = std::abs(value - stats_.mean()) /
553 (stats_.stddev() + 1e-10);
554 if (z_score > config_.outlier_threshold) {
556 outliers_.push_back(value);
557 if (outliers_.size() > 100) {
558 outliers_.erase(outliers_.begin());
559 }
560 }
561 }
562
563 stats_.add_value(value);
564
565 // Update percentile estimators
566 for (auto& [p, estimator] : percentile_estimators_) {
567 estimator.add_observation(value);
568 }
569
570 return common::ok();
571 }
void add_value(double value)
Add a value to the statistics.
double stddev() const
Get running standard deviation.
double mean() const
Get running mean.
size_t count() const
Get sample count.

References kcenon::monitoring::online_statistics::add_value(), config_, kcenon::monitoring::online_statistics::count(), kcenon::monitoring::stream_aggregator_config::enable_outlier_detection, kcenon::monitoring::online_statistics::mean(), mutex_, outlier_count_, kcenon::monitoring::stream_aggregator_config::outlier_threshold, outliers_, percentile_estimators_, stats_, and kcenon::monitoring::online_statistics::stddev().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ count()

size_t kcenon::monitoring::stream_aggregator::count ( ) const
inline

Get observation count.

Definition at line 607 of file stream_aggregator.h.

607 {
608 return stats_.count();
609 }

References kcenon::monitoring::online_statistics::count(), and stats_.

Referenced by TEST_F(), and TEST_F().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_percentile()

std::optional< double > kcenon::monitoring::stream_aggregator::get_percentile ( double p) const
inline

Get specific percentile.

Parameters
pThe percentile (0.0 to 1.0)
Returns
Optional containing the percentile value

Definition at line 595 of file stream_aggregator.h.

595 {
596 std::shared_lock<std::shared_mutex> lock(mutex_);
597 auto it = percentile_estimators_.find(p);
598 if (it != percentile_estimators_.end()) {
599 return it->second.get_quantile();
600 }
601 return std::nullopt;
602 }

References mutex_, and percentile_estimators_.

Referenced by TEST_F().

Here is the caller graph for this function:

◆ get_statistics()

streaming_statistics kcenon::monitoring::stream_aggregator::get_statistics ( ) const
inline

Get full statistics.

Definition at line 576 of file stream_aggregator.h.

576 {
577 std::shared_lock<std::shared_mutex> lock(mutex_);
578 auto stats = stats_.get_statistics();
580 stats.outliers = outliers_;
581
582 // Add percentiles
583 for (const auto& [p, estimator] : percentile_estimators_) {
584 stats.percentiles[p] = estimator.get_quantile();
585 }
586
587 return stats;
588 }
streaming_statistics get_statistics() const
Get full statistics.

References kcenon::monitoring::online_statistics::get_statistics(), mutex_, kcenon::monitoring::streaming_statistics::outlier_count, outlier_count_, outliers_, percentile_estimators_, and stats_.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mean()

double kcenon::monitoring::stream_aggregator::mean ( ) const
inline

Get mean.

Definition at line 614 of file stream_aggregator.h.

614 {
615 return stats_.mean();
616 }

References kcenon::monitoring::online_statistics::mean(), and stats_.

Referenced by TEST_F().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

void kcenon::monitoring::stream_aggregator::reset ( )
inline

Reset the aggregator.

Definition at line 635 of file stream_aggregator.h.

635 {
636 std::unique_lock<std::shared_mutex> lock(mutex_);
637 stats_.reset();
638 outlier_count_ = 0;
639 outliers_.clear();
640 for (auto& [p, estimator] : percentile_estimators_) {
641 estimator.reset();
642 }
643 }

References mutex_, outlier_count_, outliers_, percentile_estimators_, kcenon::monitoring::online_statistics::reset(), and stats_.

Referenced by TEST_F().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stddev()

double kcenon::monitoring::stream_aggregator::stddev ( ) const
inline

Get standard deviation.

Definition at line 628 of file stream_aggregator.h.

628 {
629 return stats_.stddev();
630 }

References stats_, and kcenon::monitoring::online_statistics::stddev().

Here is the call graph for this function:

◆ variance()

double kcenon::monitoring::stream_aggregator::variance ( ) const
inline

Get variance.

Definition at line 621 of file stream_aggregator.h.

621 {
622 return stats_.variance();
623 }
double variance() const
Get running variance (sample variance)

References stats_, and kcenon::monitoring::online_statistics::variance().

Referenced by TEST_F().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ config_

stream_aggregator_config kcenon::monitoring::stream_aggregator::config_
private

Definition at line 647 of file stream_aggregator.h.

Referenced by add_observation(), and stream_aggregator().

◆ mutex_

std::shared_mutex kcenon::monitoring::stream_aggregator::mutex_
mutableprivate

Definition at line 646 of file stream_aggregator.h.

Referenced by add_observation(), get_percentile(), get_statistics(), and reset().

◆ outlier_count_

size_t kcenon::monitoring::stream_aggregator::outlier_count_ = 0
private

Definition at line 650 of file stream_aggregator.h.

Referenced by add_observation(), get_statistics(), and reset().

◆ outliers_

std::vector<double> kcenon::monitoring::stream_aggregator::outliers_
private

Definition at line 651 of file stream_aggregator.h.

Referenced by add_observation(), get_statistics(), and reset().

◆ percentile_estimators_

std::map<double, quantile_estimator> kcenon::monitoring::stream_aggregator::percentile_estimators_
private

Definition at line 649 of file stream_aggregator.h.

Referenced by add_observation(), get_percentile(), get_statistics(), and reset().

◆ stats_

online_statistics kcenon::monitoring::stream_aggregator::stats_
private

Definition at line 648 of file stream_aggregator.h.

Referenced by add_observation(), count(), get_statistics(), mean(), reset(), stddev(), and variance().


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