MADARA  3.1.8
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 "ace/Guard_T.h"
20 #include "ace/Recursive_Thread_Mutex.h"
21 #include "madara/MADARA_export.h"
22 
23 namespace madara
24 {
25  namespace transport
26  {
27  typedef std::pair <time_t, uint64_t> BandwidthRecord;
28  typedef std::deque <BandwidthRecord> BandwidthMessages;
29 
35  class MADARA_Export BandwidthMonitor
36  {
37  public:
42  BandwidthMonitor (time_t window_in_secs = 10);
43 
48  BandwidthMonitor (const BandwidthMonitor & rhs);
49 
53  virtual ~BandwidthMonitor ();
54 
59  void operator= (const BandwidthMonitor & rhs);
60 
65  void add (uint64_t size);
66 
72  void add (time_t timestamp, uint64_t size);
73 
79  bool is_bandwidth_violated (int64_t limit);
80 
85  void set_window (time_t window_in_secs);
86 
92  uint64_t get_utilization (void);
93 
99  uint64_t get_bytes_per_second (void);
100 
104  void clear (void);
105 
109  void print_utilization (void);
110 
115  size_t get_number_of_messages (void);
116 
117  protected:
122  time_t update_utilization (void);
123 
127  mutable MADARA_LOCK_TYPE mutex_;
128 
132  BandwidthMessages messages_;
133 
137  uint64_t utilization_;
138 
142  time_t window_;
143  };
144  }
145 }
146 
147 #include "BandwidthMonitor.inl"
148 
149 #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.