Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
mock_monitoring Class Reference

Mock monitoring implementation for demonstration. More...

#include <mock_monitoring.h>

Inheritance diagram for mock_monitoring:
Inheritance graph
Collaboration diagram for mock_monitoring:
Collaboration graph

Classes

struct  monitoring_stats
 

Public Member Functions

 mock_monitoring ()
 
 ~mock_monitoring ()
 
kcenon::common::VoidResult record_metric (const std::string &name, double value) override
 
kcenon::common::VoidResult record_metric (const std::string &name, double value, const std::unordered_map< std::string, std::string > &tags) override
 
kcenon::common::Result< kcenon::common::interfaces::metrics_snapshot > get_metrics () override
 
kcenon::common::Result< kcenon::common::interfaces::health_check_result > check_health () override
 
kcenon::common::VoidResult reset () override
 
bool is_active () const
 
void start ()
 
void stop ()
 
monitoring_stats get_stats () const
 

Private Member Functions

void collect_loop ()
 

Private Attributes

kcenon::common::interfaces::metrics_snapshot current_snapshot_
 
std::deque< kcenon::common::interfaces::metrics_snapshot > history_
 
std::mutex mutex_
 
std::atomic< bool > active_
 
std::thread collection_thread_
 
std::atomic< std::uint64_t > total_collections_
 
const size_t max_history_
 

Detailed Description

Mock monitoring implementation for demonstration.

In a real application, this would be replaced with: #include <monitoring_system/monitoring.h> using monitoring_module::monitoring;

Note
Issue #312: Updated to implement common::interfaces::IMonitor

Definition at line 23 of file mock_monitoring.h.

Constructor & Destructor Documentation

◆ mock_monitoring()

mock_monitoring::mock_monitoring ( )
inline

Definition at line 25 of file mock_monitoring.h.

26 : active_(false)
28 , max_history_(100) {
29 }
const size_t max_history_
std::atomic< std::uint64_t > total_collections_
std::atomic< bool > active_

◆ ~mock_monitoring()

mock_monitoring::~mock_monitoring ( )
inline

Definition at line 31 of file mock_monitoring.h.

31 {
32 stop();
33 }

References stop().

Here is the call graph for this function:

Member Function Documentation

◆ check_health()

kcenon::common::Result< kcenon::common::interfaces::health_check_result > mock_monitoring::check_health ( )
inlineoverride

Definition at line 57 of file mock_monitoring.h.

57 {
58 kcenon::common::interfaces::health_check_result result;
59 result.status = active_.load()
60 ? kcenon::common::interfaces::health_status::healthy
61 : kcenon::common::interfaces::health_status::unknown;
62 result.message = active_.load() ? "Monitoring active" : "Monitoring inactive";
63 return kcenon::common::ok(result);
64 }

References active_.

◆ collect_loop()

void mock_monitoring::collect_loop ( )
inlineprivate

Definition at line 103 of file mock_monitoring.h.

103 {
104 while (active_.load()) {
105 std::this_thread::sleep_for(std::chrono::milliseconds(500));
106
107 if (active_.load()) {
108 std::lock_guard<std::mutex> lock(mutex_);
109
110 // Store snapshot in history
111 history_.push_back(current_snapshot_);
112 if (history_.size() > max_history_) {
113 history_.pop_front();
114 }
115
116 total_collections_.fetch_add(1);
117 }
118 }
119 }
std::deque< kcenon::common::interfaces::metrics_snapshot > history_
kcenon::common::interfaces::metrics_snapshot current_snapshot_

References active_, current_snapshot_, history_, max_history_, mutex_, and total_collections_.

Referenced by start().

Here is the caller graph for this function:

◆ get_metrics()

kcenon::common::Result< kcenon::common::interfaces::metrics_snapshot > mock_monitoring::get_metrics ( )
inlineoverride

Definition at line 52 of file mock_monitoring.h.

52 {
53 std::lock_guard<std::mutex> lock(mutex_);
54 return kcenon::common::ok(current_snapshot_);
55 }

References current_snapshot_, and mutex_.

◆ get_stats()

monitoring_stats mock_monitoring::get_stats ( ) const
inline

Definition at line 98 of file mock_monitoring.h.

98 {
99 return {total_collections_.load()};
100 }

References total_collections_.

◆ is_active()

bool mock_monitoring::is_active ( ) const
inline

Definition at line 74 of file mock_monitoring.h.

74 {
75 return active_.load();
76 }

References active_.

◆ record_metric() [1/2]

kcenon::common::VoidResult mock_monitoring::record_metric ( const std::string & name,
double value )
inlineoverride

Definition at line 35 of file mock_monitoring.h.

35 {
36 std::lock_guard<std::mutex> lock(mutex_);
37 current_snapshot_.add_metric(name, value);
38 return kcenon::common::ok();
39 }

References current_snapshot_, and mutex_.

◆ record_metric() [2/2]

kcenon::common::VoidResult mock_monitoring::record_metric ( const std::string & name,
double value,
const std::unordered_map< std::string, std::string > & tags )
inlineoverride

Definition at line 41 of file mock_monitoring.h.

44 {
45 std::lock_guard<std::mutex> lock(mutex_);
46 kcenon::common::interfaces::metric_value mv(name, value);
47 mv.tags = tags;
48 current_snapshot_.metrics.push_back(mv);
49 return kcenon::common::ok();
50 }

References current_snapshot_, and mutex_.

◆ reset()

kcenon::common::VoidResult mock_monitoring::reset ( )
inlineoverride

Definition at line 66 of file mock_monitoring.h.

66 {
67 std::lock_guard<std::mutex> lock(mutex_);
69 history_.clear();
70 total_collections_.store(0);
71 return kcenon::common::ok();
72 }

References current_snapshot_, history_, mutex_, and total_collections_.

◆ start()

void mock_monitoring::start ( )
inline

Definition at line 78 of file mock_monitoring.h.

78 {
79 if (!active_.exchange(true)) {
80 std::cout << "[MockMonitoring] Started" << std::endl;
82 }
83 }
std::thread collection_thread_

References active_, collect_loop(), and collection_thread_.

Here is the call graph for this function:

◆ stop()

void mock_monitoring::stop ( )
inline

Definition at line 85 of file mock_monitoring.h.

85 {
86 if (active_.exchange(false)) {
87 if (collection_thread_.joinable()) {
88 collection_thread_.join();
89 }
90 std::cout << "[MockMonitoring] Stopped" << std::endl;
91 }
92 }

References active_, and collection_thread_.

Referenced by ~mock_monitoring().

Here is the caller graph for this function:

Member Data Documentation

◆ active_

std::atomic<bool> mock_monitoring::active_
private

Definition at line 126 of file mock_monitoring.h.

Referenced by check_health(), collect_loop(), is_active(), start(), and stop().

◆ collection_thread_

std::thread mock_monitoring::collection_thread_
private

Definition at line 127 of file mock_monitoring.h.

Referenced by start(), and stop().

◆ current_snapshot_

kcenon::common::interfaces::metrics_snapshot mock_monitoring::current_snapshot_
private

Definition at line 122 of file mock_monitoring.h.

Referenced by collect_loop(), get_metrics(), record_metric(), record_metric(), and reset().

◆ history_

std::deque<kcenon::common::interfaces::metrics_snapshot> mock_monitoring::history_
private

Definition at line 123 of file mock_monitoring.h.

Referenced by collect_loop(), and reset().

◆ max_history_

const size_t mock_monitoring::max_history_
private

Definition at line 129 of file mock_monitoring.h.

Referenced by collect_loop().

◆ mutex_

std::mutex mock_monitoring::mutex_
mutableprivate

Definition at line 124 of file mock_monitoring.h.

Referenced by collect_loop(), get_metrics(), record_metric(), record_metric(), and reset().

◆ total_collections_

std::atomic<std::uint64_t> mock_monitoring::total_collections_
private

Definition at line 128 of file mock_monitoring.h.

Referenced by collect_loop(), get_stats(), and reset().


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