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 void
202 addCount(Category cat, bool inbound, int bytes)
203 {
204 XRPL_ASSERT(
205 cat <= Category::Unknown, "xrpl::TrafficCount::addCount : valid category input");
206
207 auto it = counts_.find(cat);
208
209 // nothing to do, the category does not exist
210 if (it == counts_.end())
211 return;
212
213 if (inbound)
214 {
215 it->second.bytesIn += bytes;
216 ++it->second.messagesIn;
217 }
218 else
219 {
220 it->second.bytesOut += bytes;
221 ++it->second.messagesOut;
222 }
223 }
224
230 [[nodiscard]] auto const&
231 getCounts() const
232 {
233 return counts_;
234 }
235
236 static std::string
238 {
239 static std::unordered_map<Category, std::string> const kCategoryMap = {
240 {Category::Base, "overhead"},
241 {Category::Cluster, "overhead_cluster"},
242 {Category::Overlay, "overhead_overlay"},
243 {Category::Manifests, "overhead_manifest"},
244 {Category::Transaction, "transactions"},
245 {Category::TransactionDuplicate, "transactions_duplicate"},
246 {Category::Proposal, "proposals"},
247 {Category::ProposalUntrusted, "proposals_untrusted"},
248 {Category::ProposalDuplicate, "proposals_duplicate"},
249 {Category::Validation, "validations"},
250 {Category::ValidationUntrusted, "validations_untrusted"},
251 {Category::ValidationDuplicate, "validations_duplicate"},
252 {Category::Validatorlist, "validator_lists"},
253 {Category::Squelch, "squelch"},
254 {Category::SquelchSuppressed, "squelch_suppressed"},
255 {Category::SquelchIgnored, "squelch_ignored"},
256 {Category::GetSet, "set_get"},
257 {Category::ShareSet, "set_share"},
258 {Category::LdTscGet, "ledger_data_Transaction_Set_candidate_get"},
259 {Category::LdTscShare, "ledger_data_Transaction_Set_candidate_share"},
260 {Category::LdTxnGet, "ledger_data_Transaction_Node_get"},
261 {Category::LdTxnShare, "ledger_data_Transaction_Node_share"},
262 {Category::LdAsnGet, "ledger_data_Account_State_Node_get"},
263 {Category::LdAsnShare, "ledger_data_Account_State_Node_share"},
264 {Category::LdGet, "ledger_data_get"},
265 {Category::LdShare, "ledger_data_share"},
266 {Category::GlTscShare, "ledger_Transaction_Set_candidate_share"},
267 {Category::GlTscGet, "ledger_Transaction_Set_candidate_get"},
268 {Category::GlTxnShare, "ledger_Transaction_node_share"},
269 {Category::GlTxnGet, "ledger_Transaction_node_get"},
270 {Category::GlAsnShare, "ledger_Account_State_node_share"},
271 {Category::GlAsnGet, "ledger_Account_State_node_get"},
272 {Category::GlShare, "ledger_share"},
273 {Category::GlGet, "ledger_get"},
274 {Category::ShareHashLedger, "getobject_Ledger_share"},
275 {Category::GetHashLedger, "getobject_Ledger_get"},
276 {Category::ShareHashTx, "getobject_Transaction_share"},
277 {Category::GetHashTx, "getobject_Transaction_get"},
278 {Category::ShareHashTxnode, "getobject_Transaction_node_share"},
279 {Category::GetHashTxnode, "getobject_Transaction_node_get"},
280 {Category::ShareHashAsnode, "getobject_Account_State_node_share"},
281 {Category::GetHashAsnode, "getobject_Account_State_node_get"},
282 {Category::ShareCasObject, "getobject_CAS_share"},
283 {Category::GetCasObject, "getobject_CAS_get"},
284 {Category::ShareFetchPack, "getobject_Fetch_Pack_share"},
285 {Category::GetFetchPack, "getobject_Fetch Pack_get"},
286 {Category::GetTransactions, "getobject_Transactions_get"},
287 {Category::ShareHash, "getobject_share"},
288 {Category::GetHash, "getobject_get"},
289 {Category::ProofPathRequest, "proof_path_request"},
290 {Category::ProofPathResponse, "proof_path_response"},
291 {Category::ReplayDeltaRequest, "replay_delta_request"},
292 {Category::ReplayDeltaResponse, "replay_delta_response"},
293 {Category::HaveTransactions, "have_transactions"},
294 {Category::RequestedTransactions, "requested_transactions"},
295 {Category::Total, "total"}};
296
297 if (auto it = kCategoryMap.find(cat); it != kCategoryMap.end())
298 return it->second;
299
300 return "unknown";
301 }
302
303protected:
362 };
363};
364
365} // 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
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