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

Base interface for rate limiters. More...

#include <resource_manager.h>

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

Public Member Functions

virtual ~rate_limiter ()=default
 
virtual bool try_acquire (size_t count=1)=0
 Try to acquire tokens.
 
template<typename Func >
auto execute (Func &&func) -> decltype(func())
 Execute a function with rate limiting.
 
virtual const std::string & get_name () const =0
 Get the name of this rate limiter.
 

Detailed Description

Base interface for rate limiters.

Definition at line 170 of file resource_manager.h.

Constructor & Destructor Documentation

◆ ~rate_limiter()

virtual kcenon::monitoring::rate_limiter::~rate_limiter ( )
virtualdefault

Member Function Documentation

◆ execute()

template<typename Func >
auto kcenon::monitoring::rate_limiter::execute ( Func && func) -> decltype(func())
inline

Execute a function with rate limiting.

Template Parameters
FuncFunction type that returns common::Result<T>
Parameters
funcFunction to execute
Returns
Result of the function or error if rate limited

Definition at line 188 of file resource_manager.h.

188 {
189 using result_type = decltype(func());
190 using value_type = typename result_type::value_type;
191
192 if (!try_acquire(1)) {
193 return common::make_error<value_type>(static_cast<int>(monitoring_error_code::resource_exhausted),
194 "Rate limit exceeded for '" + get_name() + "'");
195 }
196 return func();
197 }
virtual const std::string & get_name() const =0
Get the name of this rate limiter.
virtual bool try_acquire(size_t count=1)=0
Try to acquire tokens.

References get_name(), kcenon::monitoring::resource_exhausted, and try_acquire().

Here is the call graph for this function:

◆ get_name()

virtual const std::string & kcenon::monitoring::rate_limiter::get_name ( ) const
pure virtual

Get the name of this rate limiter.

Implemented in kcenon::monitoring::leaky_bucket_limiter, and kcenon::monitoring::token_bucket_limiter.

Referenced by execute().

Here is the caller graph for this function:

◆ try_acquire()

virtual bool kcenon::monitoring::rate_limiter::try_acquire ( size_t count = 1)
pure virtual

Try to acquire tokens.

Parameters
countNumber of tokens to acquire
Returns
true if tokens were acquired

Implemented in kcenon::monitoring::leaky_bucket_limiter, and kcenon::monitoring::token_bucket_limiter.

Referenced by execute().

Here is the caller graph for this function:

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