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

Coordinates multiple resource management components. More...

#include <resource_manager.h>

Collaboration diagram for kcenon::monitoring::resource_manager:
Collaboration graph

Public Member Functions

 resource_manager (const std::string &name)
 
common::Result< bool > add_rate_limiter (const std::string &name, const rate_limit_config &config)
 Add a rate limiter.
 
rate_limiterget_rate_limiter (const std::string &name)
 Get a rate limiter by name.
 
common::Result< bool > add_memory_quota (const std::string &name, const resource_quota &quota)
 Add a memory quota manager.
 
memory_quota_managerget_memory_quota (const std::string &name)
 Get a memory quota manager by name.
 
common::Result< bool > add_cpu_throttler (const std::string &name, const cpu_throttle_config &config)
 Add a CPU throttler.
 
cpu_throttlerget_cpu_throttler (const std::string &name)
 Get a CPU throttler by name.
 
common::Result< bool > is_healthy () const
 Check if all resources are healthy.
 
std::unordered_map< std::string, resource_metricsget_all_metrics () const
 Get metrics for all managed resources.
 

Private Attributes

std::string name_
 
std::unordered_map< std::string, std::unique_ptr< rate_limiter > > rate_limiters_
 
std::unordered_map< std::string, std::unique_ptr< memory_quota_manager > > memory_quotas_
 
std::unordered_map< std::string, std::unique_ptr< cpu_throttler > > cpu_throttlers_
 
std::mutex mutex_
 

Detailed Description

Coordinates multiple resource management components.

Definition at line 459 of file resource_manager.h.

Constructor & Destructor Documentation

◆ resource_manager()

kcenon::monitoring::resource_manager::resource_manager ( const std::string & name)
inlineexplicit

Definition at line 461 of file resource_manager.h.

Member Function Documentation

◆ add_cpu_throttler()

common::Result< bool > kcenon::monitoring::resource_manager::add_cpu_throttler ( const std::string & name,
const cpu_throttle_config & config )
inline

Add a CPU throttler.

Parameters
nameName for the throttler
configCPU throttle configuration
Returns
Success or error if name already exists

Definition at line 528 of file resource_manager.h.

528 {
529 std::lock_guard<std::mutex> lock(mutex_);
530
531 if (cpu_throttlers_.find(name) != cpu_throttlers_.end()) {
532 return common::make_error<bool>(static_cast<int>(monitoring_error_code::already_exists),
533 "CPU throttler '" + name + "' already exists");
534 }
535
536 cpu_throttlers_[name] = std::make_unique<cpu_throttler>(name, config);
537 return common::ok(true);
538 }
std::unordered_map< std::string, std::unique_ptr< cpu_throttler > > cpu_throttlers_

References kcenon::monitoring::already_exists, cpu_throttlers_, and mutex_.

◆ add_memory_quota()

common::Result< bool > kcenon::monitoring::resource_manager::add_memory_quota ( const std::string & name,
const resource_quota & quota )
inline

Add a memory quota manager.

Parameters
nameName for the manager
quotaResource quota configuration
Returns
Success or error if name already exists

Definition at line 499 of file resource_manager.h.

499 {
500 std::lock_guard<std::mutex> lock(mutex_);
501
502 if (memory_quotas_.find(name) != memory_quotas_.end()) {
503 return common::make_error<bool>(static_cast<int>(monitoring_error_code::already_exists),
504 "Memory quota '" + name + "' already exists");
505 }
506
507 memory_quotas_[name] = std::make_unique<memory_quota_manager>(name, quota);
508 return common::ok(true);
509 }
std::unordered_map< std::string, std::unique_ptr< memory_quota_manager > > memory_quotas_

References kcenon::monitoring::already_exists, memory_quotas_, and mutex_.

◆ add_rate_limiter()

common::Result< bool > kcenon::monitoring::resource_manager::add_rate_limiter ( const std::string & name,
const rate_limit_config & config )
inline

Add a rate limiter.

Parameters
nameName for the limiter
configRate limit configuration
Returns
Success or error if name already exists

Definition at line 469 of file resource_manager.h.

469 {
470 std::lock_guard<std::mutex> lock(mutex_);
471
472 if (rate_limiters_.find(name) != rate_limiters_.end()) {
473 return common::make_error<bool>(static_cast<int>(monitoring_error_code::already_exists),
474 "Rate limiter '" + name + "' already exists");
475 }
476
477 rate_limiters_[name] = std::make_unique<token_bucket_limiter>(
478 name, config.rate_per_second, config.burst_capacity, config.strategy);
479 return common::ok(true);
480 }
std::unordered_map< std::string, std::unique_ptr< rate_limiter > > rate_limiters_

References kcenon::monitoring::already_exists, kcenon::monitoring::rate_limit_config::burst_capacity, mutex_, rate_limiters_, kcenon::monitoring::rate_limit_config::rate_per_second, and kcenon::monitoring::rate_limit_config::strategy.

◆ get_all_metrics()

std::unordered_map< std::string, resource_metrics > kcenon::monitoring::resource_manager::get_all_metrics ( ) const
inline

Get metrics for all managed resources.

Returns
Map of resource name to metrics

Definition at line 571 of file resource_manager.h.

571 {
572 std::lock_guard<std::mutex> lock(mutex_);
573 std::unordered_map<std::string, resource_metrics> all_metrics;
574
575 for (const auto& [name, limiter] : rate_limiters_) {
576 all_metrics["rate_" + name] = resource_metrics{};
577 }
578
579 for (const auto& [name, manager] : memory_quotas_) {
580 all_metrics["memory_" + name] = manager->get_metrics();
581 }
582
583 for (const auto& [name, throttler] : cpu_throttlers_) {
584 all_metrics["cpu_" + name] = throttler->get_metrics();
585 }
586
587 return all_metrics;
588 }

References cpu_throttlers_, memory_quotas_, mutex_, and rate_limiters_.

◆ get_cpu_throttler()

cpu_throttler * kcenon::monitoring::resource_manager::get_cpu_throttler ( const std::string & name)
inline

Get a CPU throttler by name.

Parameters
nameName of the throttler
Returns
Pointer to the throttler or nullptr if not found

Definition at line 545 of file resource_manager.h.

545 {
546 std::lock_guard<std::mutex> lock(mutex_);
547 auto it = cpu_throttlers_.find(name);
548 return it != cpu_throttlers_.end() ? it->second.get() : nullptr;
549 }

References cpu_throttlers_, and mutex_.

◆ get_memory_quota()

memory_quota_manager * kcenon::monitoring::resource_manager::get_memory_quota ( const std::string & name)
inline

Get a memory quota manager by name.

Parameters
nameName of the manager
Returns
Pointer to the manager or nullptr if not found

Definition at line 516 of file resource_manager.h.

516 {
517 std::lock_guard<std::mutex> lock(mutex_);
518 auto it = memory_quotas_.find(name);
519 return it != memory_quotas_.end() ? it->second.get() : nullptr;
520 }

References memory_quotas_, and mutex_.

◆ get_rate_limiter()

rate_limiter * kcenon::monitoring::resource_manager::get_rate_limiter ( const std::string & name)
inline

Get a rate limiter by name.

Parameters
nameName of the limiter
Returns
Pointer to the limiter or nullptr if not found

Definition at line 487 of file resource_manager.h.

487 {
488 std::lock_guard<std::mutex> lock(mutex_);
489 auto it = rate_limiters_.find(name);
490 return it != rate_limiters_.end() ? it->second.get() : nullptr;
491 }

References mutex_, and rate_limiters_.

◆ is_healthy()

common::Result< bool > kcenon::monitoring::resource_manager::is_healthy ( ) const
inline

Check if all resources are healthy.

Returns
Success with health status

Definition at line 555 of file resource_manager.h.

555 {
556 std::lock_guard<std::mutex> lock(mutex_);
557
558 for (const auto& [name, manager] : memory_quotas_) {
559 if (manager->is_over_critical_threshold()) {
560 return common::ok(false);
561 }
562 }
563
564 return common::ok(true);
565 }

References memory_quotas_, and mutex_.

Member Data Documentation

◆ cpu_throttlers_

std::unordered_map<std::string, std::unique_ptr<cpu_throttler> > kcenon::monitoring::resource_manager::cpu_throttlers_
private

Definition at line 594 of file resource_manager.h.

Referenced by add_cpu_throttler(), get_all_metrics(), and get_cpu_throttler().

◆ memory_quotas_

std::unordered_map<std::string, std::unique_ptr<memory_quota_manager> > kcenon::monitoring::resource_manager::memory_quotas_
private

◆ mutex_

std::mutex kcenon::monitoring::resource_manager::mutex_
mutableprivate

◆ name_

std::string kcenon::monitoring::resource_manager::name_
private

Definition at line 591 of file resource_manager.h.

◆ rate_limiters_

std::unordered_map<std::string, std::unique_ptr<rate_limiter> > kcenon::monitoring::resource_manager::rate_limiters_
private

Definition at line 592 of file resource_manager.h.

Referenced by add_rate_limiter(), get_all_metrics(), and get_rate_limiter().


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