xrpld
Loading...
Searching...
No Matches
TrafficCount.h
1#pragma once
2
3#include <xrpl/beast/utility/instrumentation.h>
4
5#include <google/protobuf/message.h>
6
7#include <xrpl.pb.h>
8
9#include <atomic>
10#include <cstddef>
11#include <cstdint>
12#include <string>
13#include <unordered_map>
14
15namespace xrpl {
16
36{
37public:
38 enum class Category : std::size_t;
39
41 {
42 public:
44
49
53
55 : name(ts.name)
56 , bytesIn(ts.bytesIn.load())
57 , bytesOut(ts.bytesOut.load())
58 , messagesIn(ts.messagesIn.load())
59 , messagesOut(ts.messagesOut.load())
60 {
61 }
62
63 operator bool() const
64 {
65 return (messagesIn != 0u) || (messagesOut != 0u);
66 }
67 };
68
69 // If you add entries to this enum, you need to update the initialization
70 // of the arrays at the bottom of this file which map array numbers to
71 // human-readable, monitoring-tool friendly names.
72 enum class Category : std::size_t {
73 Base, // basic peer overhead, must be first
74
75 Cluster, // cluster overhead
76 Overlay, // overlay management
77 Manifests, // manifest management
78
79 Transaction, // transaction messages
80 // The following categories breakdown transaction message type
81 TransactionDuplicate, // duplicate transaction messages
82
83 Proposal, // proposal messages
84 // The following categories breakdown proposal message type
85 ProposalUntrusted, // proposals from untrusted validators
86 ProposalDuplicate, // proposals seen previously
87
88 Validation, // validation messages
89 // The following categories breakdown validation message type
90 ValidationUntrusted, // validations from untrusted validators
91 ValidationDuplicate, // validations seen previously
92
94
96 SquelchSuppressed, // egress traffic amount suppressed by squelching
97 SquelchIgnored, // the traffic amount that came from peers ignoring
98 // squelch messages
99
100 // TMHaveSet message:
101 GetSet, // transaction sets we try to get
102 ShareSet, // transaction sets we get
103
104 // TMLedgerData: transaction set candidate
107
108 // TMLedgerData: transaction node
111
112 // TMLedgerData: account state node
115
116 // TMLedgerData: generic
119
120 // TMGetLedger: transaction set candidate
123
124 // TMGetLedger: transaction node
127
128 // TMGetLedger: account state node
131
132 // TMGetLedger: generic
135
136 // TMGetObjectByHash:
139
140 // TMGetObjectByHash:
143
144 // TMGetObjectByHash: transaction node
147
148 // TMGetObjectByHash: account state node
151
152 // TMGetObjectByHash: CAS
155
156 // TMGetObjectByHash: fetch packs
159
160 // TMGetObjectByHash: transactions
162
163 // TMGetObjectByHash: generic
166
167 // TMProofPathRequest and TMProofPathResponse
170
171 // TMReplayDeltaRequest and TMReplayDeltaResponse
174
175 // TMHaveTransactions
177
178 // TMTransactions
180
181 // The total p2p bytes sent and received on the wire
183
184 Unknown // must be last
185 };
186
187 TrafficCount() = default;
188
192 static Category
194 ::google::protobuf::Message const& message,
195 protocol::MessageType type,
196 bool inbound);
197
201 enum class IsFromCluster : bool { No = false, Yes };
202
217 [[nodiscard]] static Category
218 attribute(Category cat, IsFromCluster isFromCluster);
219
223 void
224 addCount(Category cat, bool inbound, int bytes)
225 {
226 XRPL_ASSERT(
227 cat <= Category::Unknown, "xrpl::TrafficCount::addCount : valid category input");
228
229 auto it = counts_.find(cat);
230
231 // nothing to do, the category does not exist
232 if (it == counts_.end())
233 return;
234
235 if (inbound)
236 {
237 it->second.bytesIn += bytes;
238 ++it->second.messagesIn;
239 }
240 else
241 {
242 it->second.bytesOut += bytes;
243 ++it->second.messagesOut;
244 }
245 }
246
252 [[nodiscard]] auto const&
253 getCounts() const
254 {
255 return counts_;
256 }
257
258 static std::string
260 {
261 static std::unordered_map<Category, std::string> const kCategoryMap = {
262 {Category::Base, "overhead"},
263 {Category::Cluster, "overhead_cluster"},
264 {Category::Overlay, "overhead_overlay"},
265 {Category::Manifests, "overhead_manifest"},
266 {Category::Transaction, "transactions"},
267 {Category::TransactionDuplicate, "transactions_duplicate"},
268 {Category::Proposal, "proposals"},
269 {Category::ProposalUntrusted, "proposals_untrusted"},
270 {Category::ProposalDuplicate, "proposals_duplicate"},
271 {Category::Validation, "validations"},
272 {Category::ValidationUntrusted, "validations_untrusted"},
273 {Category::ValidationDuplicate, "validations_duplicate"},
274 {Category::Validatorlist, "validator_lists"},
275 {Category::Squelch, "squelch"},
276 {Category::SquelchSuppressed, "squelch_suppressed"},
277 {Category::SquelchIgnored, "squelch_ignored"},
278 {Category::GetSet, "set_get"},
279 {Category::ShareSet, "set_share"},
280 {Category::LdTscGet, "ledger_data_Transaction_Set_candidate_get"},
281 {Category::LdTscShare, "ledger_data_Transaction_Set_candidate_share"},
282 {Category::LdTxnGet, "ledger_data_Transaction_Node_get"},
283 {Category::LdTxnShare, "ledger_data_Transaction_Node_share"},
284 {Category::LdAsnGet, "ledger_data_Account_State_Node_get"},
285 {Category::LdAsnShare, "ledger_data_Account_State_Node_share"},
286 {Category::LdGet, "ledger_data_get"},
287 {Category::LdShare, "ledger_data_share"},
288 {Category::GlTscShare, "ledger_Transaction_Set_candidate_share"},
289 {Category::GlTscGet, "ledger_Transaction_Set_candidate_get"},
290 {Category::GlTxnShare, "ledger_Transaction_node_share"},
291 {Category::GlTxnGet, "ledger_Transaction_node_get"},
292 {Category::GlAsnShare, "ledger_Account_State_node_share"},
293 {Category::GlAsnGet, "ledger_Account_State_node_get"},
294 {Category::GlShare, "ledger_share"},
295 {Category::GlGet, "ledger_get"},
296 {Category::ShareHashLedger, "getobject_Ledger_share"},
297 {Category::GetHashLedger, "getobject_Ledger_get"},
298 {Category::ShareHashTx, "getobject_Transaction_share"},
299 {Category::GetHashTx, "getobject_Transaction_get"},
300 {Category::ShareHashTxnode, "getobject_Transaction_node_share"},
301 {Category::GetHashTxnode, "getobject_Transaction_node_get"},
302 {Category::ShareHashAsnode, "getobject_Account_State_node_share"},
303 {Category::GetHashAsnode, "getobject_Account_State_node_get"},
304 {Category::ShareCasObject, "getobject_CAS_share"},
305 {Category::GetCasObject, "getobject_CAS_get"},
306 {Category::ShareFetchPack, "getobject_Fetch_Pack_share"},
307 {Category::GetFetchPack, "getobject_Fetch Pack_get"},
308 {Category::GetTransactions, "getobject_Transactions_get"},
309 {Category::ShareHash, "getobject_share"},
310 {Category::GetHash, "getobject_get"},
311 {Category::ProofPathRequest, "proof_path_request"},
312 {Category::ProofPathResponse, "proof_path_response"},
313 {Category::ReplayDeltaRequest, "replay_delta_request"},
314 {Category::ReplayDeltaResponse, "replay_delta_response"},
315 {Category::HaveTransactions, "have_transactions"},
316 {Category::RequestedTransactions, "requested_transactions"},
317 {Category::Total, "total"}};
318
319 if (auto it = kCategoryMap.find(cat); it != kCategoryMap.end())
320 return it->second;
321
322 return "unknown";
323 }
324
325protected:
384 };
385};
386
387} // namespace xrpl
Manages the set of connected peers.
Definition Overlay.h:38
std::atomic< std::uint64_t > bytesIn
TrafficStats(TrafficStats const &ts)
std::atomic< std::uint64_t > messagesIn
std::atomic< std::uint64_t > messagesOut
std::atomic< std::uint64_t > bytesOut
TrafficStats(TrafficCount::Category cat)
TrafficCount()=default
IsFromCluster
Whether a message's sender is a configured cluster member.
static Category attribute(Category cat, IsFromCluster isFromCluster)
Limits a category to what the sender can report.
static Category categorize(::google::protobuf::Message const &message, protocol::MessageType type, bool inbound)
Given a protocol message, determine which traffic category it belongs to.
auto const & getCounts() const
An up-to-date copy of all the counters.
std::unordered_map< Category, TrafficStats > counts_
void addCount(Category cat, bool inbound, int bytes)
Account for traffic associated with the given category.
static std::string toString(Category cat)
T end(T... args)
T find(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5