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

Utility class to aggregate metrics from multiple monitorable components. More...

#include <monitorable_interface.h>

Collaboration diagram for kcenon::monitoring::monitoring_aggregator:
Collaboration graph

Public Member Functions

 monitoring_aggregator (const std::string &id="aggregator")
 Constructor.
 
void add_component (std::shared_ptr< monitorable_interface > component)
 Add a component to monitor.
 
bool remove_component (const std::string &id)
 Remove a component by ID.
 
common::Result< monitoring_datacollect_all () const
 Collect data from all components.
 
std::shared_ptr< monitorable_interfaceget_component (const std::string &id) const
 Get a specific component by ID.
 
std::vector< std::string > get_component_ids () const
 Get all component IDs.
 
void clear ()
 Clear all components.
 
std::size_t size () const
 Get the number of registered components.
 

Private Attributes

std::vector< std::shared_ptr< monitorable_interface > > components_
 
std::string aggregator_id_
 

Detailed Description

Utility class to aggregate metrics from multiple monitorable components.

Collects and merges monitoring data from multiple components into a single aggregated view. Useful for creating dashboards or exporting combined metrics from a subsystem.

Thread Safety:
This class is NOT thread-safe. External synchronization is required when modifying the component list from multiple threads.

Definition at line 453 of file monitorable_interface.h.

Constructor & Destructor Documentation

◆ monitoring_aggregator()

kcenon::monitoring::monitoring_aggregator::monitoring_aggregator ( const std::string & id = "aggregator")
inlineexplicit

Member Function Documentation

◆ add_component()

void kcenon::monitoring::monitoring_aggregator::add_component ( std::shared_ptr< monitorable_interface > component)
inline

Add a component to monitor.

Parameters
componentComponent to add
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/monitorable_interface.h.

Definition at line 470 of file monitorable_interface.h.

470 {
471 if (component) {
472 components_.push_back(component);
473 }
474 }
std::vector< std::shared_ptr< monitorable_interface > > components_

References components_.

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

Here is the caller graph for this function:

◆ clear()

void kcenon::monitoring::monitoring_aggregator::clear ( )
inline

Clear all components.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/monitorable_interface.h.

Definition at line 559 of file monitorable_interface.h.

559 {
560 components_.clear();
561 }

References components_.

Referenced by TEST_F().

Here is the caller graph for this function:

◆ collect_all()

common::Result< monitoring_data > kcenon::monitoring::monitoring_aggregator::collect_all ( ) const
inline

Collect data from all components.

Returns
Aggregated monitoring data
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/monitorable_interface.h.

Definition at line 498 of file monitorable_interface.h.

498 {
499 monitoring_data aggregated(aggregator_id_);
500
501 for (const auto& component : components_) {
502 if (!component->is_monitoring_enabled()) {
503 continue;
504 }
505
506 auto result = component->get_monitoring_data();
507 if (result.is_ok()) {
508 aggregated.merge(result.value(), component->get_monitoring_id());
509 } else {
510 // Log error but continue with other components
511 aggregated.add_tag(
512 component->get_monitoring_id() + ".error",
513 result.error().message
514 );
515 }
516 }
517
518 // Add aggregator metadata
519 aggregated.add_metric("aggregator.component_count",
520 static_cast<double>(components_.size()));
521 aggregated.add_metric("aggregator.total_metrics",
522 static_cast<double>(aggregated.metric_count()));
523
524 return common::ok(std::move(aggregated));
525 }

References kcenon::monitoring::monitoring_data::add_metric(), kcenon::monitoring::monitoring_data::add_tag(), aggregator_id_, components_, kcenon::monitoring::monitoring_data::merge(), and kcenon::monitoring::monitoring_data::metric_count().

Referenced by TEST_F(), and TEST_F().

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

◆ get_component()

std::shared_ptr< monitorable_interface > kcenon::monitoring::monitoring_aggregator::get_component ( const std::string & id) const
inline

Get a specific component by ID.

Parameters
idComponent ID
Returns
Shared pointer to component or nullptr
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/monitorable_interface.h.

Definition at line 532 of file monitorable_interface.h.

532 {
533 auto it = std::find_if(components_.begin(), components_.end(),
534 [&id](const auto& comp) {
535 return comp->get_monitoring_id() == id;
536 });
537
538 return (it != components_.end()) ? *it : nullptr;
539 }

References components_.

Referenced by TEST_F().

Here is the caller graph for this function:

◆ get_component_ids()

std::vector< std::string > kcenon::monitoring::monitoring_aggregator::get_component_ids ( ) const
inline

Get all component IDs.

Returns
Vector of component identifiers
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/monitorable_interface.h.

Definition at line 545 of file monitorable_interface.h.

545 {
546 std::vector<std::string> ids;
547 ids.reserve(components_.size());
548
549 for (const auto& component : components_) {
550 ids.push_back(component->get_monitoring_id());
551 }
552
553 return ids;
554 }

References components_.

Referenced by TEST_F(), and TEST_F().

Here is the caller graph for this function:

◆ remove_component()

bool kcenon::monitoring::monitoring_aggregator::remove_component ( const std::string & id)
inline

Remove a component by ID.

Parameters
idComponent ID to remove
Returns
true if component was found and removed
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/monitorable_interface.h.

Definition at line 481 of file monitorable_interface.h.

481 {
482 auto it = std::remove_if(components_.begin(), components_.end(),
483 [&id](const auto& comp) {
484 return comp->get_monitoring_id() == id;
485 });
486
487 if (it != components_.end()) {
488 components_.erase(it, components_.end());
489 return true;
490 }
491 return false;
492 }

References components_.

Referenced by TEST_F().

Here is the caller graph for this function:

◆ size()

std::size_t kcenon::monitoring::monitoring_aggregator::size ( ) const
inline

Get the number of registered components.

Returns
Component count
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/monitorable_interface.h.

Definition at line 567 of file monitorable_interface.h.

567 {
568 return components_.size();
569 }

References components_.

Referenced by TEST_F(), and TEST_F().

Here is the caller graph for this function:

Member Data Documentation

◆ aggregator_id_

std::string kcenon::monitoring::monitoring_aggregator::aggregator_id_
private

◆ components_


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