xrpld
Loading...
Searching...
No Matches
TrafficCount.h
1#pragma once
2
3#include <xrpl/beast/utility/instrumentation.h>
4#include <xrpl/protocol/messages.h>
5
6#include <atomic>
7#include <cstdint>
8
9namespace xrpl {
10
30{
31public:
32 enum class Category : std::size_t;
33
35 {
36 public:
38
43
47
49 : name(ts.name)
50 , bytesIn(ts.bytesIn.load())
51 , bytesOut(ts.bytesOut.load())
52 , messagesIn(ts.messagesIn.load())
53 , messagesOut(ts.messagesOut.load())
54 {
55 }
56
57 operator bool() const
58 {
59 return (messagesIn != 0u) || (messagesOut != 0u);
60 }
61 };
62
63 // If you add entries to this enum, you need to update the initialization
64 // of the arrays at the bottom of this file which map array numbers to
65 // human-readable, monitoring-tool friendly names.
66 enum class Category : std::size_t {
67 Base, // basic peer overhead, must be first
68
69 Cluster, // cluster overhead
70 Overlay, // overlay management
71 Manifests, // manifest management
72
73 Transaction, // transaction messages
74 // The following categories breakdown transaction message type
75 TransactionDuplicate, // duplicate transaction messages
76
77 Proposal, // proposal messages
78 // The following categories breakdown proposal message type
79 ProposalUntrusted, // proposals from untrusted validators
80 ProposalDuplicate, // proposals seen previously
81
82 Validation, // validation messages
83 // The following categories breakdown validation message type
84 ValidationUntrusted, // validations from untrusted validators
85 ValidationDuplicate, // validations seen previously
86
88
90 SquelchSuppressed, // egress traffic amount suppressed by squelching
91 SquelchIgnored, // the traffic amount that came from peers ignoring
92 // squelch messages
93
94 // TMHaveSet message:
95 GetSet, // transaction sets we try to get
96 ShareSet, // transaction sets we get
97
98 // TMLedgerData: transaction set candidate
101
102 // TMLedgerData: transaction node
105
106 // TMLedgerData: account state node
109
110 // TMLedgerData: generic
113
114 // TMGetLedger: transaction set candidate
117
118 // TMGetLedger: transaction node
121
122 // TMGetLedger: account state node
125
126 // TMGetLedger: generic
129
130 // TMGetObjectByHash:
133
134 // TMGetObjectByHash:
137
138 // TMGetObjectByHash: transaction node
141
142 // TMGetObjectByHash: account state node
145
146 // TMGetObjectByHash: CAS
149
150 // TMGetObjectByHash: fetch packs
153
154 // TMGetObjectByHash: transactions
156
157 // TMGetObjectByHash: generic
160
161 // TMProofPathRequest and TMProofPathResponse
164
165 // TMReplayDeltaRequest and TMReplayDeltaResponse
168
169 // TMHaveTransactions
171
172 // TMTransactions
174
175 // The total p2p bytes sent and received on the wire
177
178 Unknown // must be last
179 };
180
181 TrafficCount() = default;
182
185 static Category
187 ::google::protobuf::Message const& message,
188 protocol::MessageType type,
189 bool inbound);
190
192 void
193 addCount(Category cat, bool inbound, int bytes)
194 {
195 XRPL_ASSERT(
196 cat <= Category::Unknown, "xrpl::TrafficCount::addCount : valid category input");
197
198 auto it = counts_.find(cat);
199
200 // nothing to do, the category does not exist
201 if (it == counts_.end())
202 return;
203
204 if (inbound)
205 {
206 it->second.bytesIn += bytes;
207 ++it->second.messagesIn;
208 }
209 else
210 {
211 it->second.bytesOut += bytes;
212 ++it->second.messagesOut;
213 }
214 }
215
220 [[nodiscard]] auto const&
221 getCounts() const
222 {
223 return counts_;
224 }
225
226 static std::string
228 {
229 static std::unordered_map<Category, std::string> const kCategoryMap = {
230 {Category::Base, "overhead"},
231 {Category::Cluster, "overhead_cluster"},
232 {Category::Overlay, "overhead_overlay"},
233 {Category::Manifests, "overhead_manifest"},
234 {Category::Transaction, "transactions"},
235 {Category::TransactionDuplicate, "transactions_duplicate"},
236 {Category::Proposal, "proposals"},
237 {Category::ProposalUntrusted, "proposals_untrusted"},
238 {Category::ProposalDuplicate, "proposals_duplicate"},
239 {Category::Validation, "validations"},
240 {Category::ValidationUntrusted, "validations_untrusted"},
241 {Category::ValidationDuplicate, "validations_duplicate"},
242 {Category::Validatorlist, "validator_lists"},
243 {Category::Squelch, "squelch"},
244 {Category::SquelchSuppressed, "squelch_suppressed"},
245 {Category::SquelchIgnored, "squelch_ignored"},
246 {Category::GetSet, "set_get"},
247 {Category::ShareSet, "set_share"},
248 {Category::LdTscGet, "ledger_data_Transaction_Set_candidate_get"},
249 {Category::LdTscShare, "ledger_data_Transaction_Set_candidate_share"},
250 {Category::LdTxnGet, "ledger_data_Transaction_Node_get"},
251 {Category::LdTxnShare, "ledger_data_Transaction_Node_share"},
252 {Category::LdAsnGet, "ledger_data_Account_State_Node_get"},
253 {Category::LdAsnShare, "ledger_data_Account_State_Node_share"},
254 {Category::LdGet, "ledger_data_get"},
255 {Category::LdShare, "ledger_data_share"},
256 {Category::GlTscShare, "ledger_Transaction_Set_candidate_share"},
257 {Category::GlTscGet, "ledger_Transaction_Set_candidate_get"},
258 {Category::GlTxnShare, "ledger_Transaction_node_share"},
259 {Category::GlTxnGet, "ledger_Transaction_node_get"},
260 {Category::GlAsnShare, "ledger_Account_State_node_share"},
261 {Category::GlAsnGet, "ledger_Account_State_node_get"},
262 {Category::GlShare, "ledger_share"},
263 {Category::GlGet, "ledger_get"},
264 {Category::ShareHashLedger, "getobject_Ledger_share"},
265 {Category::GetHashLedger, "getobject_Ledger_get"},
266 {Category::ShareHashTx, "getobject_Transaction_share"},
267 {Category::GetHashTx, "getobject_Transaction_get"},
268 {Category::ShareHashTxnode, "getobject_Transaction_node_share"},
269 {Category::GetHashTxnode, "getobject_Transaction_node_get"},
270 {Category::ShareHashAsnode, "getobject_Account_State_node_share"},
271 {Category::GetHashAsnode, "getobject_Account_State_node_get"},
272 {Category::ShareCasObject, "getobject_CAS_share"},
273 {Category::GetCasObject, "getobject_CAS_get"},
274 {Category::ShareFetchPack, "getobject_Fetch_Pack_share"},
275 {Category::GetFetchPack, "getobject_Fetch Pack_get"},
276 {Category::GetTransactions, "getobject_Transactions_get"},
277 {Category::ShareHash, "getobject_share"},
278 {Category::GetHash, "getobject_get"},
279 {Category::ProofPathRequest, "proof_path_request"},
280 {Category::ProofPathResponse, "proof_path_response"},
281 {Category::ReplayDeltaRequest, "replay_delta_request"},
282 {Category::ReplayDeltaResponse, "replay_delta_response"},
283 {Category::HaveTransactions, "have_transactions"},
284 {Category::RequestedTransactions, "requested_transactions"},
285 {Category::Total, "total"}};
286
287 if (auto it = kCategoryMap.find(cat); it != kCategoryMap.end())
288 return it->second;
289
290 return "unknown";
291 }
292
293protected:
352 };
353};
354
355} // namespace xrpl
Manages the set of connected peers.
Definition Overlay.h:25
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
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