rippled
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 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 || messagesOut;
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.
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 transaction_duplicate, // duplicate transaction messages
76
77 proposal, // proposal messages
78 // The following categories breakdown proposal message type
79 proposal_untrusted, // proposals from untrusted validators
80 proposal_duplicate, // proposals seen previously
81
82 validation, // validation messages
83 // The following categories breakdown validation message type
84 validation_untrusted, // validations from untrusted validators
85 validation_duplicate, // validations seen previously
86
88
90 squelch_suppressed, // egress traffic amount suppressed by squelching
91 squelch_ignored, // the traffic amount that came from peers ignoring
92 // squelch messages
93
94 // TMHaveSet message:
95 get_set, // transaction sets we try to get
96 share_set, // 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
186 categorize(::google::protobuf::Message const& message, protocol::MessageType type, bool inbound);
187
189 void
190 addCount(category cat, bool inbound, int bytes)
191 {
192 XRPL_ASSERT(cat <= category::unknown, "xrpl::TrafficCount::addCount : valid category input");
193
194 auto it = counts_.find(cat);
195
196 // nothing to do, the category does not exist
197 if (it == counts_.end())
198 return;
199
200 if (inbound)
201 {
202 it->second.bytesIn += bytes;
203 ++it->second.messagesIn;
204 }
205 else
206 {
207 it->second.bytesOut += bytes;
208 ++it->second.messagesOut;
209 }
210 }
211
216 auto const&
217 getCounts() const
218 {
219 return counts_;
220 }
221
222 static std::string
224 {
225 static std::unordered_map<category, std::string> const category_map = {
226 {base, "overhead"},
227 {cluster, "overhead_cluster"},
228 {overlay, "overhead_overlay"},
229 {manifests, "overhead_manifest"},
230 {transaction, "transactions"},
231 {transaction_duplicate, "transactions_duplicate"},
232 {proposal, "proposals"},
233 {proposal_untrusted, "proposals_untrusted"},
234 {proposal_duplicate, "proposals_duplicate"},
235 {validation, "validations"},
236 {validation_untrusted, "validations_untrusted"},
237 {validation_duplicate, "validations_duplicate"},
238 {validatorlist, "validator_lists"},
239 {squelch, "squelch"},
240 {squelch_suppressed, "squelch_suppressed"},
241 {squelch_ignored, "squelch_ignored"},
242 {get_set, "set_get"},
243 {share_set, "set_share"},
244 {ld_tsc_get, "ledger_data_Transaction_Set_candidate_get"},
245 {ld_tsc_share, "ledger_data_Transaction_Set_candidate_share"},
246 {ld_txn_get, "ledger_data_Transaction_Node_get"},
247 {ld_txn_share, "ledger_data_Transaction_Node_share"},
248 {ld_asn_get, "ledger_data_Account_State_Node_get"},
249 {ld_asn_share, "ledger_data_Account_State_Node_share"},
250 {ld_get, "ledger_data_get"},
251 {ld_share, "ledger_data_share"},
252 {gl_tsc_share, "ledger_Transaction_Set_candidate_share"},
253 {gl_tsc_get, "ledger_Transaction_Set_candidate_get"},
254 {gl_txn_share, "ledger_Transaction_node_share"},
255 {gl_txn_get, "ledger_Transaction_node_get"},
256 {gl_asn_share, "ledger_Account_State_node_share"},
257 {gl_asn_get, "ledger_Account_State_node_get"},
258 {gl_share, "ledger_share"},
259 {gl_get, "ledger_get"},
260 {share_hash_ledger, "getobject_Ledger_share"},
261 {get_hash_ledger, "getobject_Ledger_get"},
262 {share_hash_tx, "getobject_Transaction_share"},
263 {get_hash_tx, "getobject_Transaction_get"},
264 {share_hash_txnode, "getobject_Transaction_node_share"},
265 {get_hash_txnode, "getobject_Transaction_node_get"},
266 {share_hash_asnode, "getobject_Account_State_node_share"},
267 {get_hash_asnode, "getobject_Account_State_node_get"},
268 {share_cas_object, "getobject_CAS_share"},
269 {get_cas_object, "getobject_CAS_get"},
270 {share_fetch_pack, "getobject_Fetch_Pack_share"},
271 {get_fetch_pack, "getobject_Fetch Pack_get"},
272 {get_transactions, "getobject_Transactions_get"},
273 {share_hash, "getobject_share"},
274 {get_hash, "getobject_get"},
275 {proof_path_request, "proof_path_request"},
276 {proof_path_response, "proof_path_response"},
277 {replay_delta_request, "replay_delta_request"},
278 {replay_delta_response, "replay_delta_response"},
279 {have_transactions, "have_transactions"},
280 {requested_transactions, "requested_transactions"},
281 {total, "total"}};
282
283 if (auto it = category_map.find(cat); it != category_map.end())
284 return it->second;
285
286 return "unknown";
287 }
288
289protected:
291 {base, {base}},
292 {cluster, {cluster}},
293 {overlay, {overlay}},
294 {manifests, {manifests}},
297 {proposal, {proposal}},
304 {squelch, {squelch}},
307 {get_set, {get_set}},
308 {share_set, {share_set}},
315 {ld_get, {ld_get}},
316 {ld_share, {ld_share}},
323 {gl_share, {gl_share}},
324 {gl_get, {gl_get}},
339 {get_hash, {get_hash}},
346 {total, {total}},
347 {unknown, {unknown}},
348 };
349};
350
351} // namespace xrpl
TrafficStats(TrafficCount::category cat)
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
TrafficCount is used to count ingress and egress wire bytes and number of messages.
std::unordered_map< category, TrafficStats > counts_
TrafficCount()=default
static std::string to_string(category cat)
void addCount(category cat, bool inbound, int bytes)
Account for traffic associated with the given category.
auto const & getCounts() const
An up-to-date copy of all the counters.
static category categorize(::google::protobuf::Message const &message, protocol::MessageType type, bool inbound)
Given a protocol message, determine which traffic category it belongs to.
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