TARAXA
time_period_packets_stats.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "common/types.hpp"
4 #include "logger/logger.hpp"
7 
8 namespace taraxa::network::tarcap {
9 
10 class PeersState;
11 class TaraxaPeer;
12 
17  public:
18  TimePeriodPacketsStats(std::chrono::milliseconds reset_time_period, const addr_t& node_addr = {});
19 
20  void addReceivedPacket(const std::string& packet_type, const dev::p2p::NodeID& node, const PacketStats& packet);
21  void addSentPacket(const std::string& packet_type, const dev::p2p::NodeID& node, const PacketStats& packet);
22 
26  void processStats(const std::vector<std::shared_ptr<TaraxaPeer>>& all_peers);
27 
28  private:
37  std::pair<bool, std::chrono::milliseconds> validMaxStatsTimePeriod(
38  const std::chrono::system_clock::time_point& start_time) const;
39 
40  private:
41  // Interval during which are the peer stats supposed to be collected
42  const std::chrono::milliseconds kResetTimePeriod;
43 
44  // Collected packets stats during time period
47 
48  // Max stats for all received packets combined per peer
50 
51  // Declare logger instances
53 };
54 
55 } // namespace taraxa::network::tarcap
Definition: FixedHash.h:35
MAx stats data holder class.
Definition: max_stats.hpp:12
Stats single packet type.
Definition: packet_stats.hpp:13
Stats for all packet types.
Definition: packets_stats.hpp:13
Stats for all received and sent packets of all types.
Definition: time_period_packets_stats.hpp:16
const std::chrono::milliseconds kResetTimePeriod
Definition: time_period_packets_stats.hpp:42
void processStats(const std::vector< std::shared_ptr< TaraxaPeer >> &all_peers)
Logs both received as well as sent packets stats + updates max count/size and reset stats.
Definition: time_period_packets_stats.cpp:42
PacketsStats received_packets_stats_
Definition: time_period_packets_stats.hpp:46
void addSentPacket(const std::string &packet_type, const dev::p2p::NodeID &node, const PacketStats &packet)
Definition: time_period_packets_stats.cpp:21
void addReceivedPacket(const std::string &packet_type, const dev::p2p::NodeID &node, const PacketStats &packet)
Definition: time_period_packets_stats.cpp:15
TimePeriodPacketsStats(std::chrono::milliseconds reset_time_period, const addr_t &node_addr={})
Definition: time_period_packets_stats.cpp:10
PacketsStats sent_packets_stats_
Definition: time_period_packets_stats.hpp:45
std::pair< bool, std::chrono::milliseconds > validMaxStatsTimePeriod(const std::chrono::system_clock::time_point &start_time) const
Checks if now() - start_time is approximately equal to kResetTimePeriod. Stats are reset in regular i...
Definition: time_period_packets_stats.cpp:27
MaxStats peer_max_stats_
Definition: time_period_packets_stats.hpp:49
#define LOG_OBJECTS_DEFINE
Definition: logger.hpp:60
std::chrono::system_clock::time_point time_point
Definition: watches.hpp:12
Definition: vote_manager.hpp:23