MADARA  3.4.1
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 
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 
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
Provides monitoring capability of a transport's bandwidth.
time_t window_
Time window for useful messages to bandwidth calculations.
MADARA_LOCK_TYPE mutex_
Mutex for supporting multithreaded monitor calls.
BandwidthMessages messages_
Map of timestamps to messages.
std::deque< BandwidthRecord > BandwidthMessages
std::pair< time_t, uint64_t > BandwidthRecord
Copyright(c) 2020 Galois.