MADARA  3.2.3
BandwidthMonitor.h
Go to the documentation of this file.
1 
2 
3 #ifndef _MADARA_BANDWIDTH_MONITOR_H
4 #define _MADARA_BANDWIDTH_MONITOR_H
5 
14 #include <deque>
15 #include <time.h>
16 
17 #include "madara/LockType.h"
18 #include "madara/utility/StdInt.h"
19 #include "madara/MadaraExport.h"
20 
21 namespace madara
22 {
23  namespace transport
24  {
25  typedef std::pair <time_t, uint64_t> BandwidthRecord;
26  typedef std::deque <BandwidthRecord> BandwidthMessages;
27 
33  class MADARA_EXPORT BandwidthMonitor
34  {
35  public:
40  BandwidthMonitor (time_t window_in_secs = 10);
41 
46  BandwidthMonitor (const BandwidthMonitor & rhs);
47 
51  virtual ~BandwidthMonitor ();
52 
57  void operator= (const BandwidthMonitor & rhs);
58 
63  void add (uint64_t size);
64 
70  void add (time_t timestamp, uint64_t size);
71 
77  bool is_bandwidth_violated (int64_t limit);
78 
83  void set_window (time_t window_in_secs);
84 
90  uint64_t get_utilization (void);
91 
97  uint64_t get_bytes_per_second (void);
98 
102  void clear (void);
103 
107  void print_utilization (void);
108 
113  size_t get_number_of_messages (void);
114 
115  protected:
120  time_t update_utilization (void);
121 
125  mutable MADARA_LOCK_TYPE mutex_;
126 
130  BandwidthMessages messages_;
131 
135  uint64_t utilization_;
136 
140  time_t window_;
141  };
142  }
143 }
144 
145 #include "BandwidthMonitor.inl"
146 
147 #endif // _MADARA_BANDWIDTH_MONITOR_H
MADARA_LOCK_TYPE mutex_
Mutex for supporting multithreaded monitor calls.
BandwidthMessages messages_
Map of timestamps to messages.
std::pair< time_t, uint64_t > BandwidthRecord
std::deque< BandwidthRecord > BandwidthMessages
Provides monitoring capability of a transport&#39;s bandwidth.
Copyright (c) 2015 Carnegie Mellon University.
time_t window_
Time window for useful messages to bandwidth calculations.