MADARA  3.4.1
madara::transport::BandwidthMonitor Class Reference

Provides monitoring capability of a transport's bandwidth. More...

#include <BandwidthMonitor.h>

Public Member Functions

 BandwidthMonitor (const BandwidthMonitor &rhs)
 Copy constructor. More...
 
 BandwidthMonitor (time_t window_in_secs=10)
 Default constructor. More...
 
virtual ~BandwidthMonitor ()
 Destructor. More...
 
void add (time_t timestamp, uint64_t size)
 Adds a message to the monitor. More...
 
void add (uint64_t size)
 Adds a message to the monitor. More...
 
void clear (void)
 Clears the bandwidth monitor. More...
 
uint64_t get_bytes_per_second (void)
 Queries the monitor for the current bandwidth utilization per second over the past window. More...
 
size_t get_number_of_messages (void)
 Returns the number of messages in the past window. More...
 
uint64_t get_utilization (void)
 Queries the monitor for the current bandwidth utilization. More...
 
bool is_bandwidth_violated (int64_t limit)
 Checks send and receive bandwidth against send and receive limits. More...
 
void operator= (const BandwidthMonitor &rhs)
 Assignment operator. More...
 
void print_utilization (void)
 Prints the number of messages and utilization within the past window. More...
 
void set_window (time_t window_in_secs)
 Sets the window in seconds to measure bandwidth. More...
 

Protected Member Functions

time_t update_utilization (void)
 Updates utilization for most public functions. More...
 

Protected Attributes

BandwidthMessages messages_
 Map of timestamps to messages. More...
 
MADARA_LOCK_TYPE mutex_
 Mutex for supporting multithreaded monitor calls. More...
 
uint64_t utilization_
 Utilization. More...
 
time_t window_
 Time window for useful messages to bandwidth calculations. More...
 

Detailed Description

Provides monitoring capability of a transport's bandwidth.

Definition at line 33 of file BandwidthMonitor.h.

Constructor & Destructor Documentation

◆ BandwidthMonitor() [1/2]

madara::transport::BandwidthMonitor::BandwidthMonitor ( time_t  window_in_secs = 10)

Default constructor.

Parameters
window_in_secsTime window to measure bandwidth usage

Definition at line 6 of file BandwidthMonitor.cpp.

◆ BandwidthMonitor() [2/2]

madara::transport::BandwidthMonitor::BandwidthMonitor ( const BandwidthMonitor rhs)

Copy constructor.

Parameters
rhsthe value to be copied into this class

Definition at line 11 of file BandwidthMonitor.cpp.

◆ ~BandwidthMonitor()

madara::transport::BandwidthMonitor::~BandwidthMonitor ( )
virtual

Destructor.

Definition at line 19 of file BandwidthMonitor.cpp.

Member Function Documentation

◆ add() [1/2]

void madara::transport::BandwidthMonitor::add ( time_t  timestamp,
uint64_t  size 
)

Adds a message to the monitor.

Parameters
timestampthe time the message occured
sizethe size of the message

Definition at line 52 of file BandwidthMonitor.cpp.

◆ add() [2/2]

void madara::transport::BandwidthMonitor::add ( uint64_t  size)

Adds a message to the monitor.

Parameters
sizethe size of the message

Definition at line 39 of file BandwidthMonitor.cpp.

◆ clear()

void madara::transport::BandwidthMonitor::clear ( void  )

Clears the bandwidth monitor.

Definition at line 93 of file BandwidthMonitor.cpp.

◆ get_bytes_per_second()

uint64_t madara::transport::BandwidthMonitor::get_bytes_per_second ( void  )

Queries the monitor for the current bandwidth utilization per second over the past window.

Returns
current bandwidth utilization in bytes/s

Definition at line 84 of file BandwidthMonitor.cpp.

◆ get_number_of_messages()

size_t madara::transport::BandwidthMonitor::get_number_of_messages ( void  )

Returns the number of messages in the past window.

Returns
the number of types that have filters

Definition at line 113 of file BandwidthMonitor.cpp.

◆ get_utilization()

uint64_t madara::transport::BandwidthMonitor::get_utilization ( void  )

Queries the monitor for the current bandwidth utilization.

Returns
current bandwidth utilization in bytes over the entire window (this is not bytes/s)

Definition at line 75 of file BandwidthMonitor.cpp.

◆ is_bandwidth_violated()

bool madara::transport::BandwidthMonitor::is_bandwidth_violated ( int64_t  limit)

Checks send and receive bandwidth against send and receive limits.

Parameters
limitif -1, does not check. If positive, checks against current usage

Definition at line 65 of file BandwidthMonitor.cpp.

◆ operator=()

void madara::transport::BandwidthMonitor::operator= ( const BandwidthMonitor rhs)

Assignment operator.

Parameters
rhsthe value to be copied into this class

Definition at line 21 of file BandwidthMonitor.cpp.

◆ print_utilization()

void madara::transport::BandwidthMonitor::print_utilization ( void  )

Prints the number of messages and utilization within the past window.

Definition at line 100 of file BandwidthMonitor.cpp.

◆ set_window()

void madara::transport::BandwidthMonitor::set_window ( time_t  window_in_secs)

Sets the window in seconds to measure bandwidth.

Parameters
window_in_secsTime window to measure bandwidth usage

Definition at line 32 of file BandwidthMonitor.cpp.

◆ update_utilization()

time_t madara::transport::BandwidthMonitor::update_utilization ( void  )
inlineprotected

Updates utilization for most public functions.

Returns
current time

if we have an old message, remove it from utilization and schedule a deletion

Definition at line 8 of file BandwidthMonitor.inl.

Member Data Documentation

◆ messages_

BandwidthMessages madara::transport::BandwidthMonitor::messages_
protected

Map of timestamps to messages.

Definition at line 130 of file BandwidthMonitor.h.

◆ mutex_

MADARA_LOCK_TYPE madara::transport::BandwidthMonitor::mutex_
mutableprotected

Mutex for supporting multithreaded monitor calls.

Definition at line 125 of file BandwidthMonitor.h.

◆ utilization_

uint64_t madara::transport::BandwidthMonitor::utilization_
protected

Utilization.

Definition at line 135 of file BandwidthMonitor.h.

◆ window_

time_t madara::transport::BandwidthMonitor::window_
protected

Time window for useful messages to bandwidth calculations.

Definition at line 140 of file BandwidthMonitor.h.


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