rippled
Loading...
Searching...
No Matches
TrafficCount.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_OVERLAY_TRAFFIC_H_INCLUDED
21#define RIPPLE_OVERLAY_TRAFFIC_H_INCLUDED
22
23#include <xrpl/beast/utility/instrumentation.h>
24#include <xrpl/protocol/messages.h>
25
26#include <atomic>
27#include <cstdint>
28
29namespace ripple {
30
50{
51public:
52 enum category : std::size_t;
53
55 {
56 public:
58
63
68
70 : name(ts.name)
71 , bytesIn(ts.bytesIn.load())
72 , bytesOut(ts.bytesOut.load())
73 , messagesIn(ts.messagesIn.load())
74 , messagesOut(ts.messagesOut.load())
75 {
76 }
77
78 operator bool() const
79 {
80 return messagesIn || messagesOut;
81 }
82 };
83
84 // If you add entries to this enum, you need to update the initialization
85 // of the arrays at the bottom of this file which map array numbers to
86 // human-readable, monitoring-tool friendly names.
88 base, // basic peer overhead, must be first
89
90 cluster, // cluster overhead
91 overlay, // overlay management
92 manifests, // manifest management
93
94 transaction, // transaction messages
95 // The following categories breakdown transaction message type
96 transaction_duplicate, // duplicate transaction messages
97
98 proposal, // proposal messages
99 // The following categories breakdown proposal message type
100 proposal_untrusted, // proposals from untrusted validators
101 proposal_duplicate, // proposals seen previously
102
103 validation, // validation messages
104 // The following categories breakdown validation message type
105 validation_untrusted, // validations from untrusted validators
106 validation_duplicate, // validations seen previously
107
109
111 squelch_suppressed, // egress traffic amount suppressed by squelching
112 squelch_ignored, // the traffic amount that came from peers ignoring
113 // squelch messages
114
115 // TMHaveSet message:
116 get_set, // transaction sets we try to get
117 share_set, // transaction sets we get
118
119 // TMLedgerData: transaction set candidate
122
123 // TMLedgerData: transaction node
126
127 // TMLedgerData: account state node
130
131 // TMLedgerData: generic
134
135 // TMGetLedger: transaction set candidate
138
139 // TMGetLedger: transaction node
142
143 // TMGetLedger: account state node
146
147 // TMGetLedger: generic
150
151 // TMGetObjectByHash:
154
155 // TMGetObjectByHash:
158
159 // TMGetObjectByHash: transaction node
162
163 // TMGetObjectByHash: account state node
166
167 // TMGetObjectByHash: CAS
170
171 // TMGetObjectByHash: fetch packs
174
175 // TMGetObjectByHash: transactions
177
178 // TMGetObjectByHash: generic
181
182 // TMProofPathRequest and TMProofPathResponse
185
186 // TMReplayDeltaRequest and TMReplayDeltaResponse
189
190 // TMHaveTransactions
192
193 // TMTransactions
195
196 // The total p2p bytes sent and received on the wire
198
199 unknown // must be last
200 };
201
202 TrafficCount() = default;
203
206 static category
208 ::google::protobuf::Message const& message,
209 protocol::MessageType type,
210 bool inbound);
211
213 void
214 addCount(category cat, bool inbound, int bytes)
215 {
216 XRPL_ASSERT(
217 cat <= category::unknown,
218 "ripple::TrafficCount::addCount : valid category input");
219
220 auto it = counts_.find(cat);
221
222 // nothing to do, the category does not exist
223 if (it == counts_.end())
224 return;
225
226 if (inbound)
227 {
228 it->second.bytesIn += bytes;
229 ++it->second.messagesIn;
230 }
231 else
232 {
233 it->second.bytesOut += bytes;
234 ++it->second.messagesOut;
235 }
236 }
237
242 auto const&
243 getCounts() const
244 {
245 return counts_;
246 }
247
248 static std::string
250 {
251 static std::unordered_map<category, std::string> const category_map = {
252 {base, "overhead"},
253 {cluster, "overhead_cluster"},
254 {overlay, "overhead_overlay"},
255 {manifests, "overhead_manifest"},
256 {transaction, "transactions"},
257 {transaction_duplicate, "transactions_duplicate"},
258 {proposal, "proposals"},
259 {proposal_untrusted, "proposals_untrusted"},
260 {proposal_duplicate, "proposals_duplicate"},
261 {validation, "validations"},
262 {validation_untrusted, "validations_untrusted"},
263 {validation_duplicate, "validations_duplicate"},
264 {validatorlist, "validator_lists"},
265 {squelch, "squelch"},
266 {squelch_suppressed, "squelch_suppressed"},
267 {squelch_ignored, "squelch_ignored"},
268 {get_set, "set_get"},
269 {share_set, "set_share"},
270 {ld_tsc_get, "ledger_data_Transaction_Set_candidate_get"},
271 {ld_tsc_share, "ledger_data_Transaction_Set_candidate_share"},
272 {ld_txn_get, "ledger_data_Transaction_Node_get"},
273 {ld_txn_share, "ledger_data_Transaction_Node_share"},
274 {ld_asn_get, "ledger_data_Account_State_Node_get"},
275 {ld_asn_share, "ledger_data_Account_State_Node_share"},
276 {ld_get, "ledger_data_get"},
277 {ld_share, "ledger_data_share"},
278 {gl_tsc_share, "ledger_Transaction_Set_candidate_share"},
279 {gl_tsc_get, "ledger_Transaction_Set_candidate_get"},
280 {gl_txn_share, "ledger_Transaction_node_share"},
281 {gl_txn_get, "ledger_Transaction_node_get"},
282 {gl_asn_share, "ledger_Account_State_node_share"},
283 {gl_asn_get, "ledger_Account_State_node_get"},
284 {gl_share, "ledger_share"},
285 {gl_get, "ledger_get"},
286 {share_hash_ledger, "getobject_Ledger_share"},
287 {get_hash_ledger, "getobject_Ledger_get"},
288 {share_hash_tx, "getobject_Transaction_share"},
289 {get_hash_tx, "getobject_Transaction_get"},
290 {share_hash_txnode, "getobject_Transaction_node_share"},
291 {get_hash_txnode, "getobject_Transaction_node_get"},
292 {share_hash_asnode, "getobject_Account_State_node_share"},
293 {get_hash_asnode, "getobject_Account_State_node_get"},
294 {share_cas_object, "getobject_CAS_share"},
295 {get_cas_object, "getobject_CAS_get"},
296 {share_fetch_pack, "getobject_Fetch_Pack_share"},
297 {get_fetch_pack, "getobject_Fetch Pack_get"},
298 {get_transactions, "getobject_Transactions_get"},
299 {share_hash, "getobject_share"},
300 {get_hash, "getobject_get"},
301 {proof_path_request, "proof_path_request"},
302 {proof_path_response, "proof_path_response"},
303 {replay_delta_request, "replay_delta_request"},
304 {replay_delta_response, "replay_delta_response"},
305 {have_transactions, "have_transactions"},
306 {requested_transactions, "requested_transactions"},
307 {total, "total"}};
308
309 if (auto it = category_map.find(cat); it != category_map.end())
310 return it->second;
311
312 return "unknown";
313 }
314
315protected:
317 {base, {base}},
318 {cluster, {cluster}},
319 {overlay, {overlay}},
320 {manifests, {manifests}},
323 {proposal, {proposal}},
330 {squelch, {squelch}},
333 {get_set, {get_set}},
334 {share_set, {share_set}},
341 {ld_get, {ld_get}},
342 {ld_share, {ld_share}},
349 {gl_share, {gl_share}},
350 {gl_get, {gl_get}},
365 {get_hash, {get_hash}},
372 {total, {total}},
373 {unknown, {unknown}},
374 };
375};
376
377} // namespace ripple
378#endif
TrafficStats(TrafficStats const &ts)
std::atomic< std::uint64_t > bytesOut
TrafficStats(TrafficCount::category cat)
std::atomic< std::uint64_t > messagesOut
std::atomic< std::uint64_t > messagesIn
std::atomic< std::uint64_t > bytesIn
TrafficCount is used to count ingress and egress wire bytes and number of messages.
auto const & getCounts() const
An up-to-date copy of all the counters.
std::unordered_map< category, TrafficStats > counts_
static category categorize(::google::protobuf::Message const &message, protocol::MessageType type, bool inbound)
Given a protocol message, determine which traffic category it belongs to.
static std::string to_string(category cat)
void addCount(category cat, bool inbound, int bytes)
Account for traffic associated with the given category.
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:25