7 : utilization_(0), window_(window_in_secs)
13 : messages_(rhs.messages_),
14 utilization_(rhs.utilization_),
23 MADARA_GUARD_TYPE guard(mutex_);
34 MADARA_GUARD_TYPE guard(mutex_);
36 window_ = window_in_secs;
41 MADARA_GUARD_TYPE guard(mutex_);
45 time_t cur_time = update_utilization();
49 messages_.push_back(entry);
54 MADARA_GUARD_TYPE guard(mutex_);
62 messages_.push_back(entry);
69 if (limit >= 0 && uint64_t(limit) > get_utilization())
77 MADARA_GUARD_TYPE guard(mutex_);
86 MADARA_GUARD_TYPE guard(mutex_);
90 return utilization_ / (uint64_t)window_;
95 MADARA_GUARD_TYPE guard(mutex_);
102 MADARA_GUARD_TYPE guard(mutex_);
104 update_utilization();
107 "Bandwidth: %d messages "
108 "for %" PRIu64
" bytes over %lld window (%" PRIu64
" B/s)\n",
109 messages_.size(), utilization_, (
long long)window_,
110 get_bytes_per_second());
115 MADARA_GUARD_TYPE guard(mutex_);
117 update_utilization();
119 return messages_.size();
#define madara_logger_ptr_log(loggering, level,...)
Fast version of the madara::logger::log method for Logger pointers.
Provides monitoring capability of a transport's bandwidth.
void operator=(const BandwidthMonitor &rhs)
Assignment operator.
void set_window(time_t window_in_secs)
Sets the window in seconds to measure bandwidth.
uint64_t get_bytes_per_second(void)
Queries the monitor for the current bandwidth utilization per second over the past window.
BandwidthMonitor(time_t window_in_secs=10)
Default constructor.
uint64_t utilization_
Utilization.
virtual ~BandwidthMonitor()
Destructor.
bool is_bandwidth_violated(int64_t limit)
Checks send and receive bandwidth against send and receive limits.
uint64_t get_utilization(void)
Queries the monitor for the current bandwidth utilization.
void add(uint64_t size)
Adds a message to the monitor.
time_t window_
Time window for useful messages to bandwidth calculations.
void clear(void)
Clears the bandwidth monitor.
size_t get_number_of_messages(void)
Returns the number of messages in the past window.
void print_utilization(void)
Prints the number of messages and utilization within the past window.
BandwidthMessages messages_
Map of timestamps to messages.
T get(const KnowledgeRecord &kr)
Get the value of a KnowlegeRecord.
MADARA_EXPORT utility::Refcounter< logger::Logger > global_logger
std::pair< time_t, uint64_t > BandwidthRecord