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

Performance monitor combining profiling and system monitoring. More...

#include <performance_monitor.h>

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

Classes

struct  metric_data
 
struct  thresholds
 

Public Member Functions

 performance_monitor (const std::string &name="performance_monitor")
 
std::string get_name () const override
 Get the name of this performance monitor.
 
bool is_enabled () const override
 Check if this performance monitor is enabled.
 
common::VoidResult set_enabled (bool enable) override
 Enable or disable the collector.
 
common::VoidResult initialize () override
 Initialize the collector.
 
common::VoidResult cleanup () override
 Cleanup collector resources.
 
common::Result< metrics_snapshotcollect () override
 Collect metrics.
 
scoped_timer time_operation (const std::string &operation_name)
 Create a scoped timer for an operation.
 
performance_profilerget_profiler ()
 Get performance profiler.
 
const performance_profilerget_profiler () const
 Get performance profiler (const)
 
system_monitorget_system_monitor ()
 Get system monitor.
 
const system_monitorget_system_monitor () const
 Get system monitor (const)
 
void set_cpu_threshold (double threshold)
 Set performance thresholds.
 
void set_memory_threshold (double threshold)
 
void set_latency_threshold (std::chrono::milliseconds threshold)
 
thresholds get_thresholds () const
 Get current threshold values.
 
common::Result< bool > check_thresholds () const
 Check if any thresholds are exceeded.
 
void reset ()
 Reset all performance profiler samples and system metrics.
 
common::VoidResult record_counter (const std::string &name, double value, const tag_map &tags={})
 
common::VoidResult record_gauge (const std::string &name, double value, const tag_map &tags={})
 
common::VoidResult record_histogram (const std::string &name, double value, const tag_map &tags={})
 
std::vector< tagged_metricget_all_tagged_metrics () const
 Get all recorded tagged metrics.
 
void clear_all_metrics ()
 Clear all recorded tagged metrics.
 
- Public Member Functions inherited from kcenon::monitoring::metrics_collector
virtual ~metrics_collector ()=default
 

Private Member Functions

common::VoidResult record_metric_internal (const std::string &name, double value, recorded_metric_type type, const tag_map &tags)
 Internal method to record a metric with type and tags.
 

Static Private Member Functions

static std::string make_metric_key (const std::string &name, const tag_map &tags)
 Generate a unique key from metric name and tags.
 

Private Attributes

performance_profiler profiler_
 
system_monitor system_monitor_
 
std::string name_
 
bool enabled_ {true}
 
struct kcenon::monitoring::performance_monitor::thresholds thresholds_
 
std::mutex thresholds_mutex_
 
std::unordered_map< std::string, std::unique_ptr< metric_data > > tagged_metrics_
 
std::shared_mutex metrics_mutex_
 

Detailed Description

Performance monitor combining profiling and system monitoring.

Implements kcenon::monitoring::metrics_collector for internal monitoring. For interoperability with common::interfaces::IMonitor, use performance_monitor_adapter.

Thread Safety:
Thread-safe. All public methods can be called concurrently.
  • profiler_ is thread-safe (uses internal synchronization)
  • system_monitor_ is thread-safe (uses internal synchronization)
  • thresholds_ protected by thresholds_mutex_
See also
performance_monitor_adapter For bridging to common::interfaces::IMonitor
Examples
basic_monitoring_example.cpp, and production_monitoring_example.cpp.

Definition at line 354 of file performance_monitor.h.

Constructor & Destructor Documentation

◆ performance_monitor()

kcenon::monitoring::performance_monitor::performance_monitor ( const std::string & name = "performance_monitor")
inlineexplicit

Member Function Documentation

◆ check_thresholds()

common::Result< bool > kcenon::monitoring::performance_monitor::check_thresholds ( ) const

◆ cleanup()

common::VoidResult kcenon::monitoring::performance_monitor::cleanup ( )
inlineoverridevirtual

Cleanup collector resources.

Returns
Result indicating success or cleanup error

Implements kcenon::monitoring::metrics_collector.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/core/performance_monitor.h, and basic_monitoring_example.cpp.

Definition at line 413 of file performance_monitor.h.

413 {
414 auto result = system_monitor_.stop_monitoring();
415 if (result.is_err()) {
416 return common::VoidResult::err(result.error());
417 }
418 return common::ok();
419 }
common::Result< bool > stop_monitoring()
Stop monitoring.

References kcenon::monitoring::system_monitor::stop_monitoring().

Referenced by main(), and PerformanceMonitoringTest::TearDown().

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

◆ clear_all_metrics()

void kcenon::monitoring::performance_monitor::clear_all_metrics ( )

Clear all recorded tagged metrics.

Thread Safety:
Thread-safe, uses shared_mutex for synchronization
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/core/performance_monitor.h.

◆ collect()

common::Result< metrics_snapshot > kcenon::monitoring::performance_monitor::collect ( )
overridevirtual

Collect metrics.

Returns
Result containing collected metrics or error

Implements kcenon::monitoring::metrics_collector.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/core/performance_monitor.h, and basic_monitoring_example.cpp.

Referenced by main().

Here is the caller graph for this function:

◆ get_all_tagged_metrics()

std::vector< tagged_metric > kcenon::monitoring::performance_monitor::get_all_tagged_metrics ( ) const

Get all recorded tagged metrics.

Returns
Vector of tagged_metric containing all recorded metrics with their tags
Thread Safety:
Thread-safe, uses shared_mutex for synchronization
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/core/performance_monitor.h.

◆ get_name()

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

Get the name of this performance monitor.

Returns
The monitor name string

Implements kcenon::monitoring::metrics_collector.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/core/performance_monitor.h.

Definition at line 391 of file performance_monitor.h.

391{ return name_; }

References name_.

◆ get_profiler() [1/2]

performance_profiler & kcenon::monitoring::performance_monitor::get_profiler ( )
inline

Get performance profiler.

Returns
Reference to the internal performance profiler
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/core/performance_monitor.h.

Definition at line 434 of file performance_monitor.h.

434{ return profiler_; }

◆ get_profiler() [2/2]

const performance_profiler & kcenon::monitoring::performance_monitor::get_profiler ( ) const
inline

Get performance profiler (const)

Returns
Const reference to the internal performance profiler

Definition at line 440 of file performance_monitor.h.

440{ return profiler_; }

◆ get_system_monitor() [1/2]

system_monitor & kcenon::monitoring::performance_monitor::get_system_monitor ( )
inline

Get system monitor.

Returns
Reference to the internal system monitor
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/core/performance_monitor.h, and basic_monitoring_example.cpp.

Definition at line 446 of file performance_monitor.h.

446{ return system_monitor_; }

Referenced by main().

Here is the caller graph for this function:

◆ get_system_monitor() [2/2]

const system_monitor & kcenon::monitoring::performance_monitor::get_system_monitor ( ) const
inline

Get system monitor (const)

Returns
Const reference to the internal system monitor

Definition at line 452 of file performance_monitor.h.

452{ return system_monitor_; }

◆ get_thresholds()

thresholds kcenon::monitoring::performance_monitor::get_thresholds ( ) const
inline

Get current threshold values.

Thread Safety:
Thread-safe. Uses mutex for synchronization.
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/core/performance_monitor.h.

Definition at line 477 of file performance_monitor.h.

477 {
478 std::lock_guard<std::mutex> lock(thresholds_mutex_);
479 return thresholds_;
480 }
struct kcenon::monitoring::performance_monitor::thresholds thresholds_

◆ initialize()

common::VoidResult kcenon::monitoring::performance_monitor::initialize ( )
inlineoverridevirtual

Initialize the collector.

Returns
Result indicating success or initialization error

Implements kcenon::monitoring::metrics_collector.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/core/performance_monitor.h, and basic_monitoring_example.cpp.

Definition at line 405 of file performance_monitor.h.

405 {
406 auto result = system_monitor_.start_monitoring();
407 if (result.is_err()) {
408 return common::VoidResult::err(result.error());
409 }
410 return common::ok();
411 }
common::Result< bool > start_monitoring(std::chrono::milliseconds interval=std::chrono::milliseconds(1000))
Start monitoring system resources.

References kcenon::monitoring::system_monitor::start_monitoring().

Referenced by main().

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

◆ is_enabled()

bool kcenon::monitoring::performance_monitor::is_enabled ( ) const
inlineoverridevirtual

Check if this performance monitor is enabled.

Returns
True if the monitor is currently enabled

Implements kcenon::monitoring::metrics_collector.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/core/performance_monitor.h.

Definition at line 397 of file performance_monitor.h.

◆ make_metric_key()

static std::string kcenon::monitoring::performance_monitor::make_metric_key ( const std::string & name,
const tag_map & tags )
staticprivate

◆ record_counter()

common::VoidResult kcenon::monitoring::performance_monitor::record_counter ( const std::string & name,
double value,
const tag_map & tags = {} )

◆ record_gauge()

common::VoidResult kcenon::monitoring::performance_monitor::record_gauge ( const std::string & name,
double value,
const tag_map & tags = {} )

◆ record_histogram()

common::VoidResult kcenon::monitoring::performance_monitor::record_histogram ( const std::string & name,
double value,
const tag_map & tags = {} )

◆ record_metric_internal()

common::VoidResult kcenon::monitoring::performance_monitor::record_metric_internal ( const std::string & name,
double value,
recorded_metric_type type,
const tag_map & tags )
private

◆ reset()

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

Reset all performance profiler samples and system metrics.

Note
For IMonitor interface compatibility, use performance_monitor_adapter
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/core/performance_monitor.h.

Definition at line 493 of file performance_monitor.h.

493 {
496 }
void clear_all_metrics()
Clear all recorded tagged metrics.
void clear_all_samples()
Clear all samples.

References kcenon::monitoring::performance_profiler::clear_all_samples().

Here is the call graph for this function:

◆ set_cpu_threshold()

void kcenon::monitoring::performance_monitor::set_cpu_threshold ( double threshold)
inline

Set performance thresholds.

Thread Safety:
Thread-safe. Uses mutex for synchronization.
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/core/performance_monitor.h.

Definition at line 458 of file performance_monitor.h.

458 {
459 std::lock_guard<std::mutex> lock(thresholds_mutex_);
460 thresholds_.cpu_threshold = threshold;
461 }

◆ set_enabled()

common::VoidResult kcenon::monitoring::performance_monitor::set_enabled ( bool enable)
inlineoverridevirtual

Enable or disable the collector.

Parameters
enabletrue to enable, false to disable
Returns
Result indicating success or error

Implements kcenon::monitoring::metrics_collector.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/core/performance_monitor.h.

Definition at line 399 of file performance_monitor.h.

399 {
400 enabled_ = enable;
401 profiler_.set_enabled(enable);
402 return common::ok();
403 }
void set_enabled(bool enabled)
Enable or disable profiling.

References kcenon::monitoring::performance_profiler::set_enabled().

Referenced by PerformanceMonitoringTest::SetUp().

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

◆ set_latency_threshold()

void kcenon::monitoring::performance_monitor::set_latency_threshold ( std::chrono::milliseconds threshold)
inline

◆ set_memory_threshold()

void kcenon::monitoring::performance_monitor::set_memory_threshold ( double threshold)
inline

◆ time_operation()

scoped_timer kcenon::monitoring::performance_monitor::time_operation ( const std::string & operation_name)
inline

Create a scoped timer for an operation.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/core/performance_monitor.h, and basic_monitoring_example.cpp.

Definition at line 426 of file performance_monitor.h.

426 {
427 return scoped_timer(&profiler_, operation_name);
428 }

Referenced by main().

Here is the caller graph for this function:

Member Data Documentation

◆ enabled_

bool kcenon::monitoring::performance_monitor::enabled_ {true}
private

◆ metrics_mutex_

std::shared_mutex kcenon::monitoring::performance_monitor::metrics_mutex_
mutableprivate

◆ name_

std::string kcenon::monitoring::performance_monitor::name_
private

◆ profiler_

performance_profiler kcenon::monitoring::performance_monitor::profiler_
private

◆ system_monitor_

system_monitor kcenon::monitoring::performance_monitor::system_monitor_
private

◆ tagged_metrics_

std::unordered_map<std::string, std::unique_ptr<metric_data> > kcenon::monitoring::performance_monitor::tagged_metrics_
private

◆ thresholds_

◆ thresholds_mutex_

std::mutex kcenon::monitoring::performance_monitor::thresholds_mutex_
mutableprivate

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