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

#include <system_resource_collector.h>

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

Public Member Functions

 system_resource_collector ()
 
 system_resource_collector (const system_metrics_config &config)
 
 ~system_resource_collector () override=default
 
bool initialize (const std::unordered_map< std::string, std::string > &config) override
 
std::vector< metriccollect () override
 
std::string get_name () const override
 
std::vector< std::string > get_metric_types () const override
 
bool is_healthy () const override
 
std::unordered_map< std::string, double > get_statistics () const override
 
system_metrics_config get_config () const
 
void set_config (const system_metrics_config &config)
 
system_resources get_last_resources () const
 
template<typename Duration >
std::vector< load_average_sampleget_load_history (Duration duration) const
 
template<typename Duration >
load_average_statistics get_load_statistics (Duration duration) const
 
std::vector< load_average_sampleget_all_load_history () const
 
load_average_statistics get_all_load_statistics () const
 
void configure_load_history (size_t max_samples)
 
bool is_load_history_enabled () const
 
- Public Member Functions inherited from kcenon::monitoring::metric_collector_plugin
virtual ~metric_collector_plugin ()=default
 

Private Member Functions

metric create_metric (const std::string &name, double value, const std::string &unit="", const std::unordered_map< std::string, std::string > &labels={}) const
 
void add_cpu_metrics (std::vector< metric > &metrics, const system_resources &resources)
 
void add_memory_metrics (std::vector< metric > &metrics, const system_resources &resources)
 
void add_disk_metrics (std::vector< metric > &metrics, const system_resources &resources)
 
void add_network_metrics (std::vector< metric > &metrics, const system_resources &resources)
 
void add_process_metrics (std::vector< metric > &metrics, const system_resources &resources)
 

Private Attributes

std::unique_ptr< system_info_collectorcollector_
 
bool collect_cpu_metrics_ {true}
 
bool collect_memory_metrics_ {true}
 
bool collect_disk_metrics_ {true}
 
bool collect_network_metrics_ {true}
 
bool collect_process_metrics_ {true}
 
std::mutex stats_mutex_
 
std::atomic< size_t > collection_count_ {0}
 
std::atomic< size_t > collection_errors_ {0}
 
std::atomic< int64_t > init_time_ns_ {0}
 
std::shared_ptr< system_resourceslast_resources_
 
std::unique_ptr< load_average_historyload_history_
 
bool enable_load_history_ {true}
 

Detailed Description

System resource collector plugin implementation

Collects system-level metrics with consistent naming convention:

  • system.cpu.* - CPU metrics
  • system.memory.* - Memory metrics
  • system.disk.* - Disk metrics
  • system.network.* - Network metrics
  • system.process.* - Process metrics
  • system.context_switches.* - Context switch metrics
Examples
system_collectors_example.cpp.

Definition at line 287 of file system_resource_collector.h.

Constructor & Destructor Documentation

◆ system_resource_collector() [1/2]

kcenon::monitoring::system_resource_collector::system_resource_collector ( )

◆ system_resource_collector() [2/2]

kcenon::monitoring::system_resource_collector::system_resource_collector ( const system_metrics_config & config)
explicit

Construct with configuration

Parameters
configCollection configuration

◆ ~system_resource_collector()

kcenon::monitoring::system_resource_collector::~system_resource_collector ( )
overridedefault

Member Function Documentation

◆ add_cpu_metrics()

void kcenon::monitoring::system_resource_collector::add_cpu_metrics ( std::vector< metric > & metrics,
const system_resources & resources )
private

◆ add_disk_metrics()

void kcenon::monitoring::system_resource_collector::add_disk_metrics ( std::vector< metric > & metrics,
const system_resources & resources )
private

◆ add_memory_metrics()

void kcenon::monitoring::system_resource_collector::add_memory_metrics ( std::vector< metric > & metrics,
const system_resources & resources )
private

◆ add_network_metrics()

void kcenon::monitoring::system_resource_collector::add_network_metrics ( std::vector< metric > & metrics,
const system_resources & resources )
private

◆ add_process_metrics()

void kcenon::monitoring::system_resource_collector::add_process_metrics ( std::vector< metric > & metrics,
const system_resources & resources )
private

◆ collect()

std::vector< metric > kcenon::monitoring::system_resource_collector::collect ( )
overridevirtual

Collect metrics from the data source

Returns
Collection of metrics

Implements kcenon::monitoring::metric_collector_plugin.

Referenced by main().

Here is the caller graph for this function:

◆ configure_load_history()

void kcenon::monitoring::system_resource_collector::configure_load_history ( size_t max_samples)

Configure load history buffer size

Parameters
max_samplesMaximum number of samples to keep (default: 1000)

◆ create_metric()

metric kcenon::monitoring::system_resource_collector::create_metric ( const std::string & name,
double value,
const std::string & unit = "",
const std::unordered_map< std::string, std::string > & labels = {} ) const
private

◆ get_all_load_history()

std::vector< load_average_sample > kcenon::monitoring::system_resource_collector::get_all_load_history ( ) const

Get all load average history

Returns
Vector of all load average samples

Referenced by main().

Here is the caller graph for this function:

◆ get_all_load_statistics()

load_average_statistics kcenon::monitoring::system_resource_collector::get_all_load_statistics ( ) const

Get load average statistics for all history

Returns
Statistics for all load average samples

Referenced by main().

Here is the caller graph for this function:

◆ get_config()

system_metrics_config kcenon::monitoring::system_resource_collector::get_config ( ) const

Get current configuration

Returns
Current metrics configuration

◆ get_last_resources()

system_resources kcenon::monitoring::system_resource_collector::get_last_resources ( ) const

Get last collected resources

Returns
Last system resources snapshot

Referenced by main().

Here is the caller graph for this function:

◆ get_load_history()

template<typename Duration >
std::vector< load_average_sample > kcenon::monitoring::system_resource_collector::get_load_history ( Duration duration) const
inline

Get load average history for trend analysis

Parameters
durationHow far back to look
Returns
Vector of load average samples within the duration

Definition at line 331 of file system_resource_collector.h.

331 {
332 if (load_history_) {
333 return load_history_->get_samples(duration);
334 }
335 return {};
336 }
std::unique_ptr< load_average_history > load_history_

References load_history_.

◆ get_load_statistics()

template<typename Duration >
load_average_statistics kcenon::monitoring::system_resource_collector::get_load_statistics ( Duration duration) const
inline

Get load average statistics for a duration

Parameters
durationHow far back to look
Returns
Statistics for load averages within the duration

Definition at line 344 of file system_resource_collector.h.

344 {
345 if (load_history_) {
346 return load_history_->get_statistics(duration);
347 }
348 return {};
349 }

References load_history_.

◆ get_metric_types()

std::vector< std::string > kcenon::monitoring::system_resource_collector::get_metric_types ( ) const
overridevirtual

Get supported metric types

Returns
Vector of supported metric type names

Implements kcenon::monitoring::metric_collector_plugin.

◆ get_name()

std::string kcenon::monitoring::system_resource_collector::get_name ( ) const
inlineoverridevirtual

Get the name of this plugin

Returns
Plugin name

Implements kcenon::monitoring::metric_collector_plugin.

Definition at line 302 of file system_resource_collector.h.

302{ return "system_resource_collector"; }

Referenced by main().

Here is the caller graph for this function:

◆ get_statistics()

std::unordered_map< std::string, double > kcenon::monitoring::system_resource_collector::get_statistics ( ) const
overridevirtual

Get plugin-specific statistics

Returns
Map of statistic name to value

Implements kcenon::monitoring::metric_collector_plugin.

Referenced by main().

Here is the caller graph for this function:

◆ initialize()

bool kcenon::monitoring::system_resource_collector::initialize ( const std::unordered_map< std::string, std::string > & config)
overridevirtual

Initialize the plugin with configuration

Parameters
configPlugin-specific configuration
Returns
true if initialization successful

Implements kcenon::monitoring::metric_collector_plugin.

Referenced by main().

Here is the caller graph for this function:

◆ is_healthy()

bool kcenon::monitoring::system_resource_collector::is_healthy ( ) const
overridevirtual

Check if the plugin is healthy

Returns
true if plugin is operational

Implements kcenon::monitoring::metric_collector_plugin.

Referenced by main().

Here is the caller graph for this function:

◆ is_load_history_enabled()

bool kcenon::monitoring::system_resource_collector::is_load_history_enabled ( ) const

Check if load history tracking is enabled

Returns
true if load history tracking is enabled

◆ set_config()

void kcenon::monitoring::system_resource_collector::set_config ( const system_metrics_config & config)

Update configuration

Parameters
configNew configuration to apply

Member Data Documentation

◆ collect_cpu_metrics_

bool kcenon::monitoring::system_resource_collector::collect_cpu_metrics_ {true}
private

Definition at line 380 of file system_resource_collector.h.

380{true};

◆ collect_disk_metrics_

bool kcenon::monitoring::system_resource_collector::collect_disk_metrics_ {true}
private

Definition at line 382 of file system_resource_collector.h.

382{true};

◆ collect_memory_metrics_

bool kcenon::monitoring::system_resource_collector::collect_memory_metrics_ {true}
private

Definition at line 381 of file system_resource_collector.h.

381{true};

◆ collect_network_metrics_

bool kcenon::monitoring::system_resource_collector::collect_network_metrics_ {true}
private

Definition at line 383 of file system_resource_collector.h.

383{true};

◆ collect_process_metrics_

bool kcenon::monitoring::system_resource_collector::collect_process_metrics_ {true}
private

Definition at line 384 of file system_resource_collector.h.

384{true};

◆ collection_count_

std::atomic<size_t> kcenon::monitoring::system_resource_collector::collection_count_ {0}
private

Definition at line 388 of file system_resource_collector.h.

388{0};

◆ collection_errors_

std::atomic<size_t> kcenon::monitoring::system_resource_collector::collection_errors_ {0}
private

Definition at line 389 of file system_resource_collector.h.

389{0};

◆ collector_

std::unique_ptr<system_info_collector> kcenon::monitoring::system_resource_collector::collector_
private

Definition at line 377 of file system_resource_collector.h.

◆ enable_load_history_

bool kcenon::monitoring::system_resource_collector::enable_load_history_ {true}
private

Definition at line 395 of file system_resource_collector.h.

395{true};

◆ init_time_ns_

std::atomic<int64_t> kcenon::monitoring::system_resource_collector::init_time_ns_ {0}
private

Definition at line 390 of file system_resource_collector.h.

390{0}; // Store as nanoseconds for atomic access

◆ last_resources_

std::shared_ptr<system_resources> kcenon::monitoring::system_resource_collector::last_resources_
private

Definition at line 391 of file system_resource_collector.h.

◆ load_history_

std::unique_ptr<load_average_history> kcenon::monitoring::system_resource_collector::load_history_
private

Definition at line 394 of file system_resource_collector.h.

Referenced by get_load_history(), and get_load_statistics().

◆ stats_mutex_

std::mutex kcenon::monitoring::system_resource_collector::stats_mutex_
mutableprivate

Definition at line 387 of file system_resource_collector.h.


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